ffmpeg 从最后删除的图像创建 mp4

ffmpeg 从最后删除的图像创建 mp4

我正在尝试从静态图像 *.png 和 *.jpg 创建 MP4 视频。最后一张图片已从 mp4 中删除。有人能给我一些线索吗?目录中的图像是:

@bambam:/tmp/create_reel/images/holding-00005> identify img0000*.png
img00001.png PNG 1280x779 1280x779+0+0 8-bit sRGB 1.311MB 0.000u 0:00.000
img00002.png PNG 1280x779 1280x779+0+0 8-bit sRGB 728KB 0.000u 0:00.000
img00003.png PNG 1280x779 1280x779+0+0 8-bit sRGB 1.311MB 0.000u 0:00.000
img00004.png PNG 1280x779 1280x779+0+0 8-bit sRGB 728KB 0.000u 0:00.000

ffmpeg 运行:

ffmpeg -r 0.15 -i img%05d.png -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" -c:v libx264 -pix_fmt yuv420p output.mp4
ffmpeg version N-77739-g7ab37ca Copyright (c) 2000-2016 the FFmpeg developers
  built with gcc 5 (SUSE Linux)
  configuration: --prefix=/home/develop/ffmpeg_build --extra-cflags=-I/home/develop/ffmpeg_build/include --extra-ldflags=-L/home/develop/ffmpeg_build/lib --bindir=/home/develop/bin --pkg-config-flags=--static --enable-gpl --enable-nonfree --enable-libfreetype --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265
  libavutil      55. 13.100 / 55. 13.100
  libavcodec     57. 22.100 / 57. 22.100
  libavformat    57. 21.101 / 57. 21.101
  libavdevice    57.  0.100 / 57.  0.100
  libavfilter     6. 23.100 /  6. 23.100
  libswscale      4.  0.100 /  4.  0.100
  libswresample   2.  0.101 /  2.  0.101
  libpostproc    54.  0.100 / 54.  0.100
Input #0, image2, from 'img%05d.png':
  Duration: 00:00:00.16, start: 0.000000, bitrate: N/A
    Stream #0:0: Video: png, rgb24(pc), 1280x779, 25 fps, 25 tbr, 25 tbn, 25 tbc
[libx264 @ 0x386a200] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 LZCNT
[libx264 @ 0x386a200] profile High, level 3.2
[libx264 @ 0x386a200] 264 - core 148 r2 7599210 - H.264/MPEG-4 AVC codec - Copyleft 2003-2015 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=3 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=1 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to 'output.mp4':
  Metadata:
    encoder         : Lavf57.21.101
    Stream #0:0: Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv420p, 1280x778, q=-1--1, 0.15 fps, 12288 tbn, 0.15 tbc
Metadata:
  encoder         : Lavc57.22.100 libx264
Side data:
  unknown side data type 10 (24 bytes)
Stream mapping:
  Stream #0:0 -> #0:0 (png (native) -> h264 (libx264))
Press [q] to stop, [?] for help
frame=    4 fps=0.0 q=-1.0 Lsize=     525kB time=00:00:13.33 bitrate=     322.7kbits/s speed=29.4x    
video:524kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.164819%
[libx264 @ 0x386a200] frame I:1     Avg QP:16.23  size:246200
[libx264 @ 0x386a200] frame P:2     Avg QP:16.29  size: 72244
[libx264 @ 0x386a200] frame B:1     Avg QP:15.11  size:145580
[libx264 @ 0x386a200] consecutive B-frames: 50.0% 50.0%  0.0%  0.0%
[libx264 @ 0x386a200] mb I  I16..4:  4.2% 43.3% 52.5%
[libx264 @ 0x386a200] mb P  I16..4: 21.6%  8.5% 19.7%  P16..4:  1.8%  0.1%  0.2%  0.0%  0.0%    skip:48.0%
[libx264 @ 0x386a200] mb B  I16..4: 43.4% 16.4% 39.8%  B16..8:  0.0%  0.1%  0.2%  direct: 0.0%  skip: 0.0%  L0:89.8% L1:10.2% BI: 0.0%
[libx264 @ 0x386a200] 8x8 transform intra:25.6% inter:2.6%
[libx264 @ 0x386a200] coded y,uvDC,uvAC intra: 62.8% 57.0% 49.5% inter: 1.1% 3.0% 0.2%
[libx264 @ 0x386a200] i16 v,h,dc,p: 76% 17%  4%  4%
[libx264 @ 0x386a200] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 11% 22% 16%  6%  8%  6% 11%  7% 11%
[libx264 @ 0x386a200] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 25% 21% 12%  6%  8%  7%  8%  6%  7%
[libx264 @ 0x386a200] i8c dc,h,v,p: 39% 43% 12%  6%
[libx264 @ 0x386a200] Weighted P-Frames: Y:0.0% UV:0.0%
[libx264 @ 0x386a200] ref P L0: 91.7%  5.8%  2.5%
[libx264 @ 0x386a200] kb/s:160.88

-rw-r--r-- 1 develop users 537839 Jan  9 10:27 output.mp4

一个明显的解决方法是复制最后一张图片,但这有点儿像 hack,我宁愿“正确地”制作电影

答案1

最后一张图片不会就这样被丢弃。每一帧都按照其显示时间戳绘制。每帧的“持久性”发生在两帧的绘制之间。最后一次绘制操作后,播放停止。

除了复制最后一张图片之外,另一个方法是生成一段长度为 的虚拟音频no. of frames x duration of each frame display- 第二项是帧速率的倒数。所以,试试这个:

ffmpeg -r 0.15 -i img%05d.png -f lavfi -i "aevalsrc=0:d=26.667" -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" -c:v libx264 -pix_fmt yuv420p output.mp4

答案2

我认为问题实际上出在 mplayer 上。命令 mplayer -fs -nosound mf://*.png -mf fps=1/5" 播放最后一张图片约 1 秒,其他图片播放 5 秒。我的解决方案是使用另一个播放器播放图片。

相关内容