1

I'm running web app that is using ffmpeg to convert image + audio to video and sometimes someone happens to upload something that will make ffmpeg run forever on 100% CPU until the whole drive is filled.

It happens when someone uploads some corrupted or weird file, or recently I was able to catch that it also happens when there is image instead of audio (has to do something with -loop)

ffmpeg -loop 1 -r 1 -i image.jpg -i image2.jpg -vcodec libx264 -acodec copy -xerror -preset ultrafast -r 1 -shortest out.mp4

I know I could validate user input, but this should be not happening. What ffmpeg query would prevent this, but also would provide identical file?

I tried adding -stimeout or -timeout but it didn't work.

1 Answer 1

1

In the given command,

ffmpeg -loop 1 -r 1 -i image.jpg -i image2.jpg -vcodec libx264 -acodec copy -xerror -preset ultrafast -r 1 -shortest out.mp4

since no map assignments are made, ffmpeg maps the first video input to the output. Since the loop option has been set, it is an unending stream. The -shortest has no effect as the 2nd image doesn't get auto-mapped and so its duration (0.04s) has no relevance.

A workaround is to add a finite dummy audio stream, created like so - ffmpeg -f lavfi -t 1 -i anullsrc=cl=mono dummy.m4a

ffmpeg -loop 1 -r 1 -i image.jpg -i image2.jpg -i dummy.m4a -vcodec libx264 -acodec copy -xerror -preset ultrafast -r 1 -shortest out.mp4

This won't tackle the issue of 'weird' files.


There's also a -timelimit seconds e.g. -timelimit 600 to exit ffmpeg after 10 minutes. However, this uses system call setrlimit and AFAICT, isn't available on Windows natively, so I can't test it right now.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .