This function creates AND initializes a filter, so setting any filter options after it is wrong. It happens to work when the filter's init function does not touch the options in question, but is forbidden by the API and is not guaranteed to remain functional. Instead, use avfilter_graph_alloc_filter(), followed by setting the options, and avfilter_init_dict().
Unified · Split
| @@ -1586,14 +1586,18 @@ static int configure_output_audio_filter(FilterGraph *fg, AVFilterGraph *graph, · 1585 unmodified lines | |||
| 1586 | int ret; | 1586 | int ret; |
| 1587 | 1587 | ||
| 1588 | snprintf(name, sizeof(name), "out_%s", ofp->name); | 1588 | snprintf(name, sizeof(name), "out_%s", ofp->name); |
| 1589 | ret = avfilter_graph_create_filter(&ofp->filter, | 1589 | ofp->filter = avfilter_graph_alloc_filter(graph, |
| 1590 | avfilter_get_by_name("abuffersink"), | 1590 | avfilter_get_by_name("abuffersink"), |
| 1591 | name, NULL, NULL, graph); | 1591 | name); |
| 1592 | if (ret < 0) | 1592 | if (!ofp->filter) |
| 1593 | return ret; | 1593 | return AVERROR(ENOMEM); |
| 1594 | if ((ret = av_opt_set_int(ofp->filter, "all_channel_counts", 1, AV_OPT_SEARCH_CHILDREN)) < 0) | 1594 | if ((ret = av_opt_set_int(ofp->filter, "all_channel_counts", 1, AV_OPT_SEARCH_CHILDREN)) < 0) |
| 1595 | return ret; | 1595 | return ret; |
| 1596 | 1596 | ||
| 1597 | ret = avfilter_init_dict(ofp->filter, NULL); | ||
| 1598 | if (ret < 0) | ||
| 1599 | return ret; | ||
| 1600 | |||
| 1597 | #define AUTO_INSERT_FILTER(opt_name, filter_name, arg) do { \ | 1601 | #define AUTO_INSERT_FILTER(opt_name, filter_name, arg) do { \ |
| 1598 | AVFilterContext *filt_ctx; \ | 1602 | AVFilterContext *filt_ctx; \ |
| 1599 | \ | 1603 | \ |
| @@ -1686,9 +1690,6 @@ static int configure_input_video_filter(FilterGraph *fg, AVFilterGraph *graph, · 86 unmodified lines | |||
| 1686 | AVFilterContext *last_filter; | 1690 | AVFilterContext *last_filter; |
| 1687 | const AVFilter *buffer_filt = avfilter_get_by_name("buffer"); | 1691 | const AVFilter *buffer_filt = avfilter_get_by_name("buffer"); |
| 1688 | const AVPixFmtDescriptor *desc; | 1692 | const AVPixFmtDescriptor *desc; |
| 1689 | AVRational fr = ifp->opts.framerate; | ||
| 1690 | AVRational sar; | ||
| 1691 | AVBPrint args; | ||
| 1692 | char name[255]; | 1693 | char name[255]; |
| 1693 | int ret, pad_idx = 0; | 1694 | int ret, pad_idx = 0; |
| 1694 | AVBufferSrcParameters *par = av_buffersrc_parameters_alloc(); | 1695 | AVBufferSrcParameters *par = av_buffersrc_parameters_alloc(); |
| @@ -1698,30 +1699,34 @@ static int configure_input_video_filter(FilterGraph *fg, AVFilterGraph *graph, · 3 unmodified lines | |||
| 1698 | if (ifp->type_src == AVMEDIA_TYPE_SUBTITLE) | 1699 | if (ifp->type_src == AVMEDIA_TYPE_SUBTITLE) |
| 1699 | sub2video_prepare(ifp); | 1700 | sub2video_prepare(ifp); |
| 1700 | 1701 | ||
| 1701 | sar = ifp->sample_aspect_ratio; | ||
| 1702 | if(!sar.den) | ||
| 1703 | sar = (AVRational){0,1}; | ||
| 1704 | av_bprint_init(&args, 0, AV_BPRINT_SIZE_AUTOMATIC); | ||
| 1705 | av_bprintf(&args, | ||
| 1706 | "video_size=%dx%d:pix_fmt=%d:time_base=%d/%d:" | ||
| 1707 | "pixel_aspect=%d/%d:colorspace=%d:range=%d", | ||
| 1708 | ifp->width, ifp->height, ifp->format, | ||
| 1709 | ifp->time_base.num, ifp->time_base.den, sar.num, sar.den, | ||
| 1710 | ifp->color_space, ifp->color_range); | ||
| 1711 | if (fr.num && fr.den) | ||
| 1712 | av_bprintf(&args, ":frame_rate=%d/%d", fr.num, fr.den); | ||
| 1713 | snprintf(name, sizeof(name), "graph %d input from stream %s", fg->index, | 1702 | snprintf(name, sizeof(name), "graph %d input from stream %s", fg->index, |
| 1714 | ifp->opts.name); | 1703 | ifp->opts.name); |
| 1715 | 1704 | ||
| 1716 | 1705 | ifp->filter = avfilter_graph_alloc_filter(graph, buffer_filt, name); | |
| 1717 | if ((ret = avfilter_graph_create_filter(&ifp->filter, buffer_filt, name, | 1706 | if (!ifp->filter) { |
| 1718 | args.str, NULL, graph)) < 0) | 1707 | ret = AVERROR(ENOMEM); |
| 1719 | goto fail; | 1708 | goto fail; |
| 1720 | par->hw_frames_ctx = ifp->hw_frames_ctx; | 1709 | } |
| 1710 | |||
| 1711 | par->format = ifp->format; | ||
| 1712 | par->time_base = ifp->time_base; | ||
| 1713 | par->frame_rate = ifp->opts.framerate; | ||
| 1714 | par->width = ifp->width; | ||
| 1715 | par->height = ifp->height; | ||
| 1716 | par->sample_aspect_ratio = ifp->sample_aspect_ratio.den > 0 ? | ||
| 1717 | ifp->sample_aspect_ratio : (AVRational){ 0, 1 }; | ||
| 1718 | par->color_space = ifp->color_space; | ||
| 1719 | par->color_range = ifp->color_range; | ||
| 1720 | par->hw_frames_ctx = ifp->hw_frames_ctx; | ||
| 1721 | ret = av_buffersrc_parameters_set(ifp->filter, par); | 1721 | ret = av_buffersrc_parameters_set(ifp->filter, par); |
| 1722 | if (ret < 0) | 1722 | if (ret < 0) |
| 1723 | goto fail; | 1723 | goto fail; |
| 1724 | av_freep(&par); | 1724 | av_freep(&par); |
| 1725 | |||
| 1726 | ret = avfilter_init_dict(ifp->filter, NULL); | ||
| 1727 | if (ret < 0) | ||
| 1728 | goto fail; | ||
| 1729 | |||
| 1725 | last_filter = ifp->filter; | 1730 | last_filter = ifp->filter; |
| 1726 | 1731 | ||
| 1727 | desc = av_pix_fmt_desc_get(ifp->format); | 1732 | desc = av_pix_fmt_desc_get(ifp->format); |