Kiran
Kiran

Reputation: 539

ffmpeg: HLS to mp4

I have one m3u8 file with ts segments. I am trying to convert a part of it to mp4 using the below command.

ffmpeg -i playlist.m3u8 -ss 30 -t 120 -c copy -bsf:a aac_adtstoasc -flags +global_header -y output.mp4

I manually calculated where my segments are located and concatenated those to form output.ts. And then converted that to mp4 using the below commands.

ffmpeg -f concat -safe 0 -i <(for f in ./*.ts; do echo "file '$PWD/$f'"; done) -c copy output.ts
ffmpeg -i output.ts -c copy -bsf:a aac_adtstoasc -flags +global_header -y output.mp4

I found that the second approach is taking far lesser time compared to the first one, an order of 10s of seconds. Someone, please let me know whether the comparison makes any sense and why there is so much difference between the two.

Upvotes: 1

Views: 4365

Answers (1)

Kiran
Kiran

Reputation: 539

I was using -ss incorrectly for the live stream.

-ss has to be used along side -live_start_index 0 before input file option -i input.m3u8.

For the live streaming from FFMpeg part, one should use -f hls -hls_playlist_type event than -f segment -segment_list_flags live for seek to work on live streaming.

As mentioned in the document for -ss, seek doesn't start exactly at 15th sec. And the duration is also not honoured(< 30secs).

ffmpeg -live_start_index 0 -ss 15  -i playlist.m3u8 -t 00:00:30 -c copy -bsf:a aac_adtstoasc -flags +global_header -y input.mp4

When used without -c copy and with transcoding and -accurate_seek, the duration is fine. But the seek position is the same as the one with -c copy.

Upvotes: 1

Related Questions