The World’s Largest Online Community for Developers

'; python 3.x - ffmpeg break up videos with frame persecond - LavOzs.Com

Theres a command to extract images of a video providing frame per seconds

ffmpeg -i "vide.mp4" -vf fps=1 frames/frame_%04d.png -hide_banner

Is there a command in ffmpeg to cut video providing fps and save it as video(.mp4 / avi) file like the command above?

What i currently have is i created a method to cut the videos with start and endtime but i firstly created a method to get the length of a video so that i could cut the video base on how many frames that was generated by the above command.

 def get_length(self):
        Gets the length of a video in seconds

            float : Length of the video

        print("Getting video length: " + self.video_string_path)
        command = 'ffprobe -i "'+self.video_string_path+'" -show_entries format=duration -v quiet -of csv="p=0"'
        self.command = command
        length = str(cmd.execute(command)).strip()
        print("lenght: "+length+" second(s)")
        return float(length)

def cut(self, start_time, duration, output_file_name = 'output_file_name.mp4', save_to =''):
        Cut a video on a specific start time of the video and duration.
        Check ffmpeg documentation for more information about the parameters

            start_time : string
                is the value of ffmpeg -ss with the format: 00:00:00.000

            duration : string | int | float
                is the end point where the video will be cut. Can be the same with start_time format but it could also handle integer as in seconds

            output_file_name : string
                is the file name once the file is save in the hardisk

            save_to : string | optional
                is the directory where the file will be saved

            string: file location of the cutted video


        print('Cutting ' + self.video_string_path + ' from ' + start_time + ' to ' + str(duration))
        print('Please wait...')
        file = '"' + self.save_to + output_file_name + '"'
        command = 'ffmpeg -i "' + self.video_string_path + '" -ss ' + str(start_time) + ' -t ' + str(duration) + ' -c copy -y ' + file
        self.command = command

        file_loc = self.get_save_to_dir() + output_file_name
        print('Done: Output file was saved to "' + file_loc + '"')

        return file_loc + output_file_name


ffmpeg -ss {start_time} -t {duration} -i "vide.mp4" -vf fps=X -c:a copy out.mp4

where X is your output framerate.

To segment the entire file,

ffmpeg -i "vide.mp4" -vf fps=X
  -f segment -segment_time {duration} -force_key_frames expr:gte(t,n_forced*{duration}) 
  -reset_timestamps 1 -segment_time_delta 1.0 -c:a copy out%d.mp4

Another way to break up video into smaller chunks is the following command.

ffmpeg -i somefile.mp3 -f segment -segment_time 3 -c copy out%03d.mp3

Rotating videos with FFmpeg
FFMPEG 2 Videos transcoded and side by side in 1 frame?
Is the duration accurate for a video file by ffmpeg?
Quicky output selection of video frames using ffmpeg
FFmpeg concatenation changes the duration and playback speed of the input videos
ffmpeg is cutting video length incorrectly
ffmpeg get last x seconds with high accuracy
how to set fps for ffmpeg lavfi