VideoHelp Forum
+ Reply to Thread
Results 1 to 17 of 17
Thread
  1. Hi

    I would like to use Mencoder to create a slideshow video from a set of photos. Unfortunately, not all the photos are of the same resolution or orientation. Using a command

    mencoder mf://@files.lst -mf w=1920:h=1080:fps=0.3:type=jpg -ovc lavc -lavcopts vcodec=mpeg4:autoaspect=1:mbd=2:trell -oac copy -o output.avi


    makes an output video that scales (stretches) all photos that are of any other aspect ration than the "normal" 16:9 landscape photo.

    How can I make it not to stretch photos, but instead zoom them out and maintain original aspect ratio.
    Quote Quote  
  2. Member
    Join Date: Jun 2012
    Location: USA
    Search Comp PM
    Why on earth would you want to use a tool completely unsuited to this purpose? Even picasa would be simpler.
    Quote Quote  
  3. Because of automation and command line.
    Quote Quote  
  4. vanished El Heggunte's Avatar
    Join Date: Jun 2009
    Location: Misplaced Childhood
    Search Comp PM
    Case 1)

    IF aspect-ratio = 16:9, THEN directly resize to 1920x1080

    Case 2)

    IF aspect-ratio > 16:9, THEN resize WIDTH to 1920, resize HEIGHT accordingly, add letterboxing

    Case 3)

    IF aspect-ratio < 16:9, THEN resize HEIGHT to 1080, resize WIDTH accordingly, add pillarboxing

    ************************

    But I serious doubt Mencoder can do this without the help from some script written in Perl, Python, or whatever
    Quote Quote  
  5. Member
    Join Date: Jun 2012
    Location: USA
    Search Comp PM
    Originally Posted by proguru View Post
    Because of automation and command line.
    Picasa (free) is pretty automated, and does everything you've asked for, but you're right -- no command line.
    Quote Quote  
  6. I would write a bash script:
    Code:
    #!/bin/bash
    
    #define width and height of the output 
    width=700
    height=400
    #call the conversion
    ffmpeg -r 1/3 -i img%03d.jpg  -filter:v "scale=iw*min($width/iw\,$height/ih):ih*min($width/iw\,$height/ih), pad=$width:$height:($width-iw*min($width/iw\,$height/ih))/2:($height-ih*min($width/iw\,$height/ih))/2" -vf fps=25 out.mp4 -c:v libxvid -pix_fmt yuv420p out.avi
    you could also do this without the script, but then you would have to replace the $... parameters.

    also instead of:
    Code:
    mencoder mf://@files.lst -mf fps=0.3:type=jpg -np -ovc lavc -lavcopts vcodec=mpeg4:autoaspect=1:mbd=2:trell -oac copy -o output.avi
    using:
    Code:
    mencoder mf://@files.lst -mf fps=0.3:type=jpg -noskip -ovc lavc -lavcopts vcodec=mpeg4:autoaspect=1:mbd=2:trell -vf expand=aspect=16/9,scale=1920:1080 -o output.avi
    might also work.
    users currently on my ignore list: deadrats, Stears555
    Quote Quote  
  7. Originally Posted by Selur View Post
    using:
    Code:
    mencoder mf://@files.lst -mf fps=0.3:type=jpg -noskip -ovc lavc -lavcopts vcodec=mpeg4:autoaspect=1:mbd=2:trell -vf expand=aspect=16/9,scale=1920:1080 -o output.avi
    might also work.
    It doesn't. Exactly the same scaled output.




    Originally Posted by Selur View Post
    I would write a bash script:
    Code:
    #!/bin/bash
    
    #define width and height of the output 
    width=700
    height=400
    #call the conversion
    ffmpeg -r 1/3 -i img%03d.jpg  -filter:v "scale=iw*min($width/iw\,$height/ih):ih*min($width/iw\,$height/ih), pad=$width:$height:($width-iw*min($width/iw\,$height/ih))/2:($height-ih*min($width/iw\,$height/ih))/2" -vf fps=25 out.mp4 -c:v libxvid -pix_fmt yuv420p out.avi
    you could also do this without the script, but then you would have to replace the $... parameters.

    I have no idea what all those commands do, but they seem to do something since it is not working
    I am a Windows user, so I used the following command:

    Code:
    ffmpeg -r 1/3 -i image_%06d.jpg  -filter:v "scale=iw*min(1920/iw\,1080/ih):ih*min(1920/iw\,1080/ih), pad=1920:1080:(1920-iw*min(1920/iw\,1080/ih))/2:(1080-ih*min(1920/iw\,1080/ih))/2" -vf fps=1 out.mp4 -c:v libxvid -pix_fmt yuv420p out.avi


    The output video contains only few frames. They seem to have approximately correct aspect ratio, but ffmpeg skipped all photos with "tricky" aspect ratio. I also noticed that the video resolution is not (1920x1080), but instead the resolution of the first photo in the input series (2724x2448).

    Here is the complete output of ffmpeg:

    Code:
    C:\temp>ffmpeg -r 1/3 -i image_%06d.jpg  -filter:v "scale=iw*min(1920/iw\,1080/i
    h):ih*min(1920/iw\,1080/ih), pad=1920:1080:(1920-iw*min(1920/iw\,1080/ih))/2:(10
    80-ih*min(1920/iw\,1080/ih))/2" -vf fps=1 out.mp4 -c:v libxvid -pix_fmt yuv420p
    out.avi
    ffmpeg version N-64836-gce385c8 Copyright (c) 2000-2014 the FFmpeg developers
      built on Jul 20 2014 23:34:53 with gcc 4.8.3 (GCC)
      configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-av
    isynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enab
    le-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --
    enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-lib
    modplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrw
    b --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinge
    r --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --en
    able-libvidstab --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis
     --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-
    libx265 --enable-libxavs --enable-libxvid --enable-decklink --enable-zlib
      libavutil      52. 92.101 / 52. 92.101
      libavcodec     55. 69.100 / 55. 69.100
      libavformat    55. 48.101 / 55. 48.101
      libavdevice    55. 13.102 / 55. 13.102
      libavfilter     4. 11.102 /  4. 11.102
      libswscale      2.  6.100 /  2.  6.100
      libswresample   0. 19.100 /  0. 19.100
      libpostproc    52.  3.100 / 52.  3.100
    Input #0, image2, from 'image_%06d.jpg':
      Duration: 00:00:00.68, start: 0.000000, bitrate: N/A
        Stream #0:0: Video: mjpeg, yuvj444p(pc, bt470bg), 2724x2448 [SAR 180:180 DAR
     227:204], 25 fps, 25 tbr, 25 tbn, 25 tbc
    No pixel format specified, yuvj444p for H.264 encoding chosen.
    Use -pix_fmt yuv420p for compatibility with outdated media players.
    [swscaler @ 04045360] deprecated pixel format used, make sure you did set range
    correctly
    [libx264 @ 002e77c0] using SAR=1/1
    [libx264 @ 002e77c0] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX AVX2
     FMA3 LZCNT BMI2
    [libx264 @ 002e77c0] profile High 4:4:4 Predictive, level 5.1, 4:4:4 8-bit
    [libx264 @ 002e77c0] 264 - core 142 r2431 ac76440 - H.264/MPEG-4 AVC codec - Cop
    yleft 2003-2014 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deb
    lock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 m
    e_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chro
    ma_qp_offset=4 threads=6 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 in
    terlaced=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 'out.mp4':
      Metadata:
        encoder         : Lavf55.48.101
        Stream #0:0: Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuvj444p, 2724x
    2448 [SAR 180:180 DAR 227:204], q=-1--1, 1 fps, 16384 tbn, 1 tbc
        Metadata:
          encoder         : Lavc55.69.100 libx264
    Output #1, avi, to 'out.avi':
      Metadata:
        ISFT            : Lavf55.48.101
        Stream #1:0: Video: mpeg4 (libxvid) (xvid / 0x64697678), yuv420p, 2724x2448
    [SAR 1:1 DAR 227:204], q=2-31, 200 kb/s, 0.33 fps, 0.33 tbn, 0.33 tbc
        Metadata:
          encoder         : Lavc55.69.100 libxvid
    Stream mapping:
      Stream #0:0 -> #0:0 (mjpeg (native) -> h264 (libx264))
      Stream #0:0 -> #1:0 (mjpeg (native) -> mpeg4 (libxvid))
    Press [q] to stop, [?] for help
    Input stream #0:0 frame changed from size:2724x2448 fmt:yuvj444p to size:1280x76
    8 fmt:yuvj444p
    [swscaler @ 040b1140] deprecated pixel format used, make sure you did set range
    correctly
    [swscaler @ 044c1480] deprecated pixel format used, make sure you did set range
    correctly
    [libxvid @ 04032e40] Invalid pixel aspect ratio 340/227, limit is 255/255 reduci
    ng
    Input stream #0:0 frame changed from size:1280x768 fmt:yuvj444p to size:1056x816
     fmt:yuvj420p
    [swscaler @ 0405b0a0] deprecated pixel format used, make sure you did set range
    correctly
    [swscaler @ 0643ad40] deprecated pixel format used, make sure you did set range
    correctly
    Input stream #0:0 frame changed from size:1056x816 fmt:yuvj420p to size:154x556
    fmt:yuvj420p
    [swscaler @ 040f07a0] deprecated pixel format used, make sure you did set range
    correctly
    [swscaler @ 0643ad40] deprecated pixel format used, make sure you did set range
    correctly
    Input stream #0:0 frame changed from size:154x556 fmt:yuvj420p to size:4000x3000
     fmt:yuvj420p
    [swscaler @ 0405b0a0] deprecated pixel format used, make sure you did set range
    correctly
    [swscaler @ 06426500] deprecated pixel format used, make sure you did set range
    correctly
    Input stream #0:0 frame changed from size:4000x3000 fmt:yuvj420p to size:580x580
     fmt:yuvj444p
    [swscaler @ 0405b0a0] deprecated pixel format used, make sure you did set range
    correctly
    [swscaler @ 044a8080] deprecated pixel format used, make sure you did set range
    correctly
    Input stream #0:0 frame changed from size:580x580 fmt:yuvj444p to size:2592x1944
     fmt:yuvj420p
    [swscaler @ 0405b0a0] deprecated pixel format used, make sure you did set range
    correctly
    [swscaler @ 0404aa40] deprecated pixel format used, make sure you did set range
    correctly
    Input stream #0:0 frame changed from size:2592x1944 fmt:yuvj420p to size:2432x54
    4 fmt:yuvj420p
    [swscaler @ 0405b0a0] deprecated pixel format used, make sure you did set range
    correctly
    [swscaler @ 0644e0a0] deprecated pixel format used, make sure you did set range
    correctly
    frame=    0 fps=0.0 q=0.0 q=8.0 size=       0kB time=00:00:06.00 bitrate=   0.1k
    Input stream #0:0 frame changed from size:2432x544 fmt:yuvj420p to size:3264x244
    8 fmt:yuvj420p
    [swscaler @ 0405b0a0] deprecated pixel format used, make sure you did set range
    correctly
    [swscaler @ 0644df00] deprecated pixel format used, make sure you did set range
    correctly
    Input stream #0:0 frame changed from size:3264x2448 fmt:yuvj420p to size:2285x17
    14 fmt:yuvj444p
    [swscaler @ 0405b0a0] deprecated pixel format used, make sure you did set range
    correctly
    [swscaler @ 0644da80] deprecated pixel format used, make sure you did set range
    correctly
    Input stream #0:0 frame changed from size:2285x1714 fmt:yuvj444p to size:2724x24
    48 fmt:yuvj444p
    [swscaler @ 044bd460] deprecated pixel format used, make sure you did set range
    correctly
    frame=    6 fps=4.7 q=0.0 q=8.0 size=       0kB time=00:00:12.00 bitrate=   0.0k
    Input stream #0:0 frame changed from size:2724x2448 fmt:yuvj444p to size:338x500
     fmt:yuvj420p
    [swscaler @ 040ffd00] deprecated pixel format used, make sure you did set range
    correctly
    [swscaler @ 040702c0] deprecated pixel format used, make sure you did set range
    correctly
    Input stream #0:0 frame changed from size:338x500 fmt:yuvj420p to size:338x499 f
    mt:yuvj420p
    [swscaler @ 040ffd00] deprecated pixel format used, make sure you did set range
    correctly
    [swscaler @ 044bd460] deprecated pixel format used, make sure you did set range
    correctly
    Input stream #0:0 frame changed from size:338x499 fmt:yuvj420p to size:1345x1763
     fmt:yuvj420p
    [swscaler @ 040ffd00] deprecated pixel format used, make sure you did set range
    correctly
    [swscaler @ 044bd460] deprecated pixel format used, make sure you did set range
    correctly
    Input stream #0:0 frame changed from size:1345x1763 fmt:yuvj420p to size:2251x22
    48 fmt:yuvj420p
    [swscaler @ 040ffd00] deprecated pixel format used, make sure you did set range
    correctly
    [swscaler @ 040c9ae0] deprecated pixel format used, make sure you did set range
    correctly
    frame=    6 fps=2.1 q=-1.0 Lq=8.0 size=     724kB time=00:00:12.00 bitrate= 493.
    9kbits/s dup=0 drop=14
    video:1190kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing
    overhead: unknown
    [libx264 @ 002e77c0] frame I:1     Avg QP: 8.87  size:722094
    [libx264 @ 002e77c0] frame P:2     Avg QP:13.30  size:  8208
    [libx264 @ 002e77c0] frame B:3     Avg QP:15.12  size:   262
    [libx264 @ 002e77c0] consecutive B-frames: 33.3%  0.0%  0.0% 66.7%
    [libx264 @ 002e77c0] mb I  I16..4: 14.6% 83.6%  1.8%
    [libx264 @ 002e77c0] mb P  I16..4:  0.0%  0.7%  0.0%  P16..4:  0.2%  0.0%  0.0%
     0.0%  0.0%    skip:99.1%
    [libx264 @ 002e77c0] mb B  I16..4:  0.0%  0.0%  0.0%  B16..8:  0.3%  0.0%  0.0%
     direct: 0.0%  skip:99.7%  L0:35.3% L1:64.7% BI: 0.0%
    [libx264 @ 002e77c0] 8x8 transform intra:83.8% inter:98.2%
    [libx264 @ 002e77c0] coded y,u,v intra: 66.1% 36.2% 37.7% inter: 0.0% 0.0% 0.0%
    [libx264 @ 002e77c0] i16 v,h,dc,p: 90%  1%  5%  3%
    [libx264 @ 002e77c0] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 27% 17% 28%  5%  3%  3%  3%
     4%  9%
    [libx264 @ 002e77c0] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 35% 23% 13%  6%  6%  6%  3%
     4%  4%
    [libx264 @ 002e77c0] Weighted P-Frames: Y:0.0% UV:0.0%
    [libx264 @ 002e77c0] ref P L0: 79.7%  0.0%  9.8% 10.6%
    [libx264 @ 002e77c0] ref B L1: 91.8%  8.2%
    [libx264 @ 002e77c0] kb/s:985.73
    
    C:\temp>
    Quote Quote  
  8. vanished El Heggunte's Avatar
    Join Date: Jun 2009
    Location: Misplaced Childhood
    Search Comp PM
    Well, Selur supposed you were a *NIX user ^.^;

    The ffmpeg command-line indicated by him depends on those lines "before", so it's no surprise that it didn't work for you.

    If you don't want to mess around with Cygwin or MSYS, you can choose VBScript instead

    OR you can resize and add borders to the pics manually.

    OR you can simply give up and go use Picasa
    Last edited by El Heggunte; 22nd Jul 2014 at 11:23. Reason: grammar : - /
    Quote Quote  
  9. I just tested that command in a real Linux (Ubuntu) computer, the result is the same. Long list of error messages and incomplete video file.
    Quote Quote  
  10. vanished El Heggunte's Avatar
    Join Date: Jun 2009
    Location: Misplaced Childhood
    Search Comp PM
    So you created a .bash file, called it from the CLI, and it didn't work

    Originally Posted by Selur
    you could also do this without the script, but then you would have to replace the $... parameters.
    Quote Quote  
  11. Member
    Join Date: Sep 2007
    Location: Canada
    Search Comp PM
    Maybe ffmpeg's image sequence reader will not accept different dimension image sequence . You probably have to do 2 step batch
    Quote Quote  
  12. Member
    Join Date: Sep 2007
    Location: Canada
    Search Comp PM
    ^Actually it seems to work ok on some test images. Final video is 1920x1080 and it's pillarboxed/letterboxxed correctly.

    What are the dimensions of the pictures that fail ?
    Quote Quote  
  13. The dimensions I used for testing:
    Name:  Clipboard01.png
