12

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.

Community
  • 1
  • 1
dvdmn
  • 6,038
  • 7
  • 42
  • 51
  • I've an idea (not ideal solution).. I can check the target file for exist or not when all the process is done. if the file is exist and bigger than zero byte I would assume the process was successful. If the target file not exist get last line of the output and show it as error message.. – dvdmn Aug 30 '12 at 16:20

2 Answers2

5

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

sashoalm
  • 69,127
  • 105
  • 396
  • 720
  • 1
    Is this guaranteed to be reliable? – nafg May 02 '16 at 09:04
  • 8
    This does not work. FFmpeg does not (always) return non 0 on errors – DIDoS Oct 25 '16 at 21:11
  • 4
    @DIDoS Can you give an example? – sashoalm Oct 26 '16 at 06:34
  • how do i check that why it failed? I have added the ffmpeg as library simple tried to follow this link http://stackoverflow.com/questions/23683960/android-video-encoding-with-fr-and-resolution-manipulation/23815402#23815402 – Arpan Sharma Apr 27 '17 at 06:15
  • @ArpanSharma That question is for using ffmpeg as executable, not as library. But you can [ask a separate question](https://stackoverflow.com/questions/ask) for libraries. – sashoalm Apr 27 '17 at 07:05
  • @sashoalm I just have to compress a video before uploading in my android app. whatever way that seems fit.Can you guide me please – Arpan Sharma Apr 27 '17 at 07:08
  • @ArpanSharma [Ask a new question](https://stackoverflow.com/questions/ask). – sashoalm Apr 27 '17 at 07:10
  • is there an extensive list of cases in which this return fail to check for errors? – cregox May 10 '21 at 12:12
5

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.

Eleasar
  • 509
  • 10
  • 20
  • is there an extensive list of cases in which the return or the file fail to check for errors? – cregox May 10 '21 at 12:11