ffmpeg : aspect ratio of image in a slideshow
Asked Answered
O

1

5

I have a bunch of images PNG files. I'm trying to make a slideshow with these using ffmpeg. The images are 3000*4000. These images don't have all the same aspect ratio.

Some are like these :

enter image description here

Some are like this :

enter image description here

I used the command :

ffmpeg -loop 1 -framerate 1/10 -i img%3d.png -i audio.wav -vf scale=w=3840:h=-1 -vcodec libx264 -crf 14 -r 60 -pix_fmt yuv420p -shortest output.mp4

It returns me this :

   ffmpeg version 3.3.2 Copyright (c) 2000-2017 the FFmpeg developers
  built with gcc 6.3.0 (Debian 6.3.0-18) 20170516
  configuration: --disable-decoder=amrnb --disable-decoder=libopenjpeg --disable-mips32r2 --disable-mips32r6 --disable-mips64r6 --disable-mipsdsp --disable-mipsdspr2 --disable-mipsfpu --disable-msa --disable-libopencv --disable-podpages --disable-stripping --enable-avfilter --enable-avresample --enable-gcrypt --enable-gnutls --enable-gpl --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libfdk-aac --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libilbc --enable-libkvazaar --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenh264 --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libx265 --enable-libxvid --enable-libzvbi --enable-nonfree --enable-opengl --enable-openssl --enable-postproc --enable-pthreads --enable-shared --enable-version3 --incdir=/usr/include/x86_64-linux-gnu --libdir=/usr/lib/x86_64-linux-gnu --prefix=/usr --toolchain=hardened --enable-frei0r --enable-chromaprint --enable-libx264 --enable-libiec61883 --enable-libdc1394 --enable-vaapi --disable-opencl --enable-libmfx --disable-altivec --shlibdir=/usr/lib/x86_64-linux-gnu
  libavutil      55. 58.100 / 55. 58.100
  libavcodec     57. 89.100 / 57. 89.100
  libavformat    57. 71.100 / 57. 71.100
  libavdevice    57.  6.100 / 57.  6.100
  libavfilter     6. 82.100 /  6. 82.100
  libavresample   3.  5.  0 /  3.  5.  0
  libswscale      4.  6.100 /  4.  6.100
  libswresample   2.  7.100 /  2.  7.100
  libpostproc    54.  5.100 / 54.  5.100
Input #0, image2, from 'img%3d.png':
  Duration: 00:02:30.00, start: 0.000000, bitrate: N/A
    Stream #0:0: Video: png, rgb24(pc), 4000x3000 [SAR 7087:7087 DAR 4:3], 0.10 tbr, 0.10 tbn, 0.10 tbc
Guessed Channel Layout for Input Stream #1.0 : stereo
Input #1, wav, from 'audio.wav':
  Duration: 01:54:44.14, bitrate: 1536 kb/s
    Stream #1:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 48000 Hz, stereo, s16, 1536 kb/s
Stream mapping:
  Stream #0:0 -> #0:0 (png (native) -> h264 (libx264))
  Stream #1:0 -> #0:1 (pcm_s16le (native) -> aac (native))
Press [q] to stop, [?] for help
[libx264 @ 0x55c1be935420] using SAR=1/1
[libx264 @ 0x55c1be935420] frame MB size (240x180) > level limit (36864)
[libx264 @ 0x55c1be935420] MB rate (2592000) > level limit (2073600)
[libx264 @ 0x55c1be935420] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 0x55c1be935420] profile High, level 5.2
[libx264 @ 0x55c1be935420] 264 - core 150 - 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=6 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=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=14.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.71.100
    Stream #0:0: Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv420p(progressive), 3840x2880 [SAR 1:1 DAR 4:3], q=-1--1, 60 fps, 15360 tbn, 60 tbc
    Metadata:
      encoder         : Lavc57.89.100 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
    Stream #0:1: Audio: aac (LC) ([64][0][0][0] / 0x0040), 48000 Hz, stereo, fltp, 128 kb/s
    Metadata:
      encoder         : Lavc57.89.100 aac
