Log in

View Full Version : Detect Invalid Video File


MysteryX
2nd August 2017, 19:25
I have written code that encodes videos in several segments and then merges at the end. It works fine *AS LONG AS* any segment is terminated cleanly. If you kill any of the FFMPEG processes, however, the merge will result in undefined behaviors.

How can I detect whether a video file is valid to prevent such undefined behavior? Is there any way to recover parts of an invalid file to make it valid, perhaps by discarding the end?

Thanks

StainlessS
2nd August 2017, 19:37
Recover Parts: Just do a remux in ffmpeg and it should chop off crap at the end.

Remux to MKV,


setlocal

REM Where to Find ffmpeg
set FFMPEG="C:\BIN\ffmpeg.exe"

REM Where to get input file, No terminating Backslash, "." = current directory
set INDIR="."


REM Where to place output file, No terminating Backslash.
set OUTDIR=".\OUTPUT"


FOR %%A IN (*.wmv *.mpg *.avi *.flv *.mov *.mp4 *.m4v *.RAM *.RM) DO (
%FFMPEG% -i "%INDIR%\%%A" -vcodec copy -acodec copy "%OUTDIR%\%%~nxA.MKV"

)

Pause


It dont like SPACE's in names.

EDIT: Maybe RaffRiff can comment on ffProbe use for error detection (Usually comes with full ffmpeg package).

MysteryX
2nd August 2017, 20:54
Remux is a good idea, it should work.

I however only want to do it if it is necessary -- how to know that?

MysteryX
5th August 2017, 03:47
In terms of terminating FFMPEG cleanly, I just found something. I run AVS2YUV and pipe it to FFMPEG; and now can run 4 instances in parallel. Killing FFMPEG gives an invalid file. Soft killing all 4 instances takes considerable time. If I hard kill the 4 instances of AVS2YUV, however, that stops immediately and FFMPEG still finishes writing its file :)

If someone kills a FFMPEG process manually, however, I still have no way of knowing the file is bad.