History

fftools/ffplay: stop using avfilter_graph_create_filter() incorrectly

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().

Anton Khirnov committed 2 years ago

Commit 577708a1 parent f6f0e051 file · +35 −23Browse files

Unified · Split

fftools/ffplay.c+35−23
@@ -1861,7 +1861,6 @@ static int configure_video_filters(AVFilterGraph *graph, VideoState *is, const c · 1860 unmodified lines
1861{1861{
1862 enum AVPixelFormat pix_fmts[FF_ARRAY_ELEMS(sdl_texture_format_map)];1862 enum AVPixelFormat pix_fmts[FF_ARRAY_ELEMS(sdl_texture_format_map)];
1863 char sws_flags_str[512] = "";1863 char sws_flags_str[512] = "";
1864 char buffersrc_args[256];
1865 int ret;1864 int ret;
1866 AVFilterContext *filt_src = NULL, *filt_out = NULL, *last_filter = NULL;1865 AVFilterContext *filt_src = NULL, *filt_out = NULL, *last_filter = NULL;
1867 AVCodecParameters *codecpar = is->video_st->codecpar;1866 AVCodecParameters *codecpar = is->video_st->codecpar;
@@ -1895,38 +1894,48 @@ static int configure_video_filters(AVFilterGraph *graph, VideoState *is, const c · 27 unmodified lines
1895 1894
1896 graph->scale_sws_opts = av_strdup(sws_flags_str);1895 graph->scale_sws_opts = av_strdup(sws_flags_str);
1897 1896
1898 snprintf(buffersrc_args, sizeof(buffersrc_args),1897
1899 "video_size=%dx%d:pix_fmt=%d:time_base=%d/%d:pixel_aspect=%d/%d:"1898 filt_src = avfilter_graph_alloc_filter(graph, avfilter_get_by_name("buffer"),
1900 "colorspace=%d:range=%d",1899 "ffplay_buffer");
1901 frame->width, frame->height, frame->format,1900 if (!filt_src) {
1902 is->video_st->time_base.num, is->video_st->time_base.den,1901 ret = AVERROR(ENOMEM);
1903 codecpar->sample_aspect_ratio.num, FFMAX(codecpar->sample_aspect_ratio.den, 1),
1904 frame->colorspace, frame->color_range);
1905 if (fr.num && fr.den)
1906 av_strlcatf(buffersrc_args, sizeof(buffersrc_args), ":frame_rate=%d/%d", fr.num, fr.den);
1907
1908 if ((ret = avfilter_graph_create_filter(&filt_src,
1909 avfilter_get_by_name("buffer"),
1910 "ffplay_buffer", buffersrc_args, NULL,
1911 graph)) < 0)
1912 goto fail;1902 goto fail;
1903 }
1904
1905 par->format = frame->format;
1906 par->time_base = is->video_st->time_base;
1907 par->width = frame->width;
1908 par->height = frame->height;
1909 par->sample_aspect_ratio = codecpar->sample_aspect_ratio;
1910 par->color_space = frame->colorspace;
1911 par->color_range = frame->color_range;
1912 par->frame_rate = fr;
1913 par->hw_frames_ctx = frame->hw_frames_ctx;1913 par->hw_frames_ctx = frame->hw_frames_ctx;
1914 ret = av_buffersrc_parameters_set(filt_src, par);1914 ret = av_buffersrc_parameters_set(filt_src, par);
1915 if (ret < 0)1915 if (ret < 0)
1916 goto fail;1916 goto fail;
1917 1917
1918 ret = avfilter_graph_create_filter(&filt_out,1918 ret = avfilter_init_dict(filt_src, NULL);
1919 avfilter_get_by_name("buffersink"),
1920 "ffplay_buffersink", NULL, NULL, graph);
1921 if (ret < 0)1919 if (ret < 0)
1922 goto fail;1920 goto fail;
1923 1921
1922 filt_out = avfilter_graph_alloc_filter(graph, avfilter_get_by_name("buffersink"),
1923 "ffplay_buffersink");
1924 if (!filt_out) {
1925 ret = AVERROR(ENOMEM);
1926 goto fail;
1927 }
1928
1924 if ((ret = av_opt_set_int_list(filt_out, "pix_fmts", pix_fmts, AV_PIX_FMT_NONE, AV_OPT_SEARCH_CHILDREN)) < 0)1929 if ((ret = av_opt_set_int_list(filt_out, "pix_fmts", pix_fmts, AV_PIX_FMT_NONE, AV_OPT_SEARCH_CHILDREN)) < 0)
1925 goto fail;1930 goto fail;
1926 if (!vk_renderer &&1931 if (!vk_renderer &&
1927 (ret = av_opt_set_int_list(filt_out, "color_spaces", sdl_supported_color_spaces, AVCOL_SPC_UNSPECIFIED, AV_OPT_SEARCH_CHILDREN)) < 0)1932 (ret = av_opt_set_int_list(filt_out, "color_spaces", sdl_supported_color_spaces, AVCOL_SPC_UNSPECIFIED, AV_OPT_SEARCH_CHILDREN)) < 0)
1928 goto fail;1933 goto fail;
1929 1934
1935 ret = avfilter_init_dict(filt_out, NULL);
1936 if (ret < 0)
1937 goto fail;
1938
1930 last_filter = filt_out;1939 last_filter = filt_out;
1931 1940
1932/* Note: this macro adds a filter before the lastly added filter, so the1941/* Note: this macro adds a filter before the lastly added filter, so the
@@ -2029,12 +2038,12 @@ static int configure_audio_filters(VideoState *is, const char *afilters, int for · 96 unmodified lines
2029 if (ret < 0)2038 if (ret < 0)
2030 goto end;2039 goto end;
2031 2040
2032 2041 filt_asink = avfilter_graph_alloc_filter(is->agraph, avfilter_get_by_name("abuffersink"),
2033 ret = avfilter_graph_create_filter(&filt_asink,2042 "ffplay_abuffersink");
2034 avfilter_get_by_name("abuffersink"), "ffplay_abuffersink",2043 if (!filt_asink) {
2035 NULL, NULL, is->agraph);2044 ret = AVERROR(ENOMEM);
2036 if (ret < 0)
2037 goto end;2045 goto end;
2046 }
2038 2047
2039 if ((ret = av_opt_set_int_list(filt_asink, "sample_fmts", sample_fmts, AV_SAMPLE_FMT_NONE, AV_OPT_SEARCH_CHILDREN)) < 0)2048 if ((ret = av_opt_set_int_list(filt_asink, "sample_fmts", sample_fmts, AV_SAMPLE_FMT_NONE, AV_OPT_SEARCH_CHILDREN)) < 0)
2040 goto end;2049 goto end;
@@ -2053,6 +2062,9 @@ static int configure_audio_filters(VideoState *is, const char *afilters, int for · 12 unmodified lines
2053 goto end;2062 goto end;
2054 }2063 }
2055 2064
2065 ret = avfilter_init_dict(filt_asink, NULL);
2066 if (ret < 0)
2067 goto end;
2056 2068
2057 if ((ret = configure_filtergraph(is->agraph, afilters, filt_asrc, filt_asink)) < 0)2069 if ((ret = configure_filtergraph(is->agraph, afilters, filt_asrc, filt_asink)) < 0)
2058 goto end;2070 goto end;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t