Skip to content

Videos that require to be rotate and flipped ignore the flip

There are about 8 transformations that describe the operations that you can make on images and videos to keep them "rectangular" along the xy dimensions. https://sirv.com/help/articles/rotate-photos-to-be-upright/

However, it seems that VLC struggles to open the ones that need to be rotated by '+- 90 degrees' and 'flipped horizontally (or vertically)'.

I tried to find where the bug was, but I was unsuccessful.

Therefore, I resorted to creating a the videos that can help you all recreate the issue and pinpoint it in hopes it would help everybody:

ffmpeg -f lavfi -i color=c=black:s=512x256:d=4 -vf "drawtext=text='Hello World':fontcolor=white:fontsize=50:x=(w-text_w)/2:y=(h-text_h)/2" -r 30 -frames:v 120 -y output.mp4

for i in $(seq 1 8); do
ffmpeg -f lavfi -i color=c=black:s=512x256:d=4 -vf "drawtext=text='Hello World'${i}:fontcolor=white:fontsize=50:x=(w-text_w)/2:y=(h-text_h)/2" -r 30 -frames:v 120 -y output_exif${i}.mp4

# This is a home made script that
# https://stackoverflow.com/a/49535017
# and adjust the display matrix
# adjust_dataset_mp4_rotation --exif-orientation ${i} output_exif${i}.mp4
done
old upload that doesn't extract with the right permissions

Sample_videos_with_numbers.zip

Sample_videos_with_numbers.zip

One can inspect the matrices with exiftool

echo output.mp4; exiftool output.mp4 | grep Matrix

for i in $(seq 1 8); do 
echo output_exif${i}.mp4; 
exiftool output_exif${i}.mp4 | grep Matrix; 
done

and it shows that they have the expected 8 operations (well 8 distinct operations).

However, if we open the videos:

for i in $(seq 1 8); do
/usr/bin/vlc --no-one-instance output_exif${i}.mp4 &
done

image

Even chrome 133.0.6943 doesn't fully support 5 and 7, they seem to have the same bug as VLC where 7 and 6 are mapped to the same transformation, but at least they support 2 and 4 correct???

image

  • Firefox 136.0.2 seems to support 1, 8, 6, 3

  • Firefox seems to just ignore transforms that relate to 2, 4, 7, 5

  • Iphone: success with EXIF7

  • Windows 11 Media Player: Completely ignores 2, 4, 7, 5

  • Mac - x86: Success

  • Mac - M1/M4: No hardware

The EXIF 2,4,5,7 should look like letters are "backward" even if you rotate your head.

My hunch is that the bug is in here: https://code.videolan.org/videolan/vlc/-/blob/master/modules/demux/avformat/demux.c#L154

but i did try to compile vlc from source and to adjust this code. It didn't really work. I don't even know if I triggered the "code path correctly".

But from inspection:

  • It seems to set fmt->video.orientation to one of 5 unique values:
    • ORIENT_ROTATED_270
    • ORIENT_VFLIPPED
    • ORIENT_ROTATED_180
    • ORIENT_ROTATED_90
    • ORIENT_NORMAL
    • Hmm, then a video_format_TransformBy is called. maybe that is what I missed....

In either case, hopefully this bug report helps drill down the issue. We often capture scientific videos and it is useful for our users to have a viewer that respects this matrix operation in all cases.

One can go through the settings under adjustment and effects and click enough buttons to get each video to display correctly, but this other limitations and isn't as general and user friendly as respecting the flag.

Thank you for your consideration and help!

Edited by Mark Harfouche
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information