Ketan
Ketan

Reputation: 1517

How to convert a m3u8 playlist file into a video segment

I've been trying to find out solutions but could not, on how to extract a video segment (say an mp4) from a given m3u8 file, where the video starts from some offset and has a particular duration. Wish someone could help.

I tried this:

ffmpeg -i http://foo.herokuapp.com/input_test.m3u8 -acodec copy -vcodec copy  -y -loglevel info -f mp4 myNewVideo.mp4

It generates the video, but now I need it to start from a particular offset and it needs to last a particular duration. I know that the offset might need the -ss flag, but it doesn't seem to be working.

Upvotes: 3

Views: 4218

Answers (1)

aergistal
aergistal

Reputation: 31209

Examples for a capture starting at 30s (-ss) with a duration of 10s (-t).

If the input HLS playlist is of type VOD you can do:

ffmpeg -ss 00:00:30 -i http://foo.herokuapp.com/input_test.m3u8 -t 10 -c copy -bsf:a aac_adtstoasc -flags +global_header -y output.mp4

If the input is a Live stream then:

ffmpeg -i http://foo.herokuapp.com/input_test.m3u8 -ss 00:00:30 -t 10 -c copy -bsf:a aac_adtstoasc -flags +global_header -y output.mp4

The seek is done on the output in the second case (-ss after -i).

You can also add a -re before -i for the live stream if you want to avoid fetching the latest 3 segments at once when you execute the command.

Upvotes: 7

Related Questions