Annoying lag when AVQueuePlayer jumps from an asset to another

I have an AVQueuePlayer which should play sequentially an AVURLAsset array representing consecutive fragments of one continuous video.

Whenever a fragment ends and another begins, there is a small glitch that can be clearly seen (the hold frame is about 0.2 seconds and the sound is muted)

I tried to figure out how to get around this problem, but found nothing. I tried to solve it by having 2 AVQueuePlayer and switch between about 0.2 sec until the end of each fragment. The problem is not solved.

Any idea on how to solve this?

Note. When combining mp4 fragments with mp4 rack software, the output is one smooth video without any glitches.

+6
source share
2 answers

It is through this for sure. You will experience this glitch no matter what you do. The reason is how AVQueuePlayer works. It loads the next item when the previous one is finished. Therefore, if your videos are large, you can also see a blank screen for 2-3 seconds. One solution is what you mentioned, i.e. Using two AVQueuePlayer . But, as you said, this does not work for you, and even if you earn, it will be awkward.

The best and cleanest AVMutableComposition solution. It may look complicated at first, but it's quick and one-time. You create a composition of all your videos and play simple AVPlayer . And in your case, I suppose you just need to play it, so you don't even need to export it.

To learn how to use AVMutableComposition , click here. He will explain you the exact code.

+3
source

As you said, "2 AVQueuePlayers" still has a problem (some sound crash). I ran into the same problem and solved it using HLS.

You can play local TS files.

First create the m3u8 and TS files from the source video file.

eg.

 mediafilesegmenter -t 10 sample.mp4 

Then add resource files to your iOS device. You can add files from iTunes, add as a resource, or download and receive from your application.

Start the http server, and then pass the local URL to the AVPlayerController. I used cocoaHttpServer.

Here I give a simple example.

https://github.com/satoshi0212/samples/tree/master/TSPlaySample

-1
source

All Articles