Resume transcoding a video with ffmpeg

2

I have a node server that uses child-process to use ffmpeg to convert a video to mp4. However if the server crashes while transcoding, then I'd like to resume transcoding the file (similar to -C with curl).

I figured I could just start transcoding the file from where it finished to a seperate file and then just concat the two. And while transcoding the file from where it finished works and the file that starts midway plays back fine, when I concat the two files with ffmpeg -i "concat:part1.mp4|part2.mp4" -c copy ouput.mp4 Only the first part will play, and when it gets to the second part it just stays on the last frame of the first part or goes black depending on the video player. (But playing part2.mp4 itself works fine)

There isn't any error during either conversion or the concat.

Jonathan.

Posted 2014-11-29T14:13:08.697

Reputation: 2 454

I assume you are transcoding the files to H264. Be aware that this codec uses interframe compression, i.e., the majority of the frames don't have complete information, but just the differences compared to the previous frame; therefore, you can't just concatenate them like that, since the references to the previous keyframes won't match. – PaulJ – 2014-11-29T14:24:48.503

I think he is treating them as two separate runs so I don't think he would see any referencing issue with the second file. The first file could have unexpected referencing issues at the end of the video due to the server crash which may be the problem.

Is the final file the expected size? Have you tried concatenating just the video streams without audio? Can you skip into part 2 without trying to do a clean transition from part 1? – dstob – 2014-12-05T17:54:34.340

I have tried without audio, and I hage tried skipping to the second part without transitioning from the 1st but it still doesn't play. Perhaps if I trim the first part by a minute or two before concating it? – Jonathan. – 2014-12-06T03:33:39.810

You've got 2 possible ways: clip part1 along the keyframe boundary (before the last keyframe) and encode part2 from there. And second - patch ffmpeg to store or reconstruct the encoder's internal state, which will unlikely be a viable solution due to numerous and numerous technical pitfalls. – ogurets – 2017-12-10T04:29:01.630

No answers