How to create an mp4 video from set of ppm images

Assuming you have set of images with *.ppm numbered. Perform the following to create an mp4 video.

 

1. Install ffmpeg

$ sudo yum localinstall --nogpgcheck https://download1.rpmfusion.org/free/el/rpmfusion-free-release-7.noarch.rpm https://download1.rpmfusion.org/nonfree/el/rpmfusion-nonfree-release-7.noarch.rpm ... $ sudo yum install ffmpeg ffmpeg-devel ...

 

2. Convert the images to *.png format

$ for f in *.ppm; do echo "Converting $f"; convert "$f" "$(basename "$f" .ppm).png"; done Converting img001.ppm Converting img002.ppm ....

 

3. User the ffmpeg tool to convert, for example

Note the framerate, the number of frames per second (in this example 10).

More explanation on the command can be found in the man page.

 

$ ffmpeg -framerate 10 -pattern_type glob -i '*.png' -c:v libx264 -pix_fmt yuv420p video.mp4 ffmpeg version 3.4.6 Copyright (c) 2000-2019 the FFmpeg developers built with gcc 4.8.5 (GCC) 20150623 (Red Hat 4.8.5-36) configuration: --prefix=/usr --bindir=/usr/bin --datadir=/usr/share/ffmpeg --docdir=/usr/share/doc/ffmpeg --incdir=/usr/include/ffmpeg --libdir=/usr/lib64 --mandir=/usr/share/man --arch=x86_64 --optflags='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic' --extra-ldflags='-Wl,-z,relro ' --extra-cflags=' ' --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libvo-amrwbenc --enable-version3 --enable-bzlib --disable-crystalhd --enable-fontconfig --enable-gcrypt --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libcdio --enable-libdrm --enable-indev=jack --enable-libfreetype --enable-libfribidi --enable-libgsm --enable-libmp3lame --enable-nvenc --enable-openal --enable-opencl --enable-opengl --enable-libopenjpeg --enable-libopus --disable-encoder=libopus --enable-libpulse --enable-librsvg --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libvorbis --enable-libv4l2 --enable-libvidstab --enable-libx264 --enable-libx265 --enable-libxvid --enable-libzvbi --enable-avfilter --enable-avresample --enable-postproc --enable-pthreads --disable-static --enable-shared --enable-gpl --disable-debug --disable-stripping --shlibdir=/usr/lib64 --enable-libmfx --enable-runtime-cpudetect 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 libavresample 3. 7. 0 / 3. 7. 0 libswscale 4. 8.100 / 4. 8.100 libswresample 2. 9.100 / 2. 9.100 libpostproc 54. 7.100 / 54. 7.100 Input #0, image2, from '*.png': Duration: 00:00:06.50, start: 0.000000, bitrate: N/A Stream #0:0: Video: png, pal8(pc), 1280x720 [SAR 72:72 DAR 16:9], 10 fps, 10 tbr, 10 tbn, 10 tbc Stream mapping: Stream #0:0 -> #0:0 (png (native) -> h264 (libx264)) Press [q] to stop, [?] for help [libx264 @ 0xb2a240] using SAR=1/1 [libx264 @ 0xb2a240] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 AVX2 LZCNT BMI2 [libx264 @ 0xb2a240] profile High, level 3.1 [libx264 @ 0xb2a240] 264 - core 148 r2795 aaa9aa8 - H.264/MPEG-4 AVC codec - Copyleft 2003-2017 - 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=22 lookahead_threads=3 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=25 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 'video.mp4': Metadata: encoder : Lavf57.83.100 Stream #0:0: Video: h264 (libx264) (avc1 / 0x31637661), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], q=-1--1, 30 fps, 15360 tbn, 30 tbc Metadata: encoder : Lavc57.107.100 libx264 Side data: cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1 frame= 195 fps=106 q=-1.0 Lsize= 5438kB time=00:00:06.40 bitrate=6961.2kbits/s dup=130 drop=0 speed=3.49x video:5435kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.058159% [libx264 @ 0xb2a240] frame I:1 Avg QP:23.12 size:171314 [libx264 @ 0xb2a240] frame P:49 Avg QP:24.06 size: 97925 [libx264 @ 0xb2a240] frame B:145 Avg QP:28.32 size: 4106 [libx264 @ 0xb2a240] consecutive B-frames: 0.5% 1.0% 0.0% 98.5% [libx264 @ 0xb2a240] mb I I16..4: 3.6% 80.2% 16.2% [libx264 @ 0xb2a240] mb P I16..4: 0.1% 10.4% 2.3% P16..4: 32.1% 29.6% 20.1% 0.0% 0.0% skip: 5.3% [libx264 @ 0xb2a240] mb B I16..4: 0.0% 0.0% 0.0% B16..8: 13.3% 0.2% 0.2% direct: 3.7% skip:82.6% L0:48.5% L1:44.1% BI: 7.4% [libx264 @ 0xb2a240] 8x8 transform intra:80.8% inter:46.0% [libx264 @ 0xb2a240] coded y,uvDC,uvAC intra: 99.8% 0.0% 0.0% inter: 20.3% 0.0% 0.0% [libx264 @ 0xb2a240] i16 v,h,dc,p: 0% 1% 67% 32% [libx264 @ 0xb2a240] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 7% 7% 32% 8% 10% 9% 8% 8% 10% [libx264 @ 0xb2a240] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 7% 7% 21% 11% 11% 11% 11% 10% 11% [libx264 @ 0xb2a240] i8c dc,h,v,p: 100% 0% 0% 0% [libx264 @ 0xb2a240] Weighted P-Frames: Y:0.0% UV:0.0% [libx264 @ 0xb2a240] ref P L0: 75.4% 20.1% 3.5% 1.0% [libx264 @ 0xb2a240] ref B L0: 98.0% 1.9% 0.1% [libx264 @ 0xb2a240] ref B L1: 96.0% 4.0% [libx264 @ 0xb2a240] kb/s:6849.33

 

Now look for the file video.mp4