IOS: AVPlayer displays a black screen and cannot play some mp4 videos

I am using AVPlayer in AVFoundation to play mp4 video in my application. Basically the player is fine. But in these two days I come across a .mp4 file that the player could not play. It shows a black screen, but no photos. I am very confused. Here is the metadata for the .mp4 file.

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 
+5
source share
2 answers

I finally found a solution. After setting up videoCompostion avplayerItem it works. The contents of the video composition are actually the same for the video. Thus, it plays the preview composition in memory, but not the video file. This is a trick. However, I still don't know why avplayer shows a black screen.

+1
source

As a complement to this, one of the reasons mp4 files sometimes do not play in AVPlayer comes down to one checkbox.

When you drag and drop to add a video file to the Xcode project, the panel crashes with some parameters. One such option is "Add to targets:".

from Xcode: dragging and dropping a video file

In .MOV files you do not need to check this box. With all other file formats you need to check this box.

So, maybe if you are like me, you spend about a day or so exploring AVAsset, etc., trying to understand why the file does not seem to load.

This is the answer. Check box. Only mp4, not MOV.

Because Apple.

-1
source

Source: https://habr.com/ru/post/1214365/


All Articles