ffmpegrotationmp4

mp4 And Rotation - Remove Flags But Set Rotation


I'm having a hard time with the rotation on some mp4 files I have. It may well be my poor understanding, so forgive me if I set out what I know (or think I know) and then what I want to happen.

An mp4 has, obviously, a right way up - that is, the way you want it to show when you watch it. Call this the orientation. This isn't metadata - it's just the way you, as a person, want to see the image, with people's heads at the top of the screen and their feet at the bottom.

As part of the metadata, mp4 files have a value/parameter (I believe called 'rotate') that tells how much the mp4 needs to be rotated (0, 90, 180, 270 degrees) so that it is correctly oriented. This value/parameter is observed by some players and not by some others. So if I play my video using this player, all is good (because it observes the value/parameter) - but if I play it with that other player, everything is sideways (because it doesn't observe the value/parameter).

What I want to do is orient the mp4 correctly with the value/parameter set to 0, so that no matter what player plays it, it will always be played oriented correctly (because those players that observe the value/parameter will see it's 0 and do nothing). So I think what I need to do is somehow remove the value/parameter, then rotate the mp4 to the correct orientation without using the rotate value/parameter. I'm thinking of something like what FastStone Image Viewer can do with JPGs - rotate them losslessly without setting the rotate value.

I've used ffmpeg and believe that it removed the rotate value/parameter (or set it to 0) because after I used it, suddenly my video appeared sideways in Windows Explorer, where previously it had appeared right way up. But how do I now rotate it to the correct orientation without changing the rotate value/parameter?

Sorry, this is very long winded and confused. Just like me.


Solution

  • ffmpeg will automatically rotate when re-encoding

    Example: Input has a raster size of 1920x1080 with 90° clockwise rotate side data. Running ffmpeg -i input.mp4 output.mp4 will result in the video being rotated 90° clockwise according to the rotate side data. The output will be 1080x1920 with the rotate side data removed.

    To avoid auto-rotation when re-encoding

    Use the -noautorotate input option:

    ffmpeg -noautorotate -i input.mp4 output.mp4
    

    Change the rotate side data without re-encoding

    Add -c copy to enable stream copy mode and use the -metadata option:

    ffmpeg -i input.mp4 -c copy -metadata:s:v rotate=90 output.mp4
    

    Show rotate side data

    ffprobe -v error -select_streams v -show_entries side_data=rotation -of default=nw=1:nk=1 input.mp4