I am using AVPlayer in AVFoundation to play mp4 videos in my app. Mostly the player is ok. But these two days i meet a .mp4 file that the player couldn't play. It shows black screen but no any pictures. I am very confused. Here is the metadata of 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 : [email protected]
Format settings, CABAC : Yes
Format settings, ReFrames : 1 frame
Muxing mode : Container [email protected]
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
iPhone can only recognize the file with M4V, MP4, and MOV extensions and compressed in H. 264 or MPEG-4. If your MP4 file is not compressed in this way, it can't be opened or played smoothly with your iPhone. You need to convert MP4 to iPhone compatible format first.
The iPad supports the MP4 video format, as long as it is encoded to Apple's specifications. To watch a video online or through an app, simply tap the Play button. To play MP4 videos stored on your computer, transfer them to iTunes and sync them to the iPad, so you can watch them in the device's Video app.
I found a solution finally. After setting the videoCompostion of the avplayerItem, it works. The content of the videoComposition is actually the same of the video. So it is playing the preview composition in the memory but not the video file. It is a trick. However I still don't know why the avplayer shows the black screen.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With