Rotate mp4 videos without re-encoding

前端 未结 5 692
渐次进展
渐次进展 2020-12-07 08:04

I\'m looking for a way to rotate videos shot with my Nexus 4 on my Debian Wheezy sytem. The videos are shot in portrait mode and I would like to rotate them to landscape mod

5条回答
  •  执念已碎
    2020-12-07 08:34

    FFmpeg and similar programs change the metadata even with the -map_metadata option. exiftool can read the rotation matrix and rotation flag, and since version 10.89 also write it as described below.

    To get true lossless (incl. metadata) rotation, I couldn't find a solution, so I grabbed a hex editor (eg HxD) and analyzed the rotated video files.

    True lossless rotation of MP4:

    • open mp4 with hex editor and search for vide to find the metadata of the video track
    • some rows above (for my files mostly 9, sometimes 12) you should see trak...\tkhd
    • in between there should be an @ sign (HEX 40)
    • in the two rows before it the rotation matrix is stored
    • no rotation:

      00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
      00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00
      40
      
    • 180°:

      FF FF 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
      FF FF 00 00 00 00 00 00 00 00 00 00 00 00 00 00
      40
      
    • 90° cw:

      00 00 00 00 00 01 00 00 00 00 00 00 FF FF 00 00 
      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
      40 
      
    • 90° ccw:

      00 00 00 00 FF FF 00 00 00 00 00 00 00 01 00 00 
      00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
      40
      

    Alter the file as you need it, and it should be rotated in players that support the rotation flag (most current players do).

    In case your video contains stereo audio, this is obviously not switched, so in case you want the sound to match with video rotation (180°), you need to switch the left and right channels.

提交回复
热议问题