[FFmpeg-cvslog] r21347 - in trunk: cmdutils.c cmdutils.h ffmpeg.c
mru
subversion
Wed Jan 20 07:42:39 CET 2010
Author: mru
Date: Wed Jan 20 07:42:39 2010
New Revision: 21347
Log:
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.
Modified:
trunk/cmdutils.c
trunk/cmdutils.h
trunk/ffmpeg.c
Modified: trunk/cmdutils.c
==============================================================================
--- trunk/cmdutils.c Wed Jan 20 07:01:54 2010 (r21346)
+++ trunk/cmdutils.c Wed Jan 20 07:42:39 2010 (r21347)
@@ -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
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;
Modified: trunk/cmdutils.h
==============================================================================
--- trunk/cmdutils.h Wed Jan 20 07:01:54 2010 (r21346)
+++ trunk/cmdutils.h Wed Jan 20 07:42:39 2010 (r21347)
@@ -56,6 +56,11 @@ int opt_default(const char *opt, const c
int opt_loglevel(const char *opt, const char *arg);
/**
+ * Limit the execution time.
+ */
+int opt_timelimit(const char *opt, const char *arg);
+
+/**
* Parses a string and returns its corresponding value as a double.
* Exits from the application if the string cannot be correctly
* parsed or the corresponding value is invalid.
Modified: trunk/ffmpeg.c
==============================================================================
--- trunk/ffmpeg.c Wed Jan 20 07:01:54 2010 (r21346)
+++ trunk/ffmpeg.c Wed Jan 20 07:42:39 2010 (r21347)
@@ -353,6 +353,10 @@ static void term_init(void)
signal(SIGINT , sigterm_handler); /* Interrupt (ANSI). */
signal(SIGTERM, sigterm_handler); /* Termination (ANSI). */
+#ifdef SIGXCPU
+ signal(SIGXCPU, sigterm_handler);
+#endif
+
/*
register a function to be called at normal program termination
*/
@@ -3863,6 +3867,7 @@ static const OptionDef options[] = {
{ "dframes", OPT_INT | HAS_ARG, {(void*)&max_frames[CODEC_TYPE_DATA]}, "set the number of data frames to record", "number" },
{ "benchmark", OPT_BOOL | OPT_EXPERT, {(void*)&do_benchmark},
"add timings for benchmarking" },
+ { "timelimit", OPT_FUNC2 | HAS_ARG, {(void*)opt_timelimit}, "set max runtime in seconds", "limit" },
{ "dump", OPT_BOOL | OPT_EXPERT, {(void*)&do_pkt_dump},
"dump each input packet" },
{ "hex", OPT_BOOL | OPT_EXPERT, {(void*)&do_hex_dump},
More information about the ffmpeg-cvslog
mailing list