1

I am a new user to FFMpeg.

I want a command-line that will create a basic slideshow MP4 video from a folder of JPG and/or PNG images. The images are sourced from either digital cameras/smartphones or scanned photos (typically 600 dpi).

I have been partially successful so far by creating an input text file with a list of the image filenames from the folder with a "duration 2" command after each "file" statement to introduce a 2 second delay between each image.

ffmpeg -hide_banner -f concat -safe 0 -i MQSS_test-ffmpeg.Txt -c:v libx264 -r 30 -pix_fmt yuv420p MQSS_test-ffmpeg.mp4

I have noticed two strange behaviors.

Behavior #1: Incorrect orientation

All images in the MP4 output file are rendered either in portrait or landscape orientation depending on the orientation of the first image. And because I have a mix of portrait and landscape images in the folder, the images that are rendered in the incorrect orientation are stretched or squashed. So if the first image is portrait, all images render as portrait. If the first image is landscape, all images are rendered as landscape.

Is there a way to get the images to render in their correct orientation?

Behavior #2: Can't mix image formats

I can't mix both JPG and PNG image files in the same input file. I receive several errors:

invalid data found when processing input can not process SOS before SOF, skipping unsupported coding type (ca)

However, if I separate the JPG and PNG files into separate JPG and PNG input files and run the separately, both image types render correctly.

Any ideas?

2

2 Answers 2

0

Is there a way to get the images to render in their correct orientation?

Example adapted from Resizing videos with ffmpeg to fit a specific size:

ffmpeg -framerate 1/2 -i %04d.jpg -filter_complex "scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:-1:-1:color=black,format=yuv420p" -r 30 -movflags +faststart output.mp4

Also see image demuxer documentation.

I can't mix both JPG and PNG image files in the same input file.

  • Convert them all to one file type before making a video.

  • Or individually input each image and use the concat filter to concatenate them. This method would be tedious.

6
  • Converting PNGs to JPGs is a good workaround suggestion. Thank you!
    – Sailor Guy
    Commented Jul 9, 2021 at 18:12
  • llogan - thank you! Your command string works perfectly and renders my JPGs in the correct orientation and correct aspect ratio! Only one issue remains.... my input file selection requires a more flexible "*.JPG" syntax because I have tens of thousands of images (52K images in over 1900 folders) that have a wide variety of naming conventions that don't match a simple numeric sequence.
    – Sailor Guy
    Commented Jul 10, 2021 at 1:31
  • I am using WIndows 10 with "ffmpeg version 4.4-full_build-www.gyan.dev Copyright (c) 2000-2021 the FFmpeg developers built with gcc 10.2.0 (Rev6, Built by MSYS2 project)". If I try adding -pattern_type glob -i "*.jpg" I receive this error message "Pattern type 'glob' was selected but globbing is not supported by this libavformat build". Is there a FFmpeg version (or license) that provides glob support on a Windows platform. I'm certainly willing to pay for it.
    – Sailor Guy
    Commented Jul 10, 2021 at 1:31
  • @SailorGuy Should be asked as a new question. This Q/A is about "images render in incorrect orientation".
    – llogan
    Commented Jul 10, 2021 at 19:43
  • Actually I did post a new question... superuser.com/questions/1661735/…
    – Sailor Guy
    Commented Jul 10, 2021 at 20:01
0

As far as I know, ffmpeg cannot use the EXIF Orientation tag to rotate the images accordingly. So you need to rotate the images first, before using ffmpeg to combine them into a slideshow.

To rotate JPEG images losslessly (without recompressing them) there are various tools like Xnview's nconvert, exiftran, and probably many others.

So for example, to rotate all "*.jpg" images in the current directory according to their Exif tag using exiftran :

exiftran -a -i -b *.jpg

The meaning of the flags used:

-a     Automatic (using exif orientation tag).
-i     Enable in-place editing of the images.
-b     Create a backup file when doing in-place editing 

After that, you can use ffmpeg with the options you need.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .