在关键帧之间剪切视频,而无需使用ffpmeg重新编码完整视频? [英] Cut a video in between key frames without re-encoding the full video using ffpmeg?

查看:118
本文介绍了在关键帧之间剪切视频,而无需使用ffpmeg重新编码完整视频?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在任何特定的时间戳开始时剪辑视频,并且必须精确 ,因此最近的关键帧不够好.

I would like to cut a video at the beginning at any particular timestamp, and it need to be precise, so the nearest key frame is not good enough.

此外,这些视频都很长-一个小时或更长时间-因此,我想尽可能避免重新编码,否则,请仅对总时长的一小部分进行重新编码.因此,想最大限度地使用 -vcodec复制.

Also, these videos are rather long - an hour or longer - so I would like to avoid re-encoding this altogether if possible, or otherwise only re-encode a minimal fraction of the total duration. Thus, would like to maximise the use of -vcodec copy.

如何使用 ffmpeg 完成此操作?

注意:请参阅方案和我自己的粗略想法,以寻求以下可能的解决方案.

NOTE: See scenario, and my own rough idea for a possible solution below.

场景:

  • 原始视频
    • 长度为1:00:00
    • 每10秒就有一个关键帧
    • 从0:01:35一直到结束
    • 使用 -ss 0:01:35 -i blah.mp4 -vcodec复制,结果是一个文件,其中:
    • 音频从0:01:30开始
    • 视频也从0:01:30开始
    • 这太早启动了音频和视频
    • Using -ss 0:01:35 -i blah.mp4 -vcodec copy, what results is a file where:
    • audio starts at 0:01:30
    • video also starts at 0:01:30
    • this starts both the audio and the video too early
    • 音频从0:01:35开始,
    • 但在前5秒钟视频为空白/黑色,
      • 直到视频开始之前的0:01:40

      好主意

      • (1)从0:01:30切至0:01:40
        • 对此重新编码以具有新的关键帧,在目标时间0:01:35包括一个
        • 然后将其剪切以从0:01:35到0:01:40获得5秒
        • 使用 -vcodec复制
        • 无需重新编码
        • without re-encoding, using -vcodec copy

        我知道/可以算出(2)和(3)的命令,但是不确定(1)需要什么命令.

        I know/ can work out the commands for (2) and (3), but am unsure about what commands are needed for (1).

        推荐答案

        列出关键帧的时间戳:

        ffprobe -v error -select_streams v:0 -skip_frame nokey -show_entries frame=pkt_pts_time -of csv=p=0 input.mp4
        

        它将输出如下内容:

        0.000000
        2.502000
        3.795000
        6.131000
        10.344000
        12.554000
        16.266000
        ...
        

        假设您要删除时间戳0到5,然后流副本余.下一个最接近的关键帧是6.131.

        Let's say you want to delete timestamps 0 to 5, and then stream copy the remainder. The closest following key frame is 6.131.

        将5重新编码为6.131.确保输入和输出匹配属性和格式.对于MP4,默认设置应完成大部分工作(假设使用H.264/AAC),但是您可能必须手动匹配个人资料.

        Re-encode 5 to 6.131. Ensure the input and output match attributes and formats. For MP4 default settings should do most of the work, assuming H.264/AAC, but you may have to manually match the profile.

        ffmpeg -i input.mp4 -ss 5 -to 6.131 trimmed.mp4
        

        concat多路复用器输入 input.txt :

        file 'trimmed.mp4'
        file 'input.mp4'
        inpoint 6.131
        

        串联:

        ffmpeg -f concat -i input.mp4 -c copy output.mp4
        

        这篇关于在关键帧之间剪切视频,而无需使用ffpmeg重新编码完整视频?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