【问题标题】:How can I create time gaps in video recordings using newest version of FFMPEG?如何使用最新版本的 FFMPEG 在视频录制中创建时间间隔?
【发布时间】:2019-10-24 17:35:11
【问题描述】:

我是论坛的新手,所以我希望我已经正确地提出了这个问题。

我已经下载了最新版本的 FFMPEG,我想通过在其中插入时间间隔来使用它来修改现有视频。

这就是我所说的时间间隔。如果我输入持续 2 秒并以 FPS=10 录制的视频,则其帧的时间戳如下:

0.1s, 0.2s,0.3s,0.4s, .. 1.7s, 1.8s, 1.9.s, 2s

如果我要引入时间间隔,输入视频帧将是这样的:

0.1s, 0.2s, 0.9s, 1s, 1.1s, 1.7s, 1.8s, 1.9s, 2s

这样的事情有可能实现吗?

!!!编辑!!!

我想在这里发布 Gyan 非常友好地发表评论的命令结果。

对于命令:

ffmpeg -i input.mp4 -vf "setpts='PTS+gte(t,0.3)*(0.6/TB)+gte(t,1.5)*(1.1/TB)',showinfo" -vsync vfr out.mp4

我得到:

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'input.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.20.100
  Duration: 00:00:09.30, start: 0.000000, bitrate: 1185 kb/s
    Stream #0:0(und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 960x540, 1184 kb/s, 10 fps, 10 tbr, 10240 tbn, 20480 tbc (default)
    Metadata:
      handler_name    : VideoHandler
File 'out.mp4' already exists. Overwrite ? [y/N] y
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
Press [q] to stop, [?] for help
[Parsed_setpts_0 @ 0x55e4f4f85400] [Eval @ 0x7fffadb2ac80] Unknown function in 't,0.3)*(0.6/TB)+gte(t,1.5)*(1.1/TB)'
[Parsed_setpts_0 @ 0x55e4f4f85400] Error while parsing expression 'PTS+gte(t,0.3)*(0.6/TB)+gte(t,1.5)*(1.1/TB)'
[AVFilterGraph @ 0x55e4f4eff400] Error initializing filter 'setpts' with args 'PTS+gte(t,0.3)*(0.6/TB)+gte(t,1.5)*(1.1/TB)'
Error reinitializing filters!
Failed to inject frame into filter network: Invalid argument
Error while processing the decoded data for stream #0:0
Conversion failed!

对于命令:

ffmpeg -i input.mp4 -vf select='not(between(t,0.3,0.7)+between(t,1.5.1.8))' -vsync vfr out.mp4

我得到:

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'input.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.20.100
  Duration: 00:00:09.30, start: 0.000000, bitrate: 1185 kb/s
    Stream #0:0(und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 960x540, 1184 kb/s, 10 fps, 10 tbr, 10240 tbn, 20480 tbc (default)
    Metadata:
      handler_name    : VideoHandler
File 'out.mp4' already exists. Overwrite ? [y/N] y
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
Press [q] to stop, [?] for help
[Parsed_select_0 @ 0x55ce2c4f9d00] [Eval @ 0x7ffc980730c0] Missing ')' or too many args in 'between(t'
[Parsed_select_0 @ 0x55ce2c4f9d00] Error while parsing expression 'not(between(t'
[AVFilterGraph @ 0x55ce2c491a00] Error initializing filter 'select' with args 'not(between(t'
Error reinitializing filters!
Failed to inject frame into filter network: Invalid argument
Error while processing the decoded data for stream #0:0
Conversion failed!

【问题讨论】:

  • 有音频吗?
  • 感谢您的快速回复!不它不是。 @Gyan
  • 您要更改0.3s,0.4s, .. 的时间戳还是删除这些时间戳的帧?
  • 两者都要求会不会太过分了?我最初想更改帧时间戳,所以我在第 5 帧和第 6 帧之间有一些时间间隔。但很高兴知道如何在特定时间戳删除帧,这样我也可以处理这个问题。 @Gyan

标签: video ffmpeg video-editing


【解决方案1】:

移动时间戳

这可以使用 setpts 过滤器。

假设没有音频,命令如下所示

ffmpeg -i in -vf setpts='PTS+gte(T\,0.3)*(0.6/TB)+gte(T\,1.5)*(1.1/TB)' -vsync vfr out

这会将时间戳为 0.3 秒或更大的所有帧向前偏移 0.6 秒。它还将所有时间戳为 1.5 秒或更大的帧向前偏移 1.1 秒。后一组帧将同时应用两个偏移量,因此净偏移量为 0.6 + 1.1 = 1.7s。每个偏移组由两部分组成:(qualification)*(offset)。所有偏移组都与原始时间戳 (PTS) 一起添加。

删除框架

假设没有音频,基本形式是

ffmpeg -i in -vf select='not(between(t\,0.3\,0.7)+between(t\,1.5\,1.8))' -vsync vfr out

这将删除时间戳在 0.3 到 0.7 秒和 1.5 到 1.8 秒之间的帧。

【讨论】:

  • 感谢您的回答!对于第一个命令,我收到此错误:[Parsed_setpts_0 @ 0x556c7f860880] [Eval @ 0x7ffeccd99c00] Unknown function in 't,0.3)*(0.6/TB)+gte(t,1.5)*(1.1/TB)' [Parsed_setpts_0 @ 0x556c7f860880] Error while parsing expression 'PTS+gte(t,0.3)*(0.6/TB)+gte(t,1.5)*(1.1/TB)' [AVFilterGraph @ 0x556c7f867400] Error initializing filter 'setpts' with args 'PTS+gte(t,0.3)*(0.6/TB)+gte(t,1.5)*(1.1/TB)' Error reinitializing filters! Failed to inject frame into filter network: Invalid argument Error while processing the decoded data for stream #0:0 Conversion failed!
  • 更正标签和转义逗号。
  • 非常感谢!我还有几个问题。使用删除帧命令时。我看到你指定了-vsync。我认为这是因为您想禁用 FFMPEG 重复/删除行为。 vfr 是干什么用的?它允许可变帧速率吗?问题是我得到了重复的帧。我的意思是,我的视频有 100 帧(10 秒,10FPS),当我从你的命令中得到的 out.mp4 中提取帧时,我仍然得到 100 帧。我希望得到 91,因为它不选择具有 [0.3,0.7] 和 [1.5, 1.8] 时间戳的帧。相反,我得到了重复
  • 图像复用器默认为vsync cfr,所以在提取图像时需要指定-vsync vfr-vsync 0
  • 我得到了两个命令!非常感谢您的帮助先生!
猜你喜欢
  • 2012-12-22
  • 2016-12-09
  • 1970-01-01
  • 2017-07-01
  • 2018-08-28
  • 2014-02-26
  • 1970-01-01
  • 2014-03-19
  • 2012-05-19
相关资源
最近更新 更多