Views: 143
Size:  8.3 KB

    All other failed, except 2724x2448 and 1280x768



    And the output video has not a correct resolution.
    Click image for larger version

Name:	Clipboard02.png
Views:	10
Size:	164.3 KB
ID:	26531
    Quote Quote  
  14. Member
    Join Date: Sep 2007
    Location: Canada
    Search Comp PM
    I'm not sure why it aborts on some but not others
    Quote Quote  
  15. Member
    Join Date: May 2014
    Location: Tennessee, US
    Search Comp PM
    Originally Posted by proguru View Post
    The dimensions I used for testing:
    ........
    All other failed, except 2724x2448 and 1280x768
    Those failed, too. Neither of those images is 16:9.

    Look, life is already tough enough. Can't count how many times I've done this. Use a photo app to make some 1920x1080 black backgrounds. Then resize your pics to fit on that 1920x1080 blackground, paste onto that background and center as well as you can. Save the pics as .png or .bmp, not as compressed .jpg or they'll look like doo-doo if they don't already. Then you'll have a bunch of 1920x1080 picture panels that are the correct frame size and correct image aspect ratio. Then just use something to make a slide show out of the 1920x1080 panels.

    Below are the picture sizes you posted (on the left side of the list). None of them are 16:9 photos. Shown are the sizes you need to expand or reduce the height and width to fit a 1920x1080 frame, but keeping the pic's original aspect ratio. I worked this out on an Excel spreadsheet in about 10 minutes. Note: use even pixel numbers. Don't use frame sizes with odd numbers.

    Code:
                      original           black     resized
    width height     ratio (w:h)       background    w:h     orientation
    ----- ------ --------------------- ---------- ---------  -----------
    2724   2448  1.13:1                1920x1080  1220x1080  landscape
    1280    768  1.66.1                1920x1080  1800x1080  landscape
    1056    816  ~1.3:1                1920x1080  1404x1080  landscape  
     154    556  1:3.6                 1920x1080   300x1080  portrait
    4000   3000  4:3                   1920x1080  1440x1080  landscape
     580    580  1:1                   1920x1080  1080x1080  square
    2592   1944  4:3                   1920x1080  1440x1080  landscape
    2432    544  ~4.5:1                1920x1080  1920x432   landscape
    3264   2448  4:3                   1920x1080  1440x1080  landscape
    2285   1714  ~4:3                  1920x1080  1440x1080  landscape
     338    500  1.48:1 (~4x6 print)   1920x1080   732x1080  portrait
     338    499  1.48:1 (~4x6 print)   1920x1080   732x1080  portrait
    1345   1763  ~1.3:1 (~11x14 print) 1920x1080   832x1080  portrait
    2251   2248  ~1:1                  1920x1080  1080x1080  square
    A picture that's wider than 1920 pixels won't fit. A picture that's taller than 1080 pixels won't fit. A picture that's smaller in every dimension won't fit either (it will, but it won't fill the width or height of the 1920x1080 panel).

    If you want to write some code to auto-test the dimensions of each pic for those sizes and resize as shown and fill out the black border pixels, go ahead. I wouldn't let ffmpeg resize photos. I'd take the time to check each resize for problems. But that's up to you.
    Last edited by LMotlow; 22nd Jul 2014 at 17:02.
    - My sister Ann's brother
    Quote Quote  
  16. All right, I used http://www.imagemagick.org/ to resize pictures. The Windows batch script renames output photos and ffmpeg will merge them in a single MJPEG video. Lets hope this thing works...

    Code:
    @echo off
    setlocal enabledelayedexpansion
     
    set /A Counter=0
     
    set sourcedir=\\veriton\c\temp\
    set destinationdir=c:\temp\resized\
    
    mkdir %destinationdir%
    
    REM dir /b /s %sourcedir%*.jpg %sourcedir%*.psd %sourcedir%*.gif %sourcedir%*.png %sourcedir%*.bmp %sourcedir%*.jpeg>%destinationdir%files.lst
    
    FOR /R "%sourcedir%" %%i in (*.jpg,*.png,*.jpeg, *.gif) DO (
    	        set /A Counter+=1
    	Set LongName=000000!counter!
    	Set Filename=!LongName:~-6!
    imagemagickconvert "%%i" -resize 1920x1080^ -background black -gravity center -extent 1920x1080 %destinationdir%img_!Filename!.jpg)
    
    
    ffmpeg -r 1/3 -start_number 1 -f image2 -i "%destinationdir%img_%%06d.jpg" -vcodec mjpeg -qscale 1 "%destinationdir%video.avi"
    Quote Quote  
  17. LMotlow is right, I can drive a screw in with a hammer, but a screwdriver does the job so much better! Just get Faststone Photo Resizer, it's free and it will batch convert any AR and size photos to fit onto the canvas size of your liking (1920x1080), add pillar bars if needed, it won't mess up photos in portrait orientation, all without changing the original AR. Then you can run your script and create your slideshow.
    Quote Quote