5

I am receiving an MPEG-TS Stream via UDP and saving the contents to a file using FFmpeg (using codec copy and mapping all streams). In cases where the stream stops, I would like to restart FFmpeg the moment it resumes and append to the existing file already written to.

How can I configure FFmpeg to append to the file and not overwrite it when it starts again?

The input and output containers are both MPEG-TS and the number of streams and codecs will be the same.

TomRay74
  • 513
  • 6
  • 17
  • 1
    I don't think it's implemented but you can just capture to different files and concatenate them later. You can use `-strftime 1 "%Y-%m-%d_%H-%M-%S.ts` to add a timestamp to your filename if needed. – aergistal Oct 13 '15 at 19:27
  • Unfortunately that would not work for me as the capture of the stream is just part of the solution I am working on. The file recorded is simultaneously transmitted further to other computers via node based network protocol I've made. It is kind of like a semi-live transfer solution. I could rewrite the code in my source node to allow for numbered files but it would be a hassle. The easiest solution would be if FFmpeg could continue writing to an already existing file instead of overwriting it. – TomRay74 Oct 13 '15 at 19:51
  • @TomRay74 hey, did you figure out the solution? It's been a while. – Patryk Cieszkowski May 29 '19 at 22:23

1 Answers1

3

You can output to stdout and use shell redirection to output to the file. This only works for formats that are directly concatenable such as mpegts and will create discontinuities:

ffmpeg -re -i udp://... -f mpegts - >> output.ts

aergistal
  • 29,947
  • 5
  • 70
  • 92
  • 2
    How to prevent discontinuities? I want to append several .ts chunks while playing the video but I can see the cut of chunks every 10 seconds. I don't have this problem if I overwrite the file (using -i "concat:chunk1.ts|chunk2.ts") instead of appending. I think it should be possible to do it with .ts chunks without overwriting because that's how HLS m3u8 livestream work, you can play a file while it is still downloading. – baptx Mar 05 '18 at 09:29
  • `-re` is useless here..? from [docs](https://ffmpeg.org/ffmpeg.html#Video-Options) it's required input value – 555Russich Dec 04 '22 at 04:22
  • 1
    @555Russich If I remember correctly, at the time when I answered this there was a difference in how UDP streams were handled when real-time emulation was active which prevented the command from terminating if the source went away for a while. It might not be needed anymore in the latest version. – aergistal Dec 05 '22 at 10:04