[FFmpeg-user] converting a video with corrupted chapter times

bbb ffmpeg-user at bugblatterbeast.de
Wed Feb 17 01:28:57 EET 2021


Hi,

I had a video that I wanted to convert using this command:
> ffmpeg -i INPUT.mkv -c:v libx264 -c:a ac3 -map 0 OUTPUT.mkv

But I always got the following error:
> Could not write header for output file #0 (incorrect codec parameters 
> ?): Invalid data found when processing input

Reason was, that the start-time and end-time of a chapter was mixed up. 
It was possible to convert the video with option -map_chapters -1, but I 
wanted to preserve the chapters.

I've extracted the metadata using this:
> ffmpeg -i INPUT.mkv -f ffmetadata METADATAFILE

I've fixed the chapter times in the metadata file and tried this:
> ffmpeg -i INPUT.mkv -i METADATAFILE -map_metadata 1 -c:v libx264 -c:a 
> ac3 -map 0 OUTPUT.mkv

I got the same error as before. The chapter information from input file 
#1 was listed correctly though. I've even tried it this way like in the 
example from the documentation:
> ffmpeg -i INPUT.mkv -i METADATAFILE -map_metadata 1 -codec copy 
> OUTPUT.mkv

That didn't work either. In the end I had to create a temp file without 
the corrupt metadata like this:
> ffmpeg -i INPUT.mkv -map_chapters -1 -map 0 TEMP.mkv

After that I was able to join the fixed metadata I've prepared with this 
command:
> ffmpeg -i TEMP.mkv -i METADATAFILE -map_metadata 1 -c:v libx264 -c:a 
> ac3 -map 0 OUTPUT.mkv


I'm glad it worked but I can't help wondering if there would have been 
an easier way to do it.


Is it possible to fix the chapter time automatically when start-time and 
end-time are mixed up?
Is it possible to make ffmpeg completely ignore the corrupt metadata of 
input file #0 and just override it with metadata from file #1?


More information about the ffmpeg-user mailing list