Closed Bug 808099 Opened 7 years ago Closed 7 years ago

Camera - video recording - recorded video is always rotated 90° CCW


(Firefox OS Graveyard :: General, defect, P1)

Gonk (Firefox OS)


(blocking-basecamp:+, firefox18 fixed, firefox19 fixed)

blocking-basecamp +
Tracking Status
firefox18 --- fixed
firefox19 --- fixed


(Reporter: mikeh, Assigned: mikeh)


(Keywords: otoro, smoketest, unagi)


(1 file, 1 obsolete file)

Recorded video, when played back, appears rotated by 90° counter-clockwise, regardless of the setting of 'video-param-rotation-angle-degrees'.
blocking-basecamp: --- → ?
Some background:

In normal execution, logcat shows:

V/GonkRecorder(  406): setParameters: video-param-rotation-angle-degrees=90
V/GonkRecorder(  406): setParameter: key (video-param-rotation-angle-degrees) => value (90)
E/MPEG4Writer(  406): writeCompositionMatrix 0 degrees
E/MPEG4Writer(  406): writeCompositionMatrix 90 degrees
E/MPEG4Writer(  406): writeCompositionMatrix 0 degrees
(written at the end of the recording)

Suspected that maybe the two writeCompositionMatrix(0) calls were overriding the writeCompositionMatrix(mRotation = 90) call; modified the code to produce:

E/MPEG4Writer(  109): writeCompositionMatrix 90 degrees
E/MPEG4Writer(  109): writeCompositionMatrix 90 degrees
E/MPEG4Writer(  109): writeCompositionMatrix 90 degrees

No difference--VLC still plays the video rotated 90-deg CCW.
Interesting discovery: for videos with 'video-param-rotation-angle-degrees' set to 90 degrees, QuickTime 7.7.2 plays the video -PROPERLY-.  What's going on?  It looks like many (most?) media players _ignore_ the composition matrix that MPEG4Writer appends to the end of a recorded file to tell it which was to rotate the recorded video.  QuickTime, however, seems to respect it.

Something to consider for our own media player.
Here are my thoughts after discussing this with Mike on IRC:

It seems to me that the best, but least likely solution would be to rotate the frames when recording them.  That means we're not outputting files that aren't portable to existing players.  

The second best would be to bake the rotation into the video element in gecko. Though if the metadata is at the end of the file, that won't work for streaming media. 

The third best will be to detect the metadata in gaia and rotate appropriately when needed.

And the fallback would be to ignore the metadata and just rotate any video we know came from the phone.

If we're going to have to read metadata from the video files, we'll need to know more about the format. Mike, can you link to the MPEG4Writer module?
(In reply to David Flanagan [:djf] from comment #3)
> Mike, can you link to the MPEG4Writer module?


The function that actually writes the rotational transform is writeCompositionMatrix().
Assignee: nobody → mhabicher
It turns out that in the case of video recording (at least on unagi), 'video-param-rotation-angle-degrees' must be set to the info.rotation output of get_camera_info().  This required exposing that raw information from GonkCameraHardware::GetSensorOrientation().

With that data plugged in, videos appear with the proper orientation in players that respect the composition matrix.  So far, the only player that seems to it QuickTime.  (Windows Media Player 12, VLC 2.0.3, and Ubuntu's Movie Player do not.)

This change at least makes sure our meta-data is correct.
Attachment #677927 - Flags: review?(jones.chris.g)
Comment on attachment 677927 [details] [diff] [review]
Write the correct rotational meta-data to the video stream

This patch looks OK, but how does android get this right?  Videos from those phones play well in all those players.

We should figure that out, perhaps as a followup.
Attachment #677927 - Flags: review?(jones.chris.g) → review+
blocking-basecamp: ? → +
Confirmed that videos recorded on the Nexus S are also rotated 90-deg CCW.
(In reply to Mike Habicher [:mikeh] from comment #7)
> Confirmed that videos recorded on the Nexus S are also rotated 90-deg CCW.

(Videos recorded with B2G loaded onto the Nexus S, that is.)
And for those still following at home, I just recorded a video on the Nexus S running ICS (ref. ) and it too is rotated 90-deg CCW in everything except QuickTime7.

(It's played properly on the phone itself.)
This doesn't apply very cleanly to inbound. Please rebase. Also, should this have a test?
Keywords: checkin-needed
rebased, as requested.
Attachment #677927 - Attachment is obsolete: true
Closed: 7 years ago
Resolution: --- → FIXED
Keywords: smoketest
Priority: -- → P1
Resolution: FIXED → ---
Reopened in todays build:

gecko-aurora: b2dd5f11c4e1
gaia: 3a1320ad953480759edbf43dd94347416e084416
gecko-aurora: 149ad5c9f94d
gaia: 8baa7e64178c2fe8e6a9f07490834de7c67e7a85

In todays build, the rotation is 270° ...
We opened a new bug after this video-param-rotation-angle-degrees fix didnt work
Closed: 7 years ago7 years ago
Resolution: --- → DUPLICATE
Duplicate of bug: 810424
You need to log in before you can comment on or make changes to this bug.