Can't change orientation - mp4 video

Started by druk, August 20, 2014, 07:30:13 AM

Previous topic - Next topic

druk

Hi, I'm working on the following file:

ExifTool Version Number         : 9.69
File Name                       : 2014-08-14 17.41.30.mp4
Directory                       : d:/dropbox/camera uploads
File Size                       : 346 MB
File Modification Date/Time     : 2014:08:14 14:41:30-03:00
File Access Date/Time           : 2014:08:16 23:49:03-03:00
File Creation Date/Time         : 2014:08:16 23:48:37-03:00
File Permissions                : rw-rw-rw-
File Type                       : MP4
MIME Type                       : video/mp4
Major Brand                     : MP4  Base Media v1 [IS0 14496-12:2003]
Minor Version                   : 0.0.0
Compatible Brands               : isom, 3gp4
Movie Data Size                 : 362337360
Movie Data Offset               : 32
Movie Header Version            : 0
Create Date                     : 2014:08:14 17:41:30
Modify Date                     : 2014:08:14 17:41:30
Time Scale                      : 1000
Duration                        : 0:02:49
Preferred Rate                  : 1
Preferred Volume                : 100.00%
Preview Time                    : 0 s
Preview Duration                : 0 s
Poster Time                     : 0 s
Selection Time                  : 0 s
Selection Duration              : 0 s
Current Time                    : 0 s
Next Track ID                   : 3
Play Mode                       : SEQ_PLAY
Track Header Version            : 0
Track Create Date               : 2014:08:14 17:41:30
Track Modify Date               : 2014:08:14 17:41:30
Track ID                        : 1
Track Duration                  : 0:02:49
Track Layer                     : 0
Track Volume                    : 0.00%
Image Width                     : 1920
Image Height                    : 1080
Graphics Mode                   : srcCopy
Op Color                        : 0 0 0
Compressor ID                   : avc1
Source Image Width              : 1920
Source Image Height             : 1080
X Resolution                    : 72
Y Resolution                    : 72
Bit Depth                       : 24
Video Frame Rate                : 30.006
Matrix Structure                : 1 0 0 0 1 0 0 0 1
Media Header Version            : 0
Media Create Date               : 2014:08:14 17:41:30
Media Modify Date               : 2014:08:14 17:41:30
Media Time Scale                : 48000
Media Duration                  : 0:02:49
Handler Type                    : Audio Track
Handler Description             : SoundHandle
Balance                         : 0
Audio Format                    : mp4a
Audio Channels                  : 2
Audio Bits Per Sample           : 16
Audio Sample Rate               : 48000
Avg Bitrate                     : 17.1 Mbps
Image Size                      : 1920x1080
Rotation                        : 90

The video is incorrectly rotated 90°, although only in some cases: the thumbnail in Windows Explorer, playback on the cell phone used to shoot it, playback on Windows Media Player. It shows correctly when playing back on VLC, but the fact that it is rotated on the device used to shoot it proves that this rotation shouldn't happen and must be removed.

I want to try changing the orientation tag to see if I can get the video to play correctly on all devices and players.

Unfortunately, orientation is a composite tag and can't be changed with exiftool, because the tags it is derived from can't be changed either.

Anyway, I refuse to believe that video orientation can't be changed without transcoding. It has to be possible, if not by changing some tag, then by reordering the information in the file a la "jpeg lossless rotator".

So question is: how on earth can I change video orientation without transcoding? I was hoping it could be done with exiftool.

Thank you.

Phil Harvey

You definitely can't do this with ExifTool.  I'm not sure that the MatrixStructure is the only thing you would need to change anyway, even if ExifTool could change this.  I really don't know enough about video rendering to help you with this.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

druk

Do you think someone in this forum could have an answer for me, or should I look elsewhere?

Phil Harvey

I imagine there are much better places to ask this question.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

SONIC3D

Hi,Phil.Sorry for bump this old thread.But what I get from search regarding on modify rotation meta info of mp4 has only got this thread and another older.So I decide to reply this one.

Actually I think I got the same problem as druk met.
At first,my mom took an video with the phone vertically.The recording software on the phone generated a 1280x720 mp4 video which is horizontal in visual but it contains tag that Rotation=90 and Matrix is identity.This video plays correct in vertical on QuickTime and Preview of OS X Finder(Select the file and press Space key).But this file plays horizontal on several windows video player.So that's the player's fault to ignore Rotation info.

For my mom's convenient,I converted the file with ffmpeg to rotation the pixel and encode.The command line I used is:
ffmpeg -vf "transpose=1" -b:v 8000k -b:a 96k -strict -2 -i input.mp4 output.mp4
Ignore the -b:v -b:a and -strict -2 parameters.I actually use transpose=1 parameter for video filter so the video content is hardly rotated 90 degrees and it plays well on those player that ignore Rotation tag.

But I found after conversion.The Rotation tag still exist in result file with the value 90(And the matrix is still identity).That cause this output file Horizontally shows in QuickTime or my OS X Finder's preview.

So after I read your post.I know changing the rotation is complex.But could you tell me how you get the "Rotation" tag value print on console output?(I mean "exiftool -Rotation output.mp4").Is it a direct value get from an offset from the mp4 file?All I want to do is modify it by hand with a hex tool.I think that could solve my problem.I can get a content rotated video with no Rotation tag(or Rotation=0) in its meta info.That can be perfect to both of my mom's windows environment and my OS X environment.

Thank you very much!

Phil Harvey

For manipulation of MP4 atoms I recommend AtomicParsley.  It is a powerful program but it may be difficult to figure out how to use.  I'm not sure if it will do this specific operation though.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

SONIC3D

Thanks phil!Truely!!!

I searched AtomicParsley you recommended.I found it's a bit low level,powerful but complex.
But while searching for how to using it.I eventually found the way to change the rotation tag in metadata of mp4.

I got the page:
http://tiku.io/questions/2621619/remove-rotate-metadata-from-mp4
And it lead me to:
http://stackoverflow.com/questions/15335073/can-i-set-rotation-field-for-a-video-stream-with-ffmpeg/15336581

So finally this command saved me and I think it would be useful to druk or any one search for this topic later:
ffmpeg -i input.mp4 -c copy -metadata:s:v:0 rotate=0 output.mp4
It will not reencode your input video.It will only change the metadata of stream:video:0 and set Rotation to 0.
After do this and check the result file with
exiftool -Rotation output.mp4
It will show:
Rotation                        : 0

pbb

@SONIC3D, you are a hero! Thanks you, that worked like a charm.

SONIC3D

Quote from: pbb on December 16, 2017, 06:04:30 PM
@SONIC3D, you are a hero! Thanks you, that worked like a charm.

My pleasure.
;D

kana

I was actually able to patch the "Rotation" tag in an mp4 file. This is in contrast to this
Quote from: Phil Harvey on August 20, 2014, 07:35:38 AM
You definitely can't do this with ExifTool.  I'm not sure that the MatrixStructure is the only thing you would need to change anyway, even if ExifTool could change this.  I really don't know enough about video rendering to help you with this.
and so I wonder what I'm missing.

If someone is interested in some details, see https://exiftool.org/forum/index.php?topic=11610.0


Phil Harvey

This is a 3-year-old thread.  ExifTool has been able to write the video Rotation for the last year or so.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).