0

I'm using the following command:

ffmpeg -i port001.jpg -vf "scale=100:-1" /tmp/1/port_converted_100-1.jpg

It is working fine on landscape pics but it automatically rotate the portrait pics. Any idea how to avoid the rotation?

davidbaumann
  • 2,189
  • 1
  • 14
  • 32
Benny
  • 1
  • 1

1 Answers1

0

The exif Orientation tag is ignored by ffmpeg

This is ticket #6945: ffmpeg fails at jpeg EXIF orientation.


Rotate your images before using ffmpeg*

Manually

jpegtran can be used to losslessly rotate images. You can use it manually to rotate or create a script to rotate based on the Orientation tag.

jpegtran -rotate 90 input.jpg > output.jpg

Note that this will strip some of the exif data. If you want to keep it all add -copy all then remove the now incorrect Orientation tag with exiftool:

exiftool -Orientation="" output.jpg

With exifautotran

This tool with automatically re-orient the images according to the Orientation tag:

mkdir images
cp *.jpg images
cd images
exifautotran *.jpg

* If ticket #6945 is fixed then this method will become moot.

Viewing exif orientation tag in JPG image

You can use exiftool to view the orientation:

$ exiftool -Orientation -S image.jpg
  Orientation: Rotate 90 CW
$ exiftool -Orientation -n -S image.jpg
  Orientation: 6

Now you can scale with ffmpeg

ffmpeg -i input.jpg -vf "scale=100:-1" output

For more fancy scaling see Resizing images with ffmpeg to fit into specific sized box.

llogan
  • 57,139
  • 15
  • 118
  • 145
  • Is there any way to know the pic orientation? If there is not, this solution doesn't fit my needs as I don't know in advance what will be the pic orientation. I'm provising service to re-scale any pic no mater what is the orientation. – Benny Feb 06 '19 at 07:08
  • @Benny I added some examples of viewing the Orientation tag with `exiftool`. Or just use `exifautotran` as mentioned before and you won't have to worry about Orientation. – llogan Feb 06 '19 at 17:51