ffmpeg

ffmpeg: how to prevent wait in case of error


I use ffmpeg to add watermark to images/videos, using the following command line:

ffmpeg -y -f mjpeg -i input -i /tmp/watermark.png -filter_complex "..." -f mjpeg output

The problem is, in case the input file is not a jpeg file, the process will HANG instead of quit with an error:

Press [q] to stop, [?] for help
[mjpeg @ 0x126dc60] dqt: len 28602 is too large
Error while decoding stream #0:0: Invalid data found when processing input
frame=    0 fps=0.0 q=0.0 size=       0kB time=-577014:32:22.77 bitrate=  -0.0kbits/s speed=N/A

In my situation, the file has no extension, and I have to specify -f. In case I got the file type wrong, it is an acceptable bug, which I can fix as soon as I found such problem. However it is not good for me if ffmpeg hangs without returning to the parent process, because I have a very large queue of files to process, and I don't want any bug to block the processing task.


Solution

  • If you know how much the program takes on processing files you can use linux timeout command, to cancel the execution of any program after such time.

    You can also play around with the -t option in the ffmpeg command wich limits the time spent processing but the first option is better in my opinion.