Add a stream using ffmpeg without creating a new file

I have some videos (.mp4) that have been tagged with metadata (descriptions, artwork, actors etc) and I now have subtitle files for them that I want to add as a stream.

I can use ffmpeg and set both the video and the .srt file as inputs and get a new output file but the output always seem to lose all of the container level metadata and it sometimes gets annoying always going back and deleting the original files.

Is there a way that I can add the subtitle file as a new stream to the video file without creating a new file? Just by modifying the original video file?

Programs like Subler seem to do this but, out of interest, can it be done from the command line?


You cannot edit a file in-place with ffmpeg – it always needs to create a new output file. I think that's the default for almost any program, and in many cases the output file needs to be seekable and editable by the program during writing.*

If the real issue is that you lose metadata, try:

ffmpeg -i input.mp4 -i subtitles.srt \
-c copy -c:s mov_text \
-map 0 -map 1 -map_metadata 0 output.mp4

You need to have ffmpeg convert SRT (SubRip) to MP4-compliant subtitles with -c:s mov_text, otherwise ffmpeg refuses to copy the stream over.**

The -map_metadata option should copy over all global metadata from the input MP4 file to the output, i.e. anything you set at the container level. The bitstream-level metadata should be copied automatically without any further options.

* Of course, programs like sponge from moreutils can "soak" up input and overwrite a file in-place, but this only works with muxers that support non-seekable output, and therefore not with MP4.
** There are problems with mov_text encoded subtitles and the QuickTime player, see FFmpeg ticket #1845 and also #2488.