How to tell if ffmpeg errored or not?

18,588

Solution 1

I know this is very old but as i came across and found no other reliable answer and after some more testing:

The suggestion with checking for return of 0 is in general a good advice - but does not help in all cases. The other idea with checking if the file exists is also good - but again - does not help in all cases.

For example when the input file is a mp3 file that has an embedded cover - then ffmpeg does (in my tests) use this image and extracts that one as an (unusable) video file.

What i do now is to have debug level output and parse it for the number of muxed packets.

ffmpeg -i "wildlife.mp4" -c:v copy -an -sn "out.mp4" -y -loglevel debug 2> wildlife.txt

With a regex i search for this text:
Output stream .+ (video): [0-9][0-9]+ packets muxed \([0-9][0-9]+ bytes\)

(this assumes that every video has more than 9 packets - could of course be optimized for really short videos).

Of course for RTMP or other settings the output may differ but i think to parse the full output stream is the only option.

Solution 2

You could just check the exit code returned by ffmpeg. It should return 0 on success, anything else means it failed.

Share:
18,588
dvdmn
Author by

dvdmn

a guy with no desire for reputation.

Updated on June 09, 2022

Comments

  • dvdmn
    dvdmn about 2 years

    The Situation: I'm using ffmpeg (via .net) to save video files. I can get the output from ffmpeg but I dont know how can I customize the output to have better result.

    My Problem: My problem is, there is no certain difference between successful and failed operation.

    last line of success:

    video:1006kB audio:134kB subtitle:0 global headers:0kB muxing overhead 0.943510%

    last lines from fails

    c:\x\test-9-8/30/2012-9:29:56-AM.mp4: Invalid argument

    rtmp://cdn.tv/cdn-live39/definst/stream01: Unknown error occurred

    My Question: Is there an option (or command line parameter) to add some sort of return code (200: success, 500: error, etc)

    Thanks!

    PS: I saw this topic How to tell if ffmpeg errored? but there is no number before/after last line. I think the last version doesnt have number anymore.