Python path not found

Hello everyone, I received a Python code that I had asked a friend for. It allows for slight modifications to a video in an INPUT folder and outputs the changed version in an OUTPUT folder. It works on his PC, but I'm having a problem with the file paths on my PC.

Here is the Python code =>

import cv2 import numpy as np import random from moviepy.editor import VideoFileClip def get_exposure_preset_parameters(preset): exposure_presets = { "Subtle": (0.9, 1.1), "Light": (0.8, 1.2), "Moderate": (0.7, 1.3), "Strong": (0.5, 1.5), } return exposure_presets.get(preset, (0.8, 1.2)) def get_brightness_preset_parameters(preset): brightness_presets = { "Subtle": (-5, 5), "Light": (-10, 10), "Moderate": (-15, 15), "Strong": (-30, 30), } return brightness_presets.get(preset, (-10, 10)) def get_contrast_preset_parameters(preset): contrast_presets = { "Subtle": (0.9, 1.1), "Light": (0.8, 1.2), "Moderate": (0.7, 1.3), "Strong": (0.5, 1.5), } return contrast_presets.get(preset, (0.8, 1.2)) def get_saturation_preset_parameters(preset): saturation_presets = { "Subtle": (0.8, 1.2), "Light": (0.7, 1.3), "Moderate": (0.5, 1.5), "Strong": (0.4, 1.6), } return saturation_presets.get(preset, (0.7, 1.3)) def print_video_parameters( video_index, exposure_factor, brightness_factor, contrast_factor, saturation_factor, mirror_effect, noise_level, rotation_angle ): print( f"Video {video_index + 1} generated successfully, " "metadata removed, anti-shadow protection activated." ) print(f"Parameters used:") print(f"Exposure: {exposure_factor}") print(f"Brightness: {brightness_factor}") print(f"Contrast: {contrast_factor}") print(f"Saturation: {saturation_factor}") print(f"Mirror effect: {'Activated' if mirror_effect else 'Deactivated'}") print(f"Noise level: {noise_level}") print(f"Rotation angle: {rotation_angle}\n") def add_noise(frame, level): h, w, c = frame.shape noise = np.random.normal(0, level, (h, w, c)) noisy_frame = np.clip(frame + noise, 0, 255) return noisy_frame.astype(np.uint8) def rotate_video(frame, angle): h, w, _ = frame.shape center = (w // 2, h // 2) rotation_matrix = cv2.getRotationMatrix2D(center, angle, 1.0) rotated_frame = cv2.warpAffine(frame, rotation_matrix, (w, h)) return rotated_frame def adjust_video_parameters_with_presets( input_video_path, output_video_path, exposure_preset, brightness_preset, contrast_preset, saturation_preset, mirror_effect=False, noise_level=None, rotation_angle=0 ): exposure_range = get_exposure_preset_parameters(exposure_preset) brightness_range = get_brightness_preset_parameters(brightness_preset) contrast_range = get_contrast_preset_parameters(contrast_preset) saturation_range = get_saturation_preset_parameters(saturation_preset) NUMBER_OF_VIDEOS = 5 cap = cv2.VideoCapture(input_video_path) width = int(cap.get(3)) height = int(cap.get(4)) fps = cap.get(5) fourcc = cv2.VideoWriter_fourcc(*'XVID') print(f"Input video path: {input_video_path}") print(f"Output path: {output_video_path}") print(f"Video width: {width}") print(f"Video height: {height}") print(f"Video FPS: {fps}") print(f"Mirror effect: {'Activated' if mirror_effect else 'Deactivated'}") print(f"Noise level: {noise_level}\n") for i in range(NUMBER_OF_VIDEOS): exposure_factor = random.uniform(*exposure_range) brightness_factor = random.uniform(*brightness_range) contrast_factor = random.uniform(*contrast_range) saturation_factor = random.uniform(*saturation_range) out = cv2.VideoWriter( f"{output_video_path}_{i}.mp4", fourcc, fps, (width, height) ) while True: ret, frame = cap.read() if not ret: break frame = cv2.convertScaleAbs( frame, alpha=contrast_factor, beta=brightness_factor ) hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV) hsv[:, :, 1] = hsv[:, :, 1] * saturation_factor frame = cv2.cvtColor(hsv, cv2.COLOR_HSV2BGR) if mirror_effect: frame = cv2.flip(frame, 1) if noise_level is not None: frame = add_noise(frame, noise_level) frame = rotate_video(frame, rotation_angle) out.write(frame) out.release() print_video_parameters( i, exposure_factor, brightness_factor, contrast_factor, saturation_factor, mirror_effect, noise_level, rotation_angle ) cap.set(cv2.CAP_PROP_POS_FRAMES, 0) cap.release() cv2.destroyAllWindows() def remove_metadata(input_video_path, output_video_path): video_clip = VideoFileClip(input_video_path) video_clip.write_videofile( output_video_path, codec="libx264", audio_codec="aac", remove_temp=True, logger=None ) # Example usage with mirror effects, # noise and rotation manually chosen input_video_path = 'c:/Users/Eleve/Desktop/BOT_Tiktok/Tiktok_INPUT/Entry_file.mp4' output_video_path = 'c:/Users/Eleve/Desktop/BOT_Tiktok/Tiktok_OUTPUT/Output_file.mp4' exposure_preset = "Subtle" brightness_preset = "Light" contrast_preset = "Moderate" saturation_preset = "Light" rotation_angle = 0 # Rotation angle in degrees adjust_video_parameters_with_presets( input_video_path, output_video_path, exposure_preset, brightness_preset, contrast_preset, saturation_preset, mirror_effect=False, noise_level=None, rotation_angle=rotation_angle )

Thanks in advance

Syntax highlighting added by moderation.

5 answers

  • Votes
  • Date
  • Descending date
  1. Moderator

    Given the description and without further clarification, I suspect that
    input_video_path and/or output_video_path do not point to an existing file/folder.


    I mainly work in VB6, VB.NET, and C#, but moderation often leads me to other languages.
    In VB.NET, remember to enable "Option Explicit" and "Option Strict".

    1. Yes, that's exactly the problem. I have indeed put the file in the right place and set the correct path to the file. But it's stuck... I really don't know what to do anymore.

    2. I am on a Windows 11 PC, and I am not sure if it is related to the path notation.

  2. Contributor

    Hello,

    You didn't specify the exact error message.

    Can you test this?

    import os def pf(path): r=os.path.exists(path) if r : print(path + " exists.") else: print (path + " does not exist.") chem1='c:/Users/Eleve/Desktop/BOT_Tiktok/Tiktok_INPUT/Fichier_entree.mp4' pf(chem1) chem1='c:/Users/Eleve/Desktop/BOT_Tiktok/Tiktok_OUTPUT' pf(chem1)
    1. The error message is as follows:

      [Running] /usr/bin/env python3 "c:\Users\Student\Desktop\BOT_Tiktok\ReplicaAlpha1.py"

      The specified path is not found.

      [Done] exited with code=1 in 4.121 seconds

    2. Unfortunately, it doesn't work. I have replaced the 2 paths with your code.

    3. Contributor
      @lilian_d57

      The error message indicates c:\Users\Elève, and in your code, I see c:/Users/Eleve.

      Which one is correct?

  3. Moderator

    Hello,

    Show us the error message.

    Do you have a Windows user called Eleve on your PC? And are you logged in with this user to run the program?

    In command line mode, run the following command:

    dir c:\Users\Eleve\Desktop\BOT_Tiktok\Tiktok_INPUT\

    1. Yes, I do have a student user account on my PC. It's my PC given to me by the school. I don't know if that could be a problem.

      When I type what you told me to put in the terminal, it says that it is impossible to find the path to /User/Student...

    2. Here is the error code it displays

    3. Moderator
      @lilian_d57

      If we look at the image, there is an accent on the word "Elève" not "Eleve".

  4. Note that, according to the prompt displayed in your image

    you are already in C:\users\Student

    you can still type

    cd Desktop\BOT_Tiktok\Tiktok_INPUT

    and when the prompt looks like this:

    C:\users\Student\Desktop\BOT_Tiktok\Tiktok_INPUT >

    you will type

    dir

    1. I typed cd Desktop\BOT_Tiktok\Tiktok_INPUT in the terminal and it shows me this error message

    2. Since my PC is on a Student session, do I need to accentuate the "e" or is it not accepted by PYTHON?

    3. Moderator
      @lilian_d57

      I would have tested it directly to find out ;-)

    4. @lilian_d57

      In your image from 31/12 at 5:48 PM, we saw the following prompt:

      C:\users\Elève>

      showing that you are in the Elève folder

      So I suggested on January 1 at 11:57 AM that you navigate to the folder

      Desktop\BOT_Tiktok\Tiktok_INPUT

      by doing

      cd Desktop\BOT_Tiktok\Tiktok_INPUT

      However, in this message, we see in your image the prompt

      C:\users\Elève\Desktop\BOT_Tiktok\Tiktok_INPUT>

      showing that you are already in Tiktok_INPUT !!!!

      So obviously, if you do, from this folder:

      cd Desktop\BOT_Tiktok\Tiktok_INPUT

      it doesn't work!

      There is no folder

      C:\users\Elève\Desktop\BOT_Tiktok\Tiktok_INPUT\Desktop\BOT_Tiktok\Tiktok_INPUT

    5. @Phil_1857

      They tell me that the access path doesn't exist, but I already knew that. Yet I copied the path from my file manager into the code.

  5. What is certain is that if the folder is really called "Elève"

    with a grave accent on the "e", you need to write:

    input_video_path = 'C:\Users\Elève\Desktop\BOT_Tiktok\Tiktok_INPUT\Fichier_entree.mp4'

    Same with output_video_path ....

    1. Alright, it's changed, that's good.

      Look when I search for the location of my video in my files:

      And also I tested typing this in the terminal:

      C:/Users/Student/Desktop/BOT_Tiktok/Tiktok_INPUT/Fichier_entree.mp4

      and it opened the video.

      So that was for the input video and now when I type:

      C:/Users/Student/Desktop/BOT_Tiktok/Tiktok_INPUT/Fichier_sortie.mp4

      for the output video, it tells me this. (noting that the video "Fichier_entree.mp4" does not exist unlike the input "Fichier_entree.mp4"):

    2. @lilian_d57

      According to your image, you didn't type

      C:/Users/Elève/Desktop/BOT_Tiktok/Tiktok_INPUT/Fichier_sortie.mp4

      but just

      C:/Users/Elève/Desktop/BOT_Tiktok (in yellow in the image)