我想运行三个命令,在视频文件中引入人为的“停顿”和音频暂停。它们如下 - 在此特定情况下,应在第 0 秒和第 5 秒引入停顿,每次持续 2 秒:
ffmpeg -nostdin -threads 1 -n -i P2LVL18_SRC20034_HRC1802_concat_wo_buffer.avi -filter_complex '[0:v]loop=loop=48:size=1:start=0,setpts=N/FRAME_RATE/TB,loop=loop=48:size=1:start=168,setpts=N/FRAME_RATE/TB[stallvid];color=c=black:r=24.0[black];[black][stallvid]scale2ref[black2][stallvid];[stallvid][black2]overlay=(main_w-overlay_w)/2:(main_h-overlay_h)/2:shortest=1:enable='"'"'between(t,0,1.99)'"'"'[stallvid2];[stallvid2]avgblur=5:enable='"'"'between(t,0,1.99)+between(t,7,8.99)'"'"',eq=brightness=0.0:enable='"'"'between(t,0,1.99)+between(t,7,8.99)'"'"'[stallvidblur];movie=filename=spinners/spinner-256-white.png:loop=0,setpts=N/(FRAME_RATE*TB)*2,fps=fps=24.0[spinner];[stallvidblur][spinner]overlay=(main_w-overlay_w)/2:(main_h-overlay_h)/2:shortest=1:enable='"'"'between(t,0,1.99)+between(t,7,8.99)'"'"'[outv]' -map '[outv]' -c:v ffv1 -pix_fmt yuv420p -vsync cfr buffered.avi_video.nut
ffmpeg -nostdin -threads 1 -n -i P2LVL18_SRC20034_HRC1802_concat_wo_buffer.avi -filter_complex '[0:a]aloop=loop=96000:size=1:start=0,asetpts=N/SAMPLE_RATE/TB,aloop=loop=96000:size=1:start=336000,asetpts=N/SAMPLE_RATE/TB,volume=0:enable='"'"'between(t,0,2)+between(t,7,9)'"'"'[outa]' -map '[outa]' -c:a pcm_s16le buffered.avi_audio.nut
ffmpeg -n -i buffered.avi_video.nut -i buffered.avi_audio.nut -c copy buffered.avi
过去,同时处理音频和视频对我来说效果并不好,并且视频流也必须分开,因此需要单独处理。
在最后一步中,视频和音频流“只是”被复制了,但我观察到报告的 FPS 发生了变化,实际上使帧速率翻倍。
以下是处理视频的日志:
ffmpeg version 4.1.3 Copyright (c) 2000-2019 the FFmpeg developers
built with gcc 5.5.0 (Homebrew gcc 5.5.0_4)
configuration: --prefix=/home/linuxbrew/.linuxbrew/Cellar/ffmpeg/4.1.3-with-options --enable-shared --enable-hardcoded-tables --cc=gcc-5 --host-cflags= --host-ldflags= --enable-gpl --enable-libaom --enable-libmp3lame --enable-libopus --enable-libsnappy --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --disable-libjack --disable-indev=jack --disable-htmlpages --enable-libvmaf --enable-version3
libavutil 56. 22.100 / 56. 22.100
libavcodec 58. 35.100 / 58. 35.100
libavformat 58. 20.100 / 58. 20.100
libavdevice 58. 5.100 / 58. 5.100
libavfilter 7. 40.101 / 7. 40.101
libswscale 5. 3.100 / 5. 3.100
libswresample 3. 3.100 / 3. 3.100
libpostproc 55. 3.100 / 55. 3.100
Guessed Channel Layout for Input Stream #0.1 : stereo
Input #0, avi, from 'P2LVL18_SRC20034_HRC1802_concat_wo_buffer.avi':
Metadata:
encoder : Lavf57.56.100
Duration: 00:02:00.00, start: 0.000000, bitrate: 83129 kb/s
Stream #0:0: Video: ffv1 (FFV1 / 0x31564646), yuv420p, 2560x1440, 81613 kb/s, SAR 1:1 DAR 16:9, 24 fps, 24 tbr, 24 tbn, 24 tbc
Stream #0:1: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 48000 Hz, stereo, s16, 1536 kb/s
Stream mapping:
Stream #0:0 (ffv1) -> loop
overlay -> Stream #0:0 (ffv1)
Output #0, nut, to 'buffered.avi_video.nut':
Metadata:
encoder : Lavf58.20.100
Stream #0:0: Video: ffv1 (FFV1 / 0x31564646), yuv420p, 2560x1440 [SAR 1:1 DAR 16:9], q=2-31, 200 kb/s, 24 fps, 49152 tbn, 24 tbc
Metadata:
encoder : Lavc58.35.100 ffv1
frame= 2976 fps= 13 q=-0.0 Lsize= 1740152kB time=00:02:03.95 bitrate=115000.9kbits/s speed=0.551x
video:1740055kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.005601%
以下是音频处理的日志(横幅截断):
Input #0, avi, from 'P2LVL18_SRC20034_HRC1802_concat_wo_buffer.avi':
Metadata:
encoder : Lavf57.56.100
Duration: 00:02:00.00, start: 0.000000, bitrate: 83129 kb/s
Stream #0:0: Video: ffv1 (FFV1 / 0x31564646), yuv420p, 2560x1440, 81613 kb/s, SAR 1:1 DAR 16:9, 24 fps, 24 tbr, 24 tbn, 24 tbc
Stream #0:1: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 48000 Hz, stereo, s16, 1536 kb/s
Stream mapping:
Stream #0:1 (pcm_s16le) -> aloop
volume -> Stream #0:0 (pcm_s16le)
Output #0, nut, to 'buffered.avi_audio.nut':
Metadata:
encoder : Lavf58.20.100
Stream #0:0: Audio: pcm_s16le (PSD[16] / 0x10445350), 48000 Hz, stereo, s16, 1536 kb/s
Metadata:
encoder : Lavc58.35.100 pcm_s16le
size= 23477kB time=00:02:03.95 bitrate=1551.6kbits/s speed= 100x
video:0kB audio:23241kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 1.016329%
以下是复制的日志:
Input #0, nut, from 'buffered.avi_video.nut':
Metadata:
encoder : Lavf58.20.100
Duration: 00:02:03.96, start: 0.000000, bitrate: 115000 kb/s
Stream #0:0: Video: ffv1 (FFV1 / 0x31564646), yuv420p, 2560x1440, SAR 1:1 DAR 16:9, 24 fps, 24 tbr, 49152 tbn, 49152 tbc
Metadata:
encoder : Lavc58.35.100 ffv1
Guessed Channel Layout for Input Stream #1.0 : stereo
Input #1, nut, from 'buffered.avi_audio.nut':
Metadata:
encoder : Lavf58.20.100
Duration: 00:02:03.94, start: 0.000000, bitrate: 1551 kb/s
Stream #1:0: Audio: pcm_s16le (PSD[16] / 0x10445350), 48000 Hz, stereo, s16, 1536 kb/s
Metadata:
encoder : Lavc58.35.100 pcm_s16le
Output #0, avi, to 'buffered.avi':
Metadata:
ISFT : Lavf58.20.100
Stream #0:0: Video: ffv1 (FFV1 / 0x31564646), yuv420p, 2560x1440 [SAR 1:1 DAR 16:9], q=2-31, 24 fps, 24 tbr, 48 tbn, 48 tbc
Metadata:
encoder : Lavc58.35.100 ffv1
Stream #0:1: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 48000 Hz, stereo, s16, 1536 kb/s
Metadata:
encoder : Lavc58.35.100 pcm_s16le
Stream mapping:
Stream #0:0 -> #0:0 (copy)
Stream #1:0 -> #0:1 (copy)
Press [q] to stop, [?] for help
frame= 2976 fps=0.0 q=-1.0 Lsize= 1769610kB time=00:02:03.97 bitrate=116928.1kbits/s speed= 136x
video:1740055kB audio:23241kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.358131%
我注意到tbc
视频文件中的值已从 24 更改为 49152,并且在输出中,tbn
和tbc
值现在设置为 48。
当我再次读取文件时,fps
变为48:
Input #0, avi, from 'buffered.avi':
Metadata:
encoder : Lavf58.20.100
Duration: 00:02:04.00, start: 0.000000, bitrate: 116908 kb/s
Stream #0:0: Video: ffv1 (FFV1 / 0x31564646), yuv420p, 2560x1440, 114994 kb/s, SAR 1:1 DAR 16:9, 48 fps, 48 tbr, 48 tbn, 48 tbc
Stream #0:1: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 48000 Hz, stereo, s16, 1536 kb/s
该文件buffered.avi
显示,而使用 检查时nb_frames=5952
原始文件已显示。nb_frames=2880
ffprobe
ffprobe
当我使用 的运行实际帧数时count_frames
,我得到的结果是 2976 buffered.avi
,而原始帧数为 2880。差异 96 正好是 4 × 24 帧的停顿。
为什么容器中会出现这种不匹配的情况,我该怎么做才能避免“帧重复”?
输入文件具有恒定的帧速率,并且以 1/24 秒为单位定期增加 PTS。
我尝试过的:
- 使用 MKV 作为中间容器
- 从视频命令中删除所有额外的循环处理