Stefan Kendall
Stefan Kendall

Reputation: 67862

ffmpeg cut video in an HLS stream, pauses playback

I have this playlist:

#EXTM3U
#EXT-X-VERSION:3
#EXT-X-TARGETDURATION:7
#EXT-X-MEDIA-SEQUENCE:0

And I want to insert a cut clip as the stream is being generated that is a bit shorter than the normal 6s length (between 1s and 3s).

So the stream looks like this.

stream136.ts
#EXTINF:7.133333,
stream137.ts
#EXT-X-DISCONTINUITY
#EXTINF:3.68,
cutstream20.ts
#EXTINF:6.933333,
stream21.ts
#EXTINF:5.2,
stream22.ts

VLC plays through the discontinuity with a pretty terrible hiccup, and AVPlayer on iOS is stopping at the discontinuity entirely. If I remove the cut clip, playback is smooth.

How can I create a cut segment or modify the playlist to allow playback on iOS?

The cut command looks like this: ffmpeg -y -i file.ts -ss 3 -c:v copy -c:a copy cut.ts

Upvotes: 1

Views: 1663

Answers (1)

aergistal
aergistal

Reputation: 31219

The EXT-X-TARGETDURATION is the maximum duration so the lower value is not a problem.

Each segment must start on a keyframe (more precisely in the case of MPEG-TS with a PAT/PMT followed by an IDR).

Since you are seeking to some arbitrary timestamp and copying the existing encoding it's likely your segment doesn't start with a keyframe thus causing issues.

You can try putting the -ss parameter before the -i as it will parse the input using keyframes when stream-copying (wiki).

Upvotes: 2

Related Questions