2
votes

I'm trying to segment multiple mp4 files from a .txt (just like concatenation works), but it doesn't seem to work for me.

This is my concat.txt:

file video1.mp4
file video2.mp4
file video3.mp4

etc...

and my ffmpeg commands are:

ffmpeg -i concat.txt -map 0 -codec:v libx264 -codec:a libfaac -f ssegment \
-segment_list playlist.m3u8 -segment_list_flags +live -segment_time 10 out%03d.ts

Unfortunately every mediaplayer throws an error on playback.

Can I use the concat file, or do I have to concat all the mp4s first into a single mp4 file, and segment that mp4 file to get the final m3u8?

1
try it and see I guess... - rogerdpack
Thanks! -f concat did it :) - Endre Börcsök
@aergistal can you please explain converting input file to MPEG-TS and then to .m3u8 by commands if possible ? I am right now using a simple command as mentioned in ffmpeg docs which is ffmpeg -re -i in.mkv -codec copy -map 0 -f segment -segment_list playlist.m3u8 \ -segment_list_flags +live -segment_time 10 out%03d.mkv - Vinay
The comment was not properly worded and was misleading so I removed it. What I meant is that if you have files with different codecs you need to convert them to use the same codecs for the concat demuxer to work. I added a proper answer with an example command. - aergistal
Have you tried the concat filter? ffmpeg -i "concat:file1.mp4|file2.mp4|fileN.mp4" [...] - Gergely Lukacsy

1 Answers

2
votes

The ffmpeg concat demuxer requires the same codecs for the input files, although the container can vary. You also need to make sure the video and audio streams have the same IDs across all files.

ffmpeg -re -f concat -i concat.txt -c:v libx264 -vbsf h264_mp4toannexb -r 25 -g 75 -c:a libfdk_aac -hls_time 3 playlist.m3u8

I used the h264_mp4toannexb bitstream filter to convert the H.264 stream to the Annex B format required by MPEG-TS, set the GOP size to 75 (3 seconds at 25 fps) and used a segment length of 3 seconds since each segment should start with a keyframe.