Skip to content
Advertisement

Overwriting TS Stream File with FFMPEG in Linux

I’m trying to convert rtmp streams to m3u8 stream. To reach that aim I use FFMPEG. Now, there is no problem with converting and downloading. However, it writes lots of .ts file such as channel0000.ts,channel0001.ts,channel0002.ts. Per every 10 seconds, 1 ts file is created. In this point, I want a single ts file. In other words, I need overwriting because I don’t want to store all the stream I need just last 10 seconds. When I try to write on the same file I get this error:

Invalid segment filename template 'channel.ts'
Could not write header for output file #0 (incorrect codec parameters ?):   Invalid argumentStream mapping:
Stream #0:0 -> #0:0 (copy)
Stream #0:1 -> #0:1 (copy)
Last message repeated 1 times

Here is my FFMPEG command.

ffmpeg -loglevel quiet -i rtmp://example -c:v libx264 -profile:v baseline -level 3.1 -c:a aac -strict experimental -f mpegts - | ffmpeg -i - -c copy -map 0 -f segment -segment_list channel.m3u8 -segment_format mpegts -segment_time 10 channel%04d.ts

Any suggestion?

Advertisement

Answer

In FFMPEG documentation, I found “segment_wrap” options. When you add this option, files are written in a loop. In my case I added “-segment_wrap 1” command part and it writes just a single file now.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement