Add -timelimit option

This option limits the CPU time used by ffmpeg to the number of seconds
specified.  After this time, the OS sends a SIGXCPU signal, which we
handle and attempt to exit cleanly.  If the process is stuck, the OS
will deliver a SIGKILL one second later, forcibly terminating the
process.

This functionality is useful in automated setups where a runaway ffmpeg
process would otherwise go undetected.

Originally committed as revision 21347 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
Måns Rullgård 2010-01-20 06:42:39 +00:00
parent 5e7dfb7de1
commit ffcc6e24f5
3 changed files with 26 additions and 0 deletions

View file

@ -41,6 +41,9 @@
#if CONFIG_NETWORK
#include "libavformat/network.h"
#endif
#if HAVE_SYS_RESOURCE_H
#include <sys/resource.h>
#endif
#undef exit
@ -257,6 +260,19 @@ int opt_loglevel(const char *opt, const char *arg)
return 0;
}
int opt_timelimit(const char *opt, const char *arg)
{
#if HAVE_SYS_RESOURCE_H
int lim = parse_number_or_die(opt, arg, OPT_INT64, 0, INT_MAX);
struct rlimit rl = { lim, lim + 1 };
if (setrlimit(RLIMIT_CPU, &rl))
perror("setrlimit");
#else
fprintf(stderr, "Warning: -%s not implemented on this OS\n", opt);
#endif
return 0;
}
void set_context_opts(void *ctx, void *opts_ctx, int flags)
{
int i;