ffmpeg rebuild file stream

(Last Updated On: May 31, 2020)

동영상의 손상등으로 재생 중에 파일에 오류가 있을 때 일부 플레이어에서는 CPU 100% 를 유지한 채 뻗어버리거나 crash 된다. 그럴때는 파일을 새로 작성해보면 괜찮을 거다???

 

Plan A
ffmpeg -err_detect ignore_err -i video.mkv -c copy video_fixed.mkv
Plan B
ffmpeg -i video.mkv -c copy video_fixed.mkv

 

 

Result

[mp4 @ 000002c30c344c40] Non-monotonous DTS in output stream 0:0; previous: 0, current: 0; changing to 1. This may result in incorrect timestamps in the output file.
[mp4 @ 000002c30c344c40] Non-monotonous DTS in output stream 0:1; previous: 0, current: -2048; changing to 1. This may result in incorrect timestamps in the output file.
[mp4 @ 000002c30c344c40] Non-monotonous DTS in output stream 0:1; previous: 1, current: -1024; changing to 2. This may result in incorrect timestamps in the output file.
[mp4 @ 000002c30c344c40] Non-monotonous DTS in output stream 0:1; previous: 2, current: 0; changing to 3. This may result in incorrect timestamps in the output file.
[mp4 @ 000002c30c344c40] Non-monotonous DTS in output stream 0:1; previous: 325300266, current: 325299177; changing to 325300267. This may result in incorrect timestamps in the output file.
[mp4 @ 000002c30c344c40] Non-monotonous DTS in output stream 0:1; previous: 325300267, current: 325300201; changing to 325300268. This may result in incorrect timestamps in the output file.
[mov,mp4,m4a,3gp,3g2,mj2 @ 000002c30c33e1c0] DTS 325255675 < 325303296 out of order
[mp4 @ 000002c30c344c40] Non-monotonous DTS in output stream 0:0; previous: 325303296, current: 325255675; changing to 325303297. This may result in incorrect timestamps in the output file.
[matroska,webm @ 000002570741d200] 0x00 at pos 1509966323 (0x5a0041f3) invalid as first byte of an EBML number
[matroska,webm @ 000002570741d200] 0x00 at pos 1803552002 (0x6b800502) invalid as first byte of an EBML number
[matroska,webm @ 000002570741d200] 0x00 at pos 2189437362 (0x828029b2) invalid as first byte of an EBML number
[matroska,webm @ 000002570741d200] 0x00 at pos 3481287702 (0xcf803c16) invalid as first byte of an EBML number
[matroska,webm @ 000002570741d200] 0x00 at pos 4244659229 (0xfd005c1d) invalid as first byte of an EBML number
[matroska,webm @ 000002570741d200] 0x00 at pos 4429199803 (0x1080039bb) invalid as first byte of an EBML number

실제로 어딘가가 손상된거같은 동영상 파일을 돌려보니 뭐라뭐라 뜬다. 그렇지만 생성된 파일은 플레이어에서 실행해보면 정상으로 실행된다.

 

오류

[mpegts @ 000001ff99b3d200] max resync size reached, could not find sync bytekbits/s speed= 197x
    Last message repeated 1 times
[mpegts @ 000001ff99b3d200] PES packet size mismatch
[mpegts @ 000001ff99b3d200] Packet corrupt (stream = 1, dts = 524651190).
[mpegts @ 000001ff99b3d200] max resync size reached, could not find sync byte
    Last message repeated 13 times
[aac_adtstoasc @ 000001ff99c96740] Error parsing ADTS frame header!
[mp4 @ 000001ff9b5d5fc0] Error applying bitstream filters to an output packet for stream #1: Invalid data found when processing input
av_interleaved_write_frame(): Invalid data found when processing input
Conversion failed!

오류가 나타나기도 한다..

ffmpeg -i broken.mp4 -c:v libx264 -c:a aac -b:a 160k -bsf:v h264_mp4toannexb -f mpegts -crf 32 pqr.ts

오류가 나면 강제로 인코딩해버린다.

ffmpeg -i pqr.ts -map 0 -c copy rebuild.mp4

다시 mp4로 씌움