Could Metadata cause an .MP4 to Display Upside Down

Started by alaska_av8r, February 17, 2021, 02:47:45 PM

Previous topic - Next topic

alaska_av8r

I use Lightroom to catalogue all of my images and video etc.

I imported some iPhone 11 footage yesterday and for some reason in LR the video clip displays upside down.  In VLC it displays properly, haven't checked Premier yet.

I have two more videos taken several minutes prior to this one and they display properly.  The videos were taken with the same phone orientation since i use a DJI Osmo and have never had this issue before after numerous imports.

so I did the exiftool -s on that video and the previous ones, the ones displaying properly showed a rotation=270, while the upside down one showed a rotation of 90, now that makes sense they are 180 degrees out.

So I used exiftool -rotation="270" on the guilty culprit, then looked at it using -s and it matches.  I synched the folder for a metadata update and it still displays upside down, I removed it from the folder and did a re-import, still not luck.

just noticed this is only showing up in videos where the iPhone is in selfie mode (you can see yourself on the screen as you video)

Any ideas?
tim

Phil Harvey

Hi Tim,

I thought that should have worked.  Maybe compare all of the rotation matrices for each of the 3 videos (originals that show normal and upside-down, and the ExifTool-edited one that still shows upside-down):

exiftool -matrixstructure -G1 -a FILE

- 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 ($).

alaska_av8r

<ges/2021/2021-02-07/test2] # exiftool -matrixstructure -G1 -a HJCV5227.MP4                         
[QuickTime]     Matrix Structure                : 1 0 0 0 1 0 0 0 1
[Track1]        Matrix Structure                : 0 -1 0 1 0 0 0 0 1
[Track2]        Matrix Structure                : 1 0 0 0 1 0 0 0 1
<ges/2021/2021-02-07/test2] # exiftool -matrixstructure -G1 -a LIVT9067.MP4                         
[QuickTime]     Matrix Structure                : 1 0 0 0 1 0 0 0 1
[Track1]        Matrix Structure                : 0 -1 0 1 0 0 0 0 1
[Track2]        Matrix Structure                : 1 0 0 0 1 0 0 0 1
<ges/2021/2021-02-07/test2] # exiftool -matrixstructure -G1 -a FRDL2730.MP4                         
[QuickTime]     Matrix Structure                : 1 0 0 0 1 0 0 0 1
[Track1]        Matrix Structure                : 0 -1 0 1 0 0 0 1080 1
[Track2]        Matrix Structure                : 1 0 0 0 1 0 0 0 1


The first two files are correctly oriented, the last file is the one upside down.

tim

Phil Harvey

OK.  Try this command on the upside-down one:

exiftool -track1:matrixstructure="0 -1 0 1 0 0 0 0 1" FRDL2730.MP4

And maybe this to see what happens:

exiftool -track1:matrixstructure="1 0 0 0 1 0 0 0 1" FRDL2730.MP4

- 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 ($).

alaska_av8r

The first command didn't appear to do anything

The second command rotated the movie 90 clockwise, so if I can rotate it 90 more it will be right side up, it is now sitting on its side with the top of image on the left and bottom on the right.

Phil Harvey

OK, good.  The first one shouldn't have done anything.

I feel that this is something you should have been able to figure out yourself, but here are the basic rotation matrices:

> exiftool -rotation=0 -q -execute -track1:matrixstructure -common_args a.mov
Matrix Structure                : 1 0 0 0 1 0 0 0 1
> exiftool -rotation=90 -q -execute -track1:matrixstructure -common_args a.mov
Matrix Structure                : 0 1 0 -1 0 0 240 0 1
> exiftool -rotation=180 -q -execute -track1:matrixstructure -common_args a.mov
Matrix Structure                : -1 0 0 0 -1 0 320 240 1
> exiftool -rotation=270 -q -execute -track1:matrixstructure -common_args a.mov
Matrix Structure                : 0 -1 0 1 0 0 0 320 1
> exiftool a.mov -imagesize
Image Size                      : 320x240


Try these out.

This is for a 320x240 video.  Technically you should use the size of your video in 7 and 8 of the matrix, but practically it usually doesn't matter.

Then the problem is figuring out why setting Rotation didn't work.  Did it set the matrix of the wrong track?

- 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 ($).

alaska_av8r

#6
lol I certainly wish I had figured that out, that is the first time I have ever seen anything like that, I did google it but have you seen the result if you google matrix structure...lmao. Now googling rotation matrices might get me somewhere and hopefully I can read some of that today to get a handle on those. 

It was really strange that for months now I never had an issue with video captured on iPhone displaying in LR and then suddenly it goes bonkers.  At this age I don't have that many brain cells left for LR to kill them like that...ha

Phil Harvey

I know what you mean.  Brain cells are precious to me nowadays, and companies like Adobe and Apple seem to keep moving the metadata target when they should be defining a consistent standard.

- 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 ($).

alaska_av8r

I tried running this command on the file mentioned above since it only needed 90 deg more in rotation

