4
2
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?
Using process substitution and a simple
cat
, I was able to modify a file in place. Seems fast and to work great. Is this problematic in anyway? – rien333 – 2018-10-30T12:28:47.7101@rien333 Depends on when the output file is being written in relation to the input being read. I can imagine that this depends on the output container as well (for some formats it must be seekable). I would not generally advise to do so, but instead use a temporary file. See also my first footnote in the post above. – slhck – 2018-10-30T12:31:08.293
Ah good. I didn't know you could map metadata like that. That will be very handy, although it is annoying that you can't just 'inject' a stream. You say that
only works with muxers that support non-seekable output, and therefore not with MP4
so how can Subler do this with mp4s? When I add a subtitle stream to a mp4 using that it takes less than two seconds, so it cant be creating a whole new file and deleting the old...? – Sam – 2013-07-30T20:32:10.550I think this is a design choice, and
– slhck – 2013-07-30T20:45:07.030ffmpeg
developers never intended to do that. Of course, I don't know what subler does – I haven't looked at its source. It could also be using temporary files, deleting the original, and replacing it with the new one. Since bitstream copies are very fast you wouldn't see the difference. I think MP4Box can also do in-place edits, but I always forget its option syntax… haven't really used it a lot.