[FFmpeg-devel] [PATCH] ffmpeg_opt: add -to option to specify stop time
Paul B Mahol
onemda at gmail.com
Mon Feb 25 13:29:11 CET 2013
On 2/25/13, Jean First <jeanfirst at gmail.com> wrote:
>
> Signed-off-by: Jean First <jeanfirst at gmail.com>
> ---
>
> I forgot to add the ffmpeg.h file. Sorry for the noise.
>
> ffmpeg.h | 1 +
> ffmpeg_opt.c | 32 ++++++++++++++++++++++++++++++--
> 2 files changed, 31 insertions(+), 2 deletions(-)
>
> diff --git a/ffmpeg.h b/ffmpeg.h
> index c64a015..012e772 100644
> --- a/ffmpeg.h
> +++ b/ffmpeg.h
> @@ -114,6 +114,7 @@ typedef struct OptionsContext {
> int chapters_input_file;
>
> int64_t recording_time;
> + int64_t stop_time;
> uint64_t limit_filesize;
> float mux_preload;
> float mux_max_delay;
> diff --git a/ffmpeg_opt.c b/ffmpeg_opt.c
> index b2a913f..92aa68a 100644
> --- a/ffmpeg_opt.c
> +++ b/ffmpeg_opt.c
> @@ -96,6 +96,7 @@ static int do_psnr = 0;
> static int input_sync;
>
> static int64_t recording_time = INT64_MAX;
> +static int64_t stop_time = INT64_MAX;
>
> static void uninit_options(OptionsContext *o, int is_input)
> {
> @@ -128,16 +129,27 @@ static void uninit_options(OptionsContext *o, int
> is_input)
> av_freep(&o->streamid_map);
> av_freep(&o->attachments);
>
> - if (is_input)
> + if (is_input) {
> recording_time = o->recording_time;
> - else
> + stop_time = o->stop_time;
> + } else {
> recording_time = INT64_MAX;
> + stop_time = INT64_MAX;
> + }
> }
>
> static void init_options(OptionsContext *o, int is_input)
> {
> memset(o, 0, sizeof(*o));
>
> + if (!is_input && stop_time != INT64_MAX) {
> + o->stop_time = stop_time;
> + av_log(NULL, AV_LOG_WARNING,
> + "-to is not an input option, keeping it for the next
> output;"
> + " consider fixing your command line.\n");
> + } else
> + o->stop_time = INT64_MAX;
> +
> if (!is_input && recording_time != INT64_MAX) {
> o->recording_time = recording_time;
> av_log(NULL, AV_LOG_WARNING,
> @@ -1655,6 +1667,20 @@ loop_end:
> exit(1);
> }
>
> + if (o->stop_time != INT64_MAX && o->recording_time != INT64_MAX) {
> + o->stop_time = INT64_MAX;
> + av_log(NULL, AV_LOG_WARNING, "-t and -to cannot be used together;
> using -t.\n");
> + }
> +
> + if (o->stop_time != INT64_MAX && o->recording_time == INT64_MAX) {
> + if (o->stop_time <= o->start_time) {
> + av_log(NULL, AV_LOG_WARNING, "-to value smaller then -ss;
> ignoring -to.\n");
> + o->stop_time = INT64_MAX;
> + } else {
> + o->recording_time = o->stop_time - o->start_time;
> + }
> + }
> +
> GROW_ARRAY(output_files, nb_output_files);
> if (!(output_files[nb_output_files - 1] =
> av_mallocz(sizeof(*output_files[0]))))
> exit(1);
> @@ -2388,6 +2414,8 @@ const OptionDef options[] = {
> { "t", HAS_ARG | OPT_TIME | OPT_OFFSET, { .off
> = OFFSET(recording_time) },
> "record or transcode \"duration\" seconds of audio/video",
> "duration" },
> + { "to", HAS_ARG | OPT_TIME | OPT_OFFSET, { .off
> = OFFSET(stop_time) },
> + "record or transcode stop time", "time_stop" },
> { "fs", HAS_ARG | OPT_INT64 | OPT_OFFSET, { .off
> = OFFSET(limit_filesize) },
> "set the limit file size in bytes", "limit_size" },
> { "ss", HAS_ARG | OPT_TIME | OPT_OFFSET, { .off
> = OFFSET(start_time) },
> --
> 1.7.10.2 (Apple Git-33)
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
Doc changes should be part of same commit.
More information about the ffmpeg-devel
mailing list