如何使用Android的MediaRecorder创建肖像视频

如何使用Android的MediaRecorder创建肖像视频,android,ffmpeg,mediarecorder,android-mediarecorder,commonsware-cwac,Android,Ffmpeg,Mediarecorder,Android Mediarecorder,Commonsware Cwac,我有一个Android应用程序,可以在纵向模式下录制和播放视频,这些功能在Android手机上运行良好 之所以会出现这个问题,是因为在通过服务器共享后,还需要在iOS设备上播放此视频 iOS无法正确显示视频,因为它看起来被裁剪了,但在iOS上录制的视频播放时没有出现问题 因此,Android和iOS上制作的视频的主要区别在于大小和轮换 我使用库进行预览和录制,并使用ffmpeg将视频缩小到320x568px,因为这是Android和iOS应用程序的标准大小 以下是从Android创建的视频中获取

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

之所以会出现这个问题,是因为在通过服务器共享后,还需要在iOS设备上播放此视频

iOS无法正确显示视频,因为它看起来被裁剪了,但在iOS上录制的视频播放时没有出现问题

因此,Android和iOS上制作的视频的主要区别在于大小和轮换

我使用库进行预览和录制,并使用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
width和height的值在Android上是反向的,并且旋转参数设置为270º这是纵向视频的旋转参数

这是iOS视频在iOS应用程序上的外观示意图:

这就是Android视频在iOS应用程序上的外观:

因此,为了在iOS和Android上正确显示视频,我需要能够在Android上将宽度设置为320,将高度设置为568。我在CWAC相机库内外的几个地方都试过,但我总是得到一个相机。参数错误

在安卓系统上有可能做到这一点吗

编辑:

这是我使用ffmpeg将旋转设置为0时得到的结果:


你不能发明你自己的决心,如果你是这个意思的话。如果它不是受支持的视频大小,则它不是受支持的视频大小。我将使用ffmpeg来旋转视频。感谢您的快速响应!我的情况是iOS没有考虑旋转,它只考虑宽度和高度,所以我恐怕这不是一个选项。无论如何,你是对的,我不能设定具体的分辨率,但似乎我也不能设定任何9:16的分辨率…我想这在AndroidI中根本不可能,我的情况是iOS没有考虑旋转,它只考虑宽度和高度,所以我恐怕这不是一个选项-我不明白。如果您旋转视频,并更改标题以反映播放器不需要自己旋转视频的事实,则旋转参数设置为270º-将其更改为0,在iOS上应该可以,对吗?毕竟,这将是一个真实的纵向视频,方向和分辨率。如果您旋转视频,并更改标题以反映播放器不需要自己旋转的事实,则旋转参数设置为270º-将其更改为0,在iOS上应该可以,对吗?毕竟,这将是一个真正的肖像视频,方向和分辨率方面。实际上没有。我知道这个iOS应用程序中的AVPlayer视图是定制的,但是如果我使用ffmpeg设置旋转,不仅iOS会以横向模式显示,而且Android和Mac OSX也会显示。我刚刚添加了一个视频的屏幕截图,旋转=0,宽度:568px,高度:320px。如果您发布了ffmpeg配方,请告诉我:-