我想在输入视频上叠加一系列图像并循环播放该序列直到输入视频完成。
输入视频时长为 00:04:09.71,帧率为 25fps,图像序列包含 497 个 png 文件。
问题是覆盖循环(图像序列)在一次迭代之后从大约第 400 帧开始,但它应该从第 0 帧开始。
命令如下:
ffmpeg -i hq26368874313361335.mp4 -i "Seq\seq_%5d.png" -filter_complex "[1:v]loop=-1:size=497[top];[0:v][top]overlay=shortest=1" temp.ts
以下是 ffmpeg 的输出:
ffmpeg version 3.4.1 Copyright (c) 2000-2017 the FFmpeg developers
built with gcc 7.2.0 (GCC)
configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-bzlib --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-cuda --enable-cuvid --enable-d3d11va --enable-nvenc --enable-dxva2 --enable-avisynth --enable-libmfx
libavutil 55. 78.100 / 55. 78.100
libavcodec 57.107.100 / 57.107.100
libavformat 57. 83.100 / 57. 83.100
libavdevice 57. 10.100 / 57. 10.100
libavfilter 6.107.100 / 6.107.100
libswscale 4. 8.100 / 4. 8.100
libswresample 2. 9.100 / 2. 9.100
libpostproc 54. 7.100 / 54. 7.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'hq26368874313361335.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf57.82.100
Duration: 00:04:09.71, start: 0.000000, bitrate: 588 kb/s
Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 502 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
Metadata:
handler_name : VideoHandler
timecode : 00:00:00:00
Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 79 kb/s (default)
Metadata:
handler_name : SoundHandler
Stream #0:2(eng): Data: none (tmcd / 0x64636D74)
Metadata:
handler_name : TimeCodeHandler
timecode : 00:00:00:00
Input #1, image2, from 'Seq\seq_%5d.png':
Duration: 00:00:19.88, start: 0.000000, bitrate: N/A
Stream #1:0: Video: png, rgba(pc), 1280x720 [SAR 1:1 DAR 16:9], 25 fps, 25 tbr, 25 tbn, 25 tbc
File 'temp.ts' already exists. Overwrite ? [y/N] y
Stream mapping:
Stream #0:0 (h264) -> overlay:main (graph 0)
Stream #1:0 (png) -> loop (graph 0)
overlay (graph 0) -> Stream #0:0 (mpeg2video)
Stream #0:1 -> #0:1 (aac (native) -> mp2 (native))
Press [q] to stop, [?] for help
Output #0, mpegts, to 'temp.ts':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf57.83.100
Stream #0:0: Video: mpeg2video (Main), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], q=2-31, 200 kb/s, 25 fps, 90k tbn, 25 tbc (default)
Metadata:
encoder : Lavc57.107.100 mpeg2video
Side data:
cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: -1
Stream #0:1(eng): Audio: mp2, 48000 Hz, stereo, s16, 384 kb/s (default)
Metadata:
handler_name : SoundHandler
encoder : Lavc57.107.100 mp2
[swscaler @ 0000027d8520e6e0] deprecated pixel format used, make sure you did set range correctly
frame= 6242 fps=101 q=31.0 Lsize= 32413kB time=00:04:09.69 bitrate=1063.4kbits/s speed=4.02x
video:17134kB audio:11700kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 12.413462%
答案1
ffprobe -show_frames -select_streams v hq26368874313361335.mp4
表示输入的像素格式在 16.322031 处从 yuv420p 变为 yuvj420p,这可能是发生故障的点。可能是由于使用 concat demuxer 的输入参数发生变化。
一种解决方案是在连接之前确保所有输入具有相同的像素格式,例如通过使用格式过滤器(-vf format=yuv420p
)或-pix_fmt yuv420p
。