12
Video rotation Video rotation correction correction Author : Fred Hsu Date : 2011/08/31

Video rotation correction

Embed Size (px)

Citation preview

Page 1: Video rotation correction

Video rotationVideo rotation correctioncorrection

Author : Fred HsuDate : 2011/08/31

Page 2: Video rotation correction

Problem StatementProblem StatementVideo player does not support

auto rotation according to sensor.Video player shows different

orientation from our video recorder.

Control B

ar ARecorded asportrait

style

Page 3: Video rotation correction

Remove fixed orientation of Remove fixed orientation of layoutlayoutMarvell provides a fixed layout

screen orientation on video player of Gallery3D app.

Remove fixed orientation video player of Gallery3D app AndroidManifest.xml◦<activity …

android:screenOrientation="landscape" > … </activity>

Page 4: Video rotation correction

ResultResult

0 degree

Control Bar

A

A

Portrait

90 degree

270 degree

Landscape

Reverse

Landscape

Control Bar

A

Control Bar

Page 5: Video rotation correction

Rotation compensationRotation compensationCheck recorder files : The three

orientations are the same as previous page shows.

We need to do a rotation compensation for video player.

Page 6: Video rotation correction

First stage : trace video First stage : trace video recorder rotation parameterrecorder rotation parameterAndroid provides a MediaRecorder object

for video/audio recording usage.MediaRecorder. setOrientationHint

method set the rotation degrees to recorded file.

Android developer website :◦ This method will not trigger the source video

frame to rotate during video recording, but to add a composition matrix containing the rotation angle in the output video if the output format is OutputFormat.THREE_GPP or OutputFormat.MPEG_4 so that a video player can choose the proper orientation for playback.

Page 7: Video rotation correction

MediaRecorder MediaRecorder setOrientationHint flowsetOrientationHint flow

JavaMediaRecord

er

Jniandroid_media_MediaRec

order

FrameworkMediaRecord

er

IPCFrameworkIMediaRecor

der

FrameworkMediaRecorderCli

ent

FrameworkStagefrightRecor

der

Store rotation degrees

MPEG4Writer

Convert to Composition matrix

Page 8: Video rotation correction

Check composition Check composition matrix(1)matrix(1)MP4 file standard defines a

composition matrix, order { a, b, u, c, d, v, x, y, w }

| a b u | | c d v | | x y w |0 degree : a = 0x00010000, b =

0x00000000, c = 0x00000000, d = 0x00010000 (Recorded as landscape)

Page 9: Video rotation correction

Check composition Check composition matrix(2)matrix(2)90 degree : a = 0x00000000, b =

0x00010000, c = 0xFFFF0000, d = 0x00000000 (Recorded as portrait)

270 degree : a = 0xFFFF0000, b = 0x00000000, c = 0x00000000, d = 0xFFFF0000 (Recorded as reverse-landscape)

Page 10: Video rotation correction

Second stage : trace video Second stage : trace video player rotation parameter(1)player rotation parameter(1)Video player create flow:

Trace the video player (Here we use StagefrightPlayer) : find out the composition matrix will get from recorded file.

JavaMediaPla

yer

Jniandroid_media_MediaPl

ayer

Framework

MediaPlayer

FrameworkMediaPlayerServ

iceVideo Player

IPC

Page 11: Video rotation correction

Second stage : trace video Second stage : trace video player rotation parameter(2)player rotation parameter(2)

StagefrightPlayer

3gp file headercomposition

matrix

libstagefrighthw

Convert to degrees

Create renderer with degrees

Display with rotation

ISurface

Part of stagefright system

Surface system

Overlay

Video Device

Overlay system

Page 12: Video rotation correction

Q & AQ & A