Issue creating a video from .pgm files using ffmpeg

1

I am stuck on trying to convert a series of 16 bit .pgm files to a video using ffmepg. The files themselves are all valid pgm files and are named

0.pgm 1.pgm 2.pgm ...

The pictures have been taken at a framerate of ~1 fps, and I want the resulting video to be in real time (one frame = 1 sec).

I've used ffmpeg -r 1 -i %d.pgm -pix_fmt yuv420p output.mp4

The output file is created, but the video only shows black pixels (except for a few gray ones in the upper right corner). Both in Windows Media Player and using ffplay.

Here is the full console output I receive:

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

All help is appreciated and thanks in advance.

Regards

Leon Kuhn

Posted 2018-03-01T15:54:44.293

Reputation: 11

That's not the full console output. Try ffmpeg -framerate 1 -i %d.pgm -r 25 -pix_fmt yuv420p output.mp4 – llogan – 2018-03-01T18:49:51.810

I get the same issue. I can not give you the console output because I am limited to 600 characters in this comment... – Leon Kuhn – 2018-03-02T12:06:09.440

You can [edit] your question to include the full console output. Also include a link to a pgm file if you can. – llogan – 2018-03-02T18:19:53.200

Answers

0

Sorry for a late reply.

I have not answered the comments, because I found the answer myself. The mistake lies within the conventions of the pgm file header. ffmpeg apparently only handles P5 files correctly (those that have a binary encoding for pixels). However, my files were P2, those that have an ASCII encoding.

The easiest solution I found was to convert the images to png format and then use ffmpg on them.

Thanks for your help and regards

Leon

Leon Kuhn

Posted 2018-03-01T15:54:44.293

Reputation: 11