Skip to content

This Python code loops through all the video files in an input folder and trims the first 5 seconds of each video. It then saves the trimmed videos to an output folder using the same video format as the input videos

Notifications You must be signed in to change notification settings

neverlast121/video-trimming

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 

Repository files navigation

Video Trimming Script

This Python script trims the first 5 seconds of each video file in a specified input folder and saves the trimmed videos to a designated output folder. The script uses OpenCV for video processing.

Input and Output Folders

  • input_folder: The path to the folder containing the original video files.
  • output_folder: The path to the folder where trimmed videos will be saved.

Code Overview

  1. Folder Setup:

    • Set the paths for the input and output folders (input_folder and output_folder).
    • Create the output folder if it doesn't exist.
  2. Video Trimming:

    • Loop through all video files in the input folder.
    • For each video file with the '.mp4' extension:
      • Open the input video file using OpenCV (cv2.VideoCapture).
      • Get video properties such as frames per second (fps) and total frame count.
      • Set the starting and ending frame numbers for trimming (trim the first 5 seconds).
      • Create a VideoWriter object to save the trimmed video file.
      • Loop through the frames between the starting and ending frames, writing them to the output video file.
      • Release the input and output video objects.
  3. Execution:

    • Replace 'videos' with the path to the actual directory containing the original video files.
    • Replace 'trimmed_videos' with the path to the desired output directory.
    • Execute the script to trim the first 5 seconds of each video and save the trimmed videos in the output folder.

Note

  • The script assumes that the input videos are in the '.mp4' format. You can modify the condition if filename.endswith('.mp4') to match the format of your input videos.

About

This Python code loops through all the video files in an input folder and trims the first 5 seconds of each video. It then saves the trimmed videos to an output folder using the same video format as the input videos

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published