iOS:AVPlayer显示黑屏并且无法播放某些MP4视频。

7

我在AVFoundation中使用AVPlayer播放mp4视频。大多数情况下播放器都可以正常工作。但是最近几天我遇到了一个无法播放的.mp4文件。它只显示黑屏,没有任何图片。我很困惑。

以下是.mp4文件的元数据信息:

General
Complete name                    : E:\test.mp4
Format                           : MPEG-4
Format profile                   : Base Media
Codec ID                         : isom
File size                        : 28.2 MiB
Duration                         : 1mn 30s
Overall bit rate                 : 2 613 Kbps
Encoded date                     : UTC 2015-01-09 13:55:04
Tagged date                      : UTC 2015-01-09 13:55:04

Video
ID                               : 1
Format                           : AVC
Format/Info                      : Advanced Video Codec
Format profile                   : High@L4.1
Format settings, CABAC           : Yes
Format settings, ReFrames        : 1 frame
Muxing mode                      : Container profile=High@1.3
Codec ID                         : avc1
Codec ID/Info                    : Advanced Video Coding
Duration                         : 1mn 27s
Bit rate mode                    : Variable
Bit rate                         : 2 675 Kbps
Width                            : 756 pixels
Height                           : 1 260 pixels
Display aspect ratio             : 0.600
Frame rate mode                  : Variable
Frame rate                       : 54.536 fps
Minimum frame rate               : 4.646 fps
Maximum frame rate               : 148.515 fps
Color space                      : YUV
Chroma subsampling               : 4:2:0
Bit depth                        : 8 bits
Scan type                        : Progressive
Bits/(Pixel*Frame)               : 0.051
Stream size                      : 27.9 MiB (99%)
Title                            : VideoHandle
Language                         : English
Encoded date                     : UTC 2015-01-09 13:55:04
Tagged date                      : UTC 2015-01-09 13:55:04

Audio
ID                               : 2
Format                           : AMR
Format/Info                      : Adaptive Multi-Rate
Format profile                   : Narrow band
Codec ID                         : samr
Duration                         : 1mn 30s
Bit rate mode                    : Constant
Bit rate                         : 12.8 Kbps
Channel(s)                       : 1 channel
Sampling rate                    : 8 000 Hz
Bit depth                        : 13 bits
Stream size                      : 141 KiB (0%)
Title                            : SoundHandle
Writing library                  :    
Language                         : English
Encoded date                     : UTC 2015-01-09 13:55:04
Tagged date                      : UTC 2015-01-09 13:55:04
2个回答

1

我最终找到了一个解决方案。在设置avplayerItem的videoCompostion之后,它开始工作了。videoComposition的内容实际上与视频的内容相同。因此,它在内存中播放预览合成而不是视频文件。这是一个技巧。但我仍然不知道为什么avplayer显示黑屏。


4
请提供您解决方案的代码。 - n1ru4l

-1

作为对此的补充,mp4文件有时无法在AVPlayer中播放的原因之一是一个复选框。

当您拖放视频文件以将其添加到XCode项目时,会出现一个面板并显示一些选项。其中之一是“添加到目标:”。

从XCode:拖放视频文件

对于.MOV文件,您不需要勾选此复选框。对于所有其他文件格式,您需要勾选此复选框。

所以,也许如果您像我一样,您会花费一天左右的时间,探究AVAsset等等,试图弄清楚为什么文件似乎无法加载。

这就是答案。复选框。仅适用于mp4,而不是MOV。

因为,苹果。


我在项目中有mov和mp4文件,添加到目标按钮必须对这两种类型的文件都勾选。 - Jeremy Kelleher

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接