diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2013-05-01 14:12:04 +0200 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2013-05-01 14:23:52 +0200 |
commit | 76c1f9200fa3bf16a47042c0c2a1bd11e408b56c (patch) | |
tree | c16437b77ee9ddfff2d7fb02f5aa33bf4f2f62fe /ffmpeg_filter.c | |
parent | 1a94d7c7c8ca2164c2a1e7d6f1fe7868b01e7e43 (diff) | |
parent | a83c0da539fb07260310bc3b34056239d2b138b2 (diff) | |
download | ffmpeg-76c1f9200fa3bf16a47042c0c2a1bd11e408b56c.tar.gz |
Merge commit 'a83c0da539fb07260310bc3b34056239d2b138b2'
* commit 'a83c0da539fb07260310bc3b34056239d2b138b2':
avconv: make -t insert trim/atrim filters.
The filter insertion code is merged but disabled as it is buggy.
For example it fails in various ways when used with -s with some files.
Also the trimming is arguably less accurate than the default without
filters in some cases.
These issues should be fixed before auto inserting the filters,
until then the user can explicitly add a trim/atrim filter when one is
wanted.
Conflicts:
Changelog
ffmpeg.c
ffmpeg_filter.c
tests/ref/fate/bethsoft-vid
tests/ref/lavf/aiff
tests/ref/lavf/asf
tests/ref/lavf/au
tests/ref/lavf/avi
tests/ref/lavf/dpx
tests/ref/lavf/ffm
tests/ref/lavf/gxf
tests/ref/lavf/jpg
tests/ref/lavf/mkv
tests/ref/lavf/mmf
tests/ref/lavf/mov
tests/ref/lavf/mpg
tests/ref/lavf/nut
tests/ref/lavf/ogg
tests/ref/lavf/pcx
tests/ref/lavf/png
tests/ref/lavf/rm
tests/ref/lavf/ts
tests/ref/lavf/voc
tests/ref/lavf/voc_s16
tests/ref/lavf/wav
Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'ffmpeg_filter.c')
-rw-r--r-- | ffmpeg_filter.c | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/ffmpeg_filter.c b/ffmpeg_filter.c index e7e7242788..b9e3e4eed1 100644 --- a/ffmpeg_filter.c +++ b/ffmpeg_filter.c @@ -276,6 +276,54 @@ static void init_input_filter(FilterGraph *fg, AVFilterInOut *in) ist->filters[ist->nb_filters - 1] = fg->inputs[fg->nb_inputs - 1]; } +static int insert_trim(OutputStream *ost, AVFilterContext **last_filter, int *pad_idx) +{ + OutputFile *of = output_files[ost->file_index]; + AVFilterGraph *graph = (*last_filter)->graph; + AVFilterContext *ctx; + const AVFilter *trim; + const char *name = ost->st->codec->codec_type == AVMEDIA_TYPE_VIDEO ? "trim" : "atrim"; + char filter_name[128]; + int ret = 0; + + if (of->recording_time == INT64_MAX) + return 0; + + return 0; + + trim = avfilter_get_by_name(name); + if (!trim) { + av_log(NULL, AV_LOG_ERROR, "%s filter not present, cannot limit " + "recording time.\n", name); + return AVERROR_FILTER_NOT_FOUND; + } + + snprintf(filter_name, sizeof(filter_name), "%s for output stream %d:%d", + name, ost->file_index, ost->index); + ctx = avfilter_graph_alloc_filter(graph, trim, filter_name); + if (!ctx) + return AVERROR(ENOMEM); + + ret = av_opt_set_double(ctx, "duration", (double)of->recording_time / 1e6, + AV_OPT_SEARCH_CHILDREN); + if (ret < 0) { + av_log(ctx, AV_LOG_ERROR, "Error configuring the %s filter", name); + return ret; + } + + ret = avfilter_init_str(ctx, NULL); + if (ret < 0) + return ret; + + ret = avfilter_link(*last_filter, *pad_idx, ctx, 0); + if (ret < 0) + return ret; + + *last_filter = ctx; + *pad_idx = 0; + return 0; +} + static int configure_output_video_filter(FilterGraph *fg, OutputFilter *ofilter, AVFilterInOut *out) { char *pix_fmts; @@ -352,6 +400,11 @@ static int configure_output_video_filter(FilterGraph *fg, OutputFilter *ofilter, pad_idx = 0; } + ret = insert_trim(ost, &last_filter, &pad_idx); + if (ret < 0) + return ret; + + if ((ret = avfilter_link(last_filter, pad_idx, ofilter->filter, 0)) < 0) return ret; @@ -458,6 +511,10 @@ static int configure_output_audio_filter(FilterGraph *fg, OutputFilter *ofilter, AUTO_INSERT_FILTER("-vol", "volume", args); } + ret = insert_trim(ost, &last_filter, &pad_idx); + if (ret < 0) + return ret; + if ((ret = avfilter_link(last_filter, pad_idx, ofilter->filter, 0)) < 0) return ret; |