Make MKV file suitable for streaming with ffmpeg (or avconv) - how to move all metadata to beginning of file?
The Matroska foundation offers a tool, mkclean, that performs a task similar to what qt-faststart does for MOV/MP4s.
Syntax:
mkclean in.mkv out.mkv
This will regenerate the cues index. To keep the original cues,
mkclean --keep-cues in.mkv out.mkv
FFmpeg can also do this, with some guesswork, on the user's part.
ffmpeg -i in.mkv -c copy -reserve_index_space 50k out.mkv
where the reserve_index_space
value in bytes is the size needed for the index. 50k
bytes is the suggested size for 1 hour of media.
Related videos on Youtube
Fredrick Brennan
Updated on September 18, 2022Comments
-
Fredrick Brennan almost 2 years
My question, I think, is pretty simple...
Sometimes I like to download large MKV files from a webserver of mine, and play them back while they are downloading. However, if I do this on MKV files I've transcoded, often the file will show that it is much shorter than it actually is, and after it gets to the end it will just keep playing and display an incorrect time...e.g. it will display 2:50/2:50 but keep playing, however if I try to seek backwards with the arrow keys the player will either crash or skip back to the beginning of the file.
So, how can I move all the metadata to the beginning of the file while encoding so that the player will know how long the file is without having the whole thing? You can do this with the
mp4
format by using-movflags faststart
, but how to do it formkv
?I'm sorry if this is already asked and answered elsewhere, I could not think of better keywords than I used and the ones I used produced no results.
-
Fredrick Brennan over 7 yearsThanks a lot! Before I accept--what are the benefits/drawbacks of keeping the cues versus not? Is it one of those things where if I have to ask I won't notice? :)
-
Gyan over 7 yearsThat would be my answer. It will render the cues to spec if regenerating them.
-
Fredrick Brennan over 7 yearsOK, I understand, the reason that this is happening is because the cues are all written at the end, and I need them at the front;
mkclean
will move the cues. Without--keep-cues
it will regenerate the cues, and with it it will preserve the current cues generated by ffmpeg...but since Cues are not Chapters...not much of a difference, but probably keeping the cues takes less CPU time and disk access than regenerating them. Thanks for your help once again :D