【问题标题】:Trimming batch of videos using timestamp使用时间戳修剪一批视频
【发布时间】:2021-02-26 13:57:38
【问题描述】:

我想根据存储在 csv 文件中的开始和结束时间剪切文件夹中的多个视频:annotations.csv

csv文件的格式为:

视频名称 |开始时间 |结束时间

我认为伪代码可能看起来像这样:

`for i in video_names
 do: cut video according to time frame`

ffmpeg -ss 00:01:00 -i input.mp4 -to 00:02:00 -c copy output.mp4

这是我在硬编码输入名称以及开始和结束时间时为单个视频找到的。 如何使这个动态与我的注释文件相对应?

【问题讨论】:

    标签: python video ffmpeg video-editing


    【解决方案1】:

    想通了。在下面的代码 sn-p 中,只需添加您的路径而不是“your_file_path/annotations.csv”

    pip install moviepy
    from moviepy.video.io.ffmpeg_tools import ffmpeg_extract_subclip
    import csv
    # name of output file
    naming = 'trim_'
    def get_sec(time_str):
        """Get Seconds from time."""
        h, m, s = time_str.split(':')
        return int(h) * 3600 + int(m) * 60 + int(s)
    
    sample = open('your_file_path/annotations.csv', 'r') 
    csv1 = csv.reader(sample,delimiter=',')
    next(csv1, None)
    for eachline in csv1:
        file_name = str(eachline[0])
        out_file = naming + file_name
        start = eachline[1]
        start = get_sec(start)
        end = eachline[2]
        end = get_sec(end)
    
        ffmpeg_extract_subclip(file_name, start, end, targetname=out_file)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-12
      相关资源
      最近更新 更多