如何使用Android的MediaRecorder创建纵向视频

时间:2015-03-23 19:50:31

标签: android ffmpeg mediarecorder android-mediarecorder commonsware-cwac

我有一个能够以纵向模式录制和播放视频的Android应用程序,这些功能在Android手机上运行良好。

问题出现了,因为此视频也需要在iOS设备上播放(通过服务器共享后)。

iOS未正确显示视频,因为它看起来“裁剪”,但iOS上录制的视频播放没有问题。

因此,在Android和iOS上创建的视频之间的主要区别在于尺寸和旋转。

我使用CWAC-Camera库进行预览和录制,并使用ffmpeg将视频缩小到320x568px(因为这是Android和iOS应用的标准尺寸)。

以下是从Android创建的视频中的元数据:

General
Complete name                            : android_video.mp4
Format                                   : MPEG-4
Format profile                           : Base Media
Codec ID                                 : isom
File size                                : 447 KiB
Duration                                 : 5s 596ms
Overall bit rate                         : 654 Kbps
Encoded date                             : UTC 1904-01-01 00:00:00
Tagged date                              : UTC 1904-01-01 00:00:00
Writing application                      : Lavf56.4.101

Video
ID                                       : 1
Format                                   : AVC
Format/Info                              : Advanced Video Codec
Format profile                           : High@L2.1
Format settings, CABAC                   : Yes
Format settings, ReFrames                : 4 frames
Codec ID                                 : avc1
Codec ID/Info                            : Advanced Video Coding
Duration                                 : 5s 406ms
Bit rate                                 : 536 Kbps
Width                                    : 568 pixels
Height                                   : 320 pixels
Display aspect ratio                     : 16:9
Original display aspect ratio            : 16:9
Rotation                                 : 270°
Frame rate mode                          : Constant
Frame rate                               : 14.985 fps
Color space                              : YUV
Chroma subsampling                       : 4:2:0
Bit depth                                : 8 bits
Scan type                                : Progressive
Bits/(Pixel*Frame)                       : 0.197
Stream size                              : 354 KiB (79%)
Writing library                          : x264 core 142
Encoding settings                        : cabac=1 / ref=3 / deblock=1:0:0 / analyse=0x3:0x113 / me=hex / subme=7 / psy=1 / psy_rd=1.00:0.00 / mixed_ref=1 / me_range=16 / chroma_me=1 / trellis=1 / 8x8dct=1 / cqm=0 / deadzone=21,11 / fast_pskip=1 / chroma_qp_offset=-2 / threads=6 / lookahead_threads=1 / sliced_threads=0 / nr=0 / decimate=1 / interlaced=0 / bluray_compat=0 / constrained_intra=0 / bframes=3 / b_pyramid=2 / b_adapt=1 / b_bias=0 / direct=1 / weightb=1 / open_gop=0 / weightp=2 / keyint=250 / keyint_min=14 / scenecut=40 / intra_refresh=0 / rc_lookahead=40 / rc=crf / mbtree=1 / crf=23.0 / qcomp=0.60 / qpmin=0 / qpmax=69 / qpstep=4 / ip_ratio=1.40 / aq=1:1.00
Language                                 : English
Encoded date                             : UTC 1904-01-01 00:00:00
Tagged date                              : UTC 1904-01-01 00:00:00

Audio
ID                                       : 2
Format                                   : AAC
Format/Info                              : Advanced Audio Codec
Format profile                           : LC
Codec ID                                 : 40
Duration                                 : 5s 596ms
Bit rate mode                            : Constant
Bit rate                                 : 132 Kbps
Channel(s)                               : 2 channels
Channel(s)_Original                      : 1 channel
Channel positions                        : Front: C
Sampling rate                            : 44.1 KHz
Compression mode                         : Lossy
Stream size                              : 89.4 KiB (20%)
Language                                 : English
Encoded date                             : UTC 1904-01-01 00:00:00
Tagged date                              : UTC 1904-01-01 00:00:00

以下是在iOS上创建的视频中的元数据:

General
Complete name                            : ios_video.mp4
Format                                   : MPEG-4
Format profile                           : Base Media / Version 2
Codec ID                                 : mp42
File size                                : 673 KiB
Duration                                 : 7s 38ms
Overall bit rate                         : 783 Kbps
Encoded date                             : UTC 2015-03-17 19:16:36
Tagged date                              : UTC 2015-03-17 19:16:37

Video
ID                                       : 2
Format                                   : AVC
Format/Info                              : Advanced Video Codec
Format profile                           : Main@L3.0
Format settings, CABAC                   : Yes
Format settings, ReFrames                : 2 frames
Codec ID                                 : avc1
Codec ID/Info                            : Advanced Video Coding
Duration                                 : 7s 33ms
Bit rate                                 : 711 Kbps
Width                                    : 320 pixels
Height                                   : 568 pixels
Display aspect ratio                     : 0.563
Frame rate mode                          : Constant
Frame rate                               : 30.000 fps
Color space                              : YUV
Chroma subsampling                       : 4:2:0
Bit depth                                : 8 bits
Scan type                                : Progressive
Bits/(Pixel*Frame)                       : 0.130
Stream size                              : 610 KiB (91%)
Title                                    : Core Media Video
Encoded date                             : UTC 2015-03-17 19:16:36
Tagged date                              : UTC 2015-03-17 19:16:37
Color primaries                          : BT.709
Transfer characteristics                 : BT.709
Matrix coefficients                      : BT.709
Color range                              : Limited

Audio
ID                                       : 1
Format                                   : AAC
Format/Info                              : Advanced Audio Codec
Format profile                           : LC
Codec ID                                 : 40
Duration                                 : 7s 38ms
Source duration                          : 7s 105ms
Bit rate mode                            : Constant
Bit rate                                 : 64.0 Kbps
Channel(s)                               : 2 channels
Channel(s)_Original                      : 1 channel
Channel positions                        : Front: C
Sampling rate                            : 44.1 KHz
Compression mode                         : Lossy
Stream size                              : 56.8 KiB (8%)
Source stream size                       : 57.2 KiB (9%)
Title                                    : Core Media Audio
Encoded date                             : UTC 2015-03-17 19:16:36
Tagged date                              : UTC 2015-03-17 19:16:37

在Android上反转宽度和高度值,旋转参数也设置为270º(这是纵向视频的旋转参数)。

这是关于iOS视频在iOS应用上的外观的草图:

Videos recorded on iOS

这就是Android视频在iOS应用中的外观:

enter image description here

因此,为了在iOS和Android上正确显示视频,我需要能够在Android上将宽度设置为320,将高度设置为568。我从几个地方(CWAC-Camera库的外部和内部)尝试过,但我总是得到一个Camera.Parameters错误。

可以在Android上执行此操作吗?

修改

这是我用ffmpeg:

将旋转设置为0时得到的结果

enter image description here

0 个答案:

没有答案