<02-07/test2] # exiftool -rotation=90 -q -execute -track1:matrixstructure="0 1 0 -1 0 0 240 0 1" FRDL2730.MP4
                                 
No file specified
    1 image files updated


Now it displays properly in LR, awesome I don't have to turn my head upside down now.

I assume that is how the command should have been typed, interpolating between what you wrote and the previous command

tim

StarGeek

The reason you received the No file specified error was because there wasn't a file name to go with the first part of the command.  The -execute option can be considered like you pressed enter at that point and started a new command.  So splitting your listed command, you would have
exiftool -rotation=90 -q      (*no filename included*)
exiftool -track1:matrixstructure="0 1 0 -1 0 0 240 0 1" FRDL2730.MP4

If you wanted the filename to be part of both, you would use the -Common_Args option.  Anything following -Common_Args would be common to both parts. 
exiftool -rotation=90 -q -execute -track1:matrixstructure="0 1 0 -1 0 0 240 0 1" -Common_Args FRDL2730.MP4
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

alaska_av8r

#10
thank you, now that makes sense why it gave an error, and that leads to questions.

Would that have been considered two actions combined into a single command, and if so even with the error it worked correctly for the picture after the second command completed.

And if the above is true, is there any need for me to do both commands?  Should I just use the second command adapted to the rotation needed?  Or are they interrelated in some way and better to execute both.  I did read about rotation matrices and I understand the basis but I am not afraid to admit, that was way above my head when they started talking about sin, cosine etc...

I hope that makes sense.

Phil Harvey

The command with -rotation=90 should do exactly the same thing as setting Track1:MatrixStructure to "0 1 0 -1 0 0 240 0 1", provided that setting Rotation updates MatrixStructure for the correct Track(s).  You shouldn't need both.

I'm still not seeing the full picture because I don't know what Track(s) are being written when you write Rotation.  What is the output of this command on the original video before and after writing -rotation=90 ?:

exiftool -rotation -matrixstructure -G1 -a FILE

And does the resulting video display right side up?

- 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 ($).

alaska_av8r

#12
Here I am running the commands for the first time on a completely different file:

Before rotation:
[/share/Pictures02/Professional Images/2021/2021-02-06/Video/iphone] # exiftool -rotation -matrixstructure -G1 -a UZCG2152.MP4
[Composite]     Rotation                        : 90
[QuickTime]     Matrix Structure                : 1 0 0 0 1 0 0 0 1
[Track1]        Matrix Structure                : 0 1 0 1 0 0 0 0 1
[Track2]        Matrix Structure                : 1 0 0 0 1 0 0 0 1


[/share/Pictures02/Professional Images/2021/2021-02-06/Video/iphone] # exiftool -rotation=90 -q UZCG2152.MP4


[/share/Pictures02/Professional Images/2021/2021-02-06/Video/iphone] # exiftool -rotation -matrixstructure -G1 -a UZCG2152.MP4

[Composite]     Rotation                        : 90
[QuickTime]     Matrix Structure                : 1 0 0 0 1 0 0 0 1
[Track1]        Matrix Structure                : 0 1 0 -1 0 0 1920 0 1
[Track2]        Matrix Structure                : 1 0 0 0 1 0 0 0 1


Okay, I'm trying to understand this myself, I can see that it is writing to track 1.  Is the rotation command "relative" meaning rotate it 90 deg more from its pre-command position, or is it "absolute" as in 90 is always displayed in this orientation?  I am assuming it is absolute.

After running the rotation command, the video displays properly as far as the thumbnail in LightRoom (LR), and in LR you can scrub the video to get an idea about what is inside, when I scrub the video is upside down, as soon as I stop scrubbing it goes back to proper orientation.  When I double click the video it opens and plays in a viewer and plays oriented correctly.


Phil Harvey

The rotation is absolute.  I don't understand why scrubbing doesn't work while everything else seems to be OK (you'll have to experiment with this yourself if you want to figure it out), but it looks like ExifTool is writing MatrixStructure of the correct track.

However, I think I understand the problem better now:  I hadn't considered this, but it isn't a simple rotation.  Your original matrix will also do a horizontal flip (ie. the video is mirrored).  Interesting.  This is why you see a Rotation of 90 in both cases, but the MatrixStructure is different.  ExifTool doesn't consider mirroring when writing Rotation or when calculating Rotation from MatrixStructure when reading.

- 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 ($).

alaska_av8r

Thanks Phil

Yeah I'm not too concerned with the scrubbing but I thought i would mention it, seemed weird to me...ha

Yes the 90 deg rotation with two different matrix structures confused the heck out of me and now have me thinking and I may know the answer.

The video is iPhone 11 video....but....I had my iPhone in a DJI Osmo gimbal and it has an app for the phone which can control many aspects of both picture and video with just various button or switch movements.

And sometimes when you use it the app crashes and if you aren't paying attention you are back to using just the normal iPhone video controls which can be hard to detect just from looking at the screen (until you go and hit a button and get no response).

So I wonder if the mirroring and different matrix input is a function of that DJI app....

anyway, thanks so much for your help
tim