
我一直在嘗試使用 ffmepg 將一系列 16 位元 .pgm 檔案轉換為影片。檔案本身都是有效的 pgm 檔案並且被命名為
0.pgm 1.pgm 2.pgm ...
這些照片是以 ~1 fps 的幀速率拍攝的,我希望生成的影片是即時的(一幀 = 1 秒)。
我用過ffmpeg -r 1 -i %d.pgm -pix_fmt yuv420p output.mp4
輸出檔案已創建,但影片僅顯示黑色像素(右上角的一些灰色像素除外)。在 Windows Media Player 中和使用ffplay
.
這是我收到的完整控制台輸出:
File 'output.mp4' already exists. Overwrite ? [y/N] y
Stream mapping:
Stream #0:0 -> #0:0 (pgm (native) -> h264 (libx264))
Press [q] to stop, [?] for help
[libx264 @ 0000027f39775c80] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 0000027f39775c80] profile High, level 2.2
[libx264 @ 0000027f39775c80] 264 - core 155 r2901 7d0ff22 - H.264/MPEG-4 AVC codec - Copyleft 2003-2018 - 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=15 lookahead_threads=2 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 : Lavf58.10.100
Stream #0:0: Video: h264 (libx264) (avc1 / 0x31637661), yuv420p, 640x480, q=-1--1, 1 fps, 16384 tbn, 1 tbc
Metadata:
encoder : Lavc58.13.100 libx264
Side data:
cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
frame= 549 fps=109 q=-1.0 Lsize= 503kB time=00:09:06.00 bitrate= 7.6kbits/s speed= 109x
video:496kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 1.459769%
[libx264 @ 0000027f39775c80] frame I:3 Avg QP: 2.81 size: 34676
[libx264 @ 0000027f39775c80] frame P:139 Avg QP: 4.47 size: 1849
[libx264 @ 0000027f39775c80] frame B:407 Avg QP:14.75 size: 359
[libx264 @ 0000027f39775c80] consecutive B-frames: 1.1% 0.0% 0.5% 98.4%
[libx264 @ 0000027f39775c80] mb I I16..4: 20.2% 79.1% 0.6%
[libx264 @ 0000027f39775c80] mb P I16..4: 0.0% 1.3% 0.0% P16..4: 19.2% 0.7% 1.6% 0.0% 0.0% skip:77.1%
[libx264 @ 0000027f39775c80] mb B I16..4: 0.0% 0.0% 0.0% B16..8: 10.2% 0.5% 0.3% direct: 0.3% skip:88.7% L0:34.6% L1:64.1% BI: 1.2%
[libx264 @ 0000027f39775c80] 8x8 transform intra:85.7% inter:66.0%
[libx264 @ 0000027f39775c80] coded y,uvDC,uvAC intra: 83.8% 89.0% 88.8% inter: 2.1% 0.3% 0.2%
[libx264 @ 0000027f39775c80] i16 v,h,dc,p: 54% 20% 24% 2%
[libx264 @ 0000027f39775c80] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 23% 16% 59% 1% 0% 0% 0% 0% 0%
[libx264 @ 0000027f39775c80] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 9% 23% 35% 4% 9% 4% 9% 2% 6%
[libx264 @ 0000027f39775c80] i8c dc,h,v,p: 43% 29% 27% 2%
[libx264 @ 0000027f39775c80] Weighted P-Frames: Y:2.9% UV:0.0%
[libx264 @ 0000027f39775c80] ref P L0: 84.0% 0.1% 9.8% 6.0% 0.1%
[libx264 @ 0000027f39775c80] ref B L0: 73.4% 22.6% 4.0%
[libx264 @ 0000027f39775c80] ref B L1: 85.3% 14.7%
[libx264 @ 0000027f39775c80] kb/s:7.39
感謝所有幫助並提前致謝。
問候
答案1
抱歉回覆晚了。
我沒有回覆評論,因為我自己找到了答案。錯誤在於 pgm 檔案頭的約定。 ffmpeg 顯然只能正確處理 P5 檔案(那些具有像素二進位編碼的檔案)。但是,我的檔案是 P2,即具有 ASCII 編碼的檔案。
我發現的最簡單的解決方案是將圖像轉換為 png 格式,然後對它們使用 ffmpg。
感謝您的幫助和問候
萊昂