如何使用最新版本的FFMPEG在视频录制中创建时间间隔? [英] How can I create time gaps in video recordings using newest version of FFMPEG?

查看:446
本文介绍了如何使用最新版本的FFMPEG在视频录制中创建时间间隔?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am new to the forum so I hope I've formulated this question correctly.

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

I have downloaded newest version of FFMPEG and I would like to use it to modify existing video by inserting time gaps in it.

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

Here is what I mean by time gap. If I have input video that lasts 2 seconds and was recorded at FPS=10, timestamps of its frames would be as follows:

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

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

If I would to introduce time gaps, input videos frame would be something like this:

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

有没有可能实现这样的目标?

Is something like this possible to achieve?

!!! 编辑 !!!

我想在这里发布命令的结果,Gyan十分友好地发表了评论.

I would like to post here results of the commands Gyan was kind enough to comment.

对于命令:

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!

推荐答案

更改时间戳记

可以使用setpts过滤器.

Shifting timestamps

This is possible using the setpts filter.

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

Assuming no audio, command would look like this

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

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

This will offset all frames with timestamps 0.3s or greater forward by 0.6s. It will also offset all frames with timestamps 1.5s or greater forward by 1.1s. These latter set of frames will have both offsets applied to them, so net offset is 0.6 + 1.1 = 1.7s. Each offset group is composed of two parts: (qualification)*(offset). All offset groups are added together with the original timestamp (PTS).

假设没有音频,则基本形式为

Assuming no audio, basic form is

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秒之间的帧.

This will remove frames having timestamps between 0.3 and 0.7s and between 1.5s and 1.8s.

这篇关于如何使用最新版本的FFMPEG在视频录制中创建时间间隔?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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