[image2 @ 0x55c1be8edde0] Thread message queue blocking; consider raising the thread_queue_size option (current value: 8)
More than 1000 frames duplicated    5309kB time=00:00:09.13 bitrate=4762.0kbits/s dup=599 drop=0 speed=0.164x   
More than 10000 frames duplicated 137722kB time=00:02:39.13 bitrate=7089.8kbits/s dup=9584 drop=0 speed=0.174x   
More than 100000 frames duplicated429964kB time=00:27:39.13 bitrate=7060.5kbits/s dup=99434 drop=0 speed=0.173x   
frame=413401 fps= 10 q=-1.0 Lsize= 5962186kB time=01:54:49.96 bitrate=7088.9kbits/s dup=413310 drop=0 speed=0.173x   
video:5831116kB audio:117825kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.222641%
[libx264 @ 0x55c1be935420] frame I:2068  Avg QP: 6.65  size:2816521
[libx264 @ 0x55c1be935420] frame P:104040 Avg QP:10.85  size:   470
[libx264 @ 0x55c1be935420] frame B:307293 Avg QP:16.51  size:   318
[libx264 @ 0x55c1be935420] consecutive B-frames:  0.8%  0.0%  0.5% 98.7%
[libx264 @ 0x55c1be935420] mb I  I16..4:  7.3% 54.6% 38.1%
[libx264 @ 0x55c1be935420] mb P  I16..4:  0.0%  0.0%  0.0%  P16..4:  0.2%  0.0%  0.0%  0.0%  0.0%    skip:99.8%
[libx264 @ 0x55c1be935420] mb B  I16..4:  0.0%  0.0%  0.0%  B16..8:  0.0%  0.0%  0.0%  direct: 0.0%  skip:100.0%  L0:49.5% L1:50.5% BI: 0.0%
[libx264 @ 0x55c1be935420] 8x8 transform intra:54.6% inter:97.9%
[libx264 @ 0x55c1be935420] coded y,uvDC,uvAC intra: 98.2% 92.7% 92.2% inter: 0.0% 0.0% 0.0%
[libx264 @ 0x55c1be935420] i16 v,h,dc,p: 17% 12% 36% 35%
[libx264 @ 0x55c1be935420] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 18% 26% 13%  5%  6%  6%  9%  6% 11%
[libx264 @ 0x55c1be935420] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 15% 24% 11%  7%  9%  7% 10%  7% 11%
[libx264 @ 0x55c1be935420] i8c dc,h,v,p: 40% 33% 18% 10%
[libx264 @ 0x55c1be935420] Weighted P-Frames: Y:0.0% UV:0.0%
[libx264 @ 0x55c1be935420] ref P L0: 99.6%  0.0%  0.4%  0.0%
[libx264 @ 0x55c1be935420] ref B L0: 21.9% 78.1%  0.0%
[libx264 @ 0x55c1be935420] ref B L1: 99.5%  0.5%
[libx264 @ 0x55c1be935420] kb/s:6933.00
[aac @ 0x55c1be938aa0] Qavg: 640.546

But the second image is distorted in the video (I can't show you because I don't have enough reputation to post more links).

So I would like to preserve the aspect ratio of each picture : the images shouldn't be distorted. What command should I use for this ?

Thanks in advance.

Obfuscate answered 19/6, 2017 at 15:43 Comment(5)
You'll have to add padding to images which get resized, so as to preserve frame size. Fine?Noenoel
Thank you for your answer, Mulvya. How do I do that ? (Pardon me, as you have guessed it, I'm a noob)Obfuscate
Stack Overflow is a site for programming and development questions. This question appears to be off-topic because it is not about programming or development. See What topics can I ask about here in the Help Center. Perhaps Super User or Unix & Linux Stack Exchange would be a better place to ask.Ecclesia
jww, thank you for the information. The ffmpeg support forum displays a message on its homepage : "This forum has not been maintained for a long time and will probably get deleted in the near future. For faster responses to your questions, please use StackOverflow instead and tag your questions with "FFmpeg" [ffmpeg.gusari.org/index.php] So I asked my question here. I apologize if I did something wrong. I didn't meant to.Obfuscate
@Obfuscate - Yeah, it sounds like something is bent on their end. If its a programming/development question, like configuring and compiling the library, calling functions in the API, or fixing a bug, then it would be on-topic at Stack Overflow. If the question is about how to use the package's commands, then its off-topic here and probably on-topic at Super User or Unix & Linux Stack Exchange. SU and U&L.SE are the sites that help with commands.Ecclesia
N
7

Looks like the input resolution is fixed but the orientation varies.

Use

ffmpeg -framerate 1/10 -i img%3d.png -i audio.wav \
       -vf 'scale=3840:2880:force_original_aspect_ratio=decrease,pad=3840:2880:(ow-iw)/2:(oh-ih)/2,setsar=1' \
       -c:v libx264 -crf 14 -r 25 -pix_fmt yuv420p -shortest output.mp4

(Since this is a slideshow, there's absolutely no point to encode at 60 fps.)

Noenoel answered 19/6, 2017 at 17:22 Comment(2)
It returns me : bash: syntax error near unexpected token (Obfuscate
Enclose in quotes starting with scale and ending with setsar=1.Noenoel

© 2022 - 2024 — McMap. All rights reserved.