【问题标题】:ffmpeg break up videos with frame persecondffmpeg 以每秒帧数分解视频
【发布时间】:2018-05-25 18:14:34
【问题描述】:

有一个命令可以提取每秒提供帧数的视频图像

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

ffmpeg 中是否有一个命令可以像上面的命令一样剪切提供 fps 的视频并将其保存为视频(.mp4 / avi)文件?

我目前拥有的是我创建了一种方法来剪切具有开始和结束时间的视频,但我首先创建了一种方法来获取视频的长度,以便我可以根据生成的帧数来剪切视频上面的命令。

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

        Returns:
            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 https://ffmpeg.org/ffmpeg.html for more information about the parameters

        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

        Returns:
            string: file location of the cutted video

        """

        self.make_sure_save_dir_exits(save_to)
        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
        cmd.execute(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

【问题讨论】:

    标签: python-3.x ffmpeg


    【解决方案1】:

    使用

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

    X 是你的输出帧率。


    分割整个文件,

    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
    

    【讨论】:

    • 嗨,Mulvya,有没有办法自动分割整个视频并指定每个剪辑的长度?
    • 嗨@Gyan。我已经在 ubuntu 上尝试过这个命令并且我有 bash: 意外标记附近的语法错误 `(' 我已经问了另一个问题所以这个stackoverflow.com/questions/50264687/…
    【解决方案2】:

    另一种将视频分成更小块的方法是以下命令。

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

    https://www.ffmpeg.org/ffmpeg-formats.html#segment_002c-stream_005fsegment_002c-ssegment

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-12-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-09
      • 1970-01-01
      • 2013-10-01
      相关资源
      最近更新 更多