diff mbox series

[FFmpeg-devel,1/2] avfilter/src_movie: add format_opts for the opened file

Message ID 1637592434-16132-1-git-send-email-lance.lmwang@gmail.com
State New
Headers show
Series [FFmpeg-devel,1/2] avfilter/src_movie: add format_opts for the opened file
Related show

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished
andriy/make_ppc success Make finished
andriy/make_fate_ppc success Make fate finished

Commit Message

Limin Wang Nov. 22, 2021, 2:47 p.m. UTC
From: Limin Wang <lance.lmwang@gmail.com>

Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
---
 doc/filters.texi        | 5 +++++
 libavfilter/src_movie.c | 8 +++++++-
 2 files changed, 12 insertions(+), 1 deletion(-)

Comments

Andreas Rheinhardt Nov. 26, 2021, 6:36 a.m. UTC | #1
lance.lmwang@gmail.com:
> From: Limin Wang <lance.lmwang@gmail.com>
> 
> Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
> ---
>  doc/filters.texi        | 5 +++++
>  libavfilter/src_movie.c | 8 +++++++-
>  2 files changed, 12 insertions(+), 1 deletion(-)
> 
> diff --git a/doc/filters.texi b/doc/filters.texi
> index c3ccaf9..6c35788 100644
> --- a/doc/filters.texi
> +++ b/doc/filters.texi
> @@ -28386,6 +28386,11 @@ timestamps.
>  
>  @item dec_threads
>  Specifies the number of threads for decoding
> +
> +@item format_opts
> +Specify format options for the opened file. Format options can be specified
> +as a list of @var{key}=@var{value} pairs separated by ':'. For example,
> +some protocol you need to add protocol_whitelist for the opened file.
>  @end table
>  
>  It allows overlaying a second video on top of the main input of
> diff --git a/libavfilter/src_movie.c b/libavfilter/src_movie.c
> index 220a43c..5e52015 100644
> --- a/libavfilter/src_movie.c
> +++ b/libavfilter/src_movie.c
> @@ -74,6 +74,7 @@ typedef struct MovieContext {
>      int max_stream_index; /**< max stream # actually used for output */
>      MovieStream *st; /**< array of all streams, one per output */
>      int *out_index; /**< stream number -> output number map, or -1 */
> +    AVDictionary *format_opts;
>  } MovieContext;
>  
>  #define OFFSET(x) offsetof(MovieContext, x)
> @@ -92,6 +93,7 @@ static const AVOption movie_options[]= {
>      { "loop",         "set loop count",          OFFSET(loop_count),   AV_OPT_TYPE_INT,    {.i64 =  1},  0,        INT_MAX, FLAGS },
>      { "discontinuity", "set discontinuity threshold", OFFSET(discontinuity_threshold), AV_OPT_TYPE_DURATION, {.i64 = 0}, 0, INT64_MAX, FLAGS },
>      { "dec_threads",  "set the number of threads for decoding", OFFSET(dec_threads), AV_OPT_TYPE_INT, {.i64 =  0}, 0, INT_MAX, FLAGS },
> +    { "format_opts",  "set format options for the opened file", OFFSET(format_opts), AV_OPT_TYPE_DICT, {.str = NULL}, 0, 0, FLAGS},
>      { NULL },
>  };
>  
> @@ -214,6 +216,7 @@ static av_cold int movie_common_init(AVFilterContext *ctx)
>      int nb_streams = 1, ret, i;
>      char default_streams[16], *stream_specs, *spec, *cursor;
>      AVStream *st;
> +    AVDictionary *options = NULL;
>  
>      if (!movie->file_name) {
>          av_log(ctx, AV_LOG_ERROR, "No filename provided!\n");
> @@ -243,11 +246,14 @@ static av_cold int movie_common_init(AVFilterContext *ctx)
>      iformat = movie->format_name ? av_find_input_format(movie->format_name) : NULL;
>  
>      movie->format_ctx = NULL;
> -    if ((ret = avformat_open_input(&movie->format_ctx, movie->file_name, iformat, NULL)) < 0) {
> +    av_dict_copy(&options, movie->format_opts, 0);

Why are you copying the options instead of just using them?

> +    if ((ret = avformat_open_input(&movie->format_ctx, movie->file_name, iformat, &options)) < 0) {
>          av_log(ctx, AV_LOG_ERROR,
>                 "Failed to avformat_open_input '%s'\n", movie->file_name);

Your copy of options leaks here; it would not leak if there were no copy.

>          return ret;
>      }
> +    av_dict_free(&options);
> +
>      if ((ret = avformat_find_stream_info(movie->format_ctx, NULL)) < 0)
>          av_log(ctx, AV_LOG_WARNING, "Failed to find stream info\n");
>  
>
Limin Wang Nov. 26, 2021, 9:27 a.m. UTC | #2
On Fri, Nov 26, 2021 at 07:36:33AM +0100, Andreas Rheinhardt wrote:
> lance.lmwang@gmail.com:
> > From: Limin Wang <lance.lmwang@gmail.com>
> > 
> > Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
> > ---
> >  doc/filters.texi        | 5 +++++
> >  libavfilter/src_movie.c | 8 +++++++-
> >  2 files changed, 12 insertions(+), 1 deletion(-)
> > 
> > diff --git a/doc/filters.texi b/doc/filters.texi
> > index c3ccaf9..6c35788 100644
> > --- a/doc/filters.texi
> > +++ b/doc/filters.texi
> > @@ -28386,6 +28386,11 @@ timestamps.
> >  
> >  @item dec_threads
> >  Specifies the number of threads for decoding
> > +
> > +@item format_opts
> > +Specify format options for the opened file. Format options can be specified
> > +as a list of @var{key}=@var{value} pairs separated by ':'. For example,
> > +some protocol you need to add protocol_whitelist for the opened file.
> >  @end table
> >  
> >  It allows overlaying a second video on top of the main input of
> > diff --git a/libavfilter/src_movie.c b/libavfilter/src_movie.c
> > index 220a43c..5e52015 100644
> > --- a/libavfilter/src_movie.c
> > +++ b/libavfilter/src_movie.c
> > @@ -74,6 +74,7 @@ typedef struct MovieContext {
> >      int max_stream_index; /**< max stream # actually used for output */
> >      MovieStream *st; /**< array of all streams, one per output */
> >      int *out_index; /**< stream number -> output number map, or -1 */
> > +    AVDictionary *format_opts;
> >  } MovieContext;
> >  
> >  #define OFFSET(x) offsetof(MovieContext, x)
> > @@ -92,6 +93,7 @@ static const AVOption movie_options[]= {
> >      { "loop",         "set loop count",          OFFSET(loop_count),   AV_OPT_TYPE_INT,    {.i64 =  1},  0,        INT_MAX, FLAGS },
> >      { "discontinuity", "set discontinuity threshold", OFFSET(discontinuity_threshold), AV_OPT_TYPE_DURATION, {.i64 = 0}, 0, INT64_MAX, FLAGS },
> >      { "dec_threads",  "set the number of threads for decoding", OFFSET(dec_threads), AV_OPT_TYPE_INT, {.i64 =  0}, 0, INT_MAX, FLAGS },
> > +    { "format_opts",  "set format options for the opened file", OFFSET(format_opts), AV_OPT_TYPE_DICT, {.str = NULL}, 0, 0, FLAGS},
> >      { NULL },
> >  };
> >  
> > @@ -214,6 +216,7 @@ static av_cold int movie_common_init(AVFilterContext *ctx)
> >      int nb_streams = 1, ret, i;
> >      char default_streams[16], *stream_specs, *spec, *cursor;
> >      AVStream *st;
> > +    AVDictionary *options = NULL;
> >  
> >      if (!movie->file_name) {
> >          av_log(ctx, AV_LOG_ERROR, "No filename provided!\n");
> > @@ -243,11 +246,14 @@ static av_cold int movie_common_init(AVFilterContext *ctx)
> >      iformat = movie->format_name ? av_find_input_format(movie->format_name) : NULL;
> >  
> >      movie->format_ctx = NULL;
> > -    if ((ret = avformat_open_input(&movie->format_ctx, movie->file_name, iformat, NULL)) < 0) {
> > +    av_dict_copy(&options, movie->format_opts, 0);
> 
> Why are you copying the options instead of just using them?

yes, it's better to use it directly, maybe I'm afraid of format_opts may be changed by avformat_open_input when
add it. Will update the patch.

> 
> > +    if ((ret = avformat_open_input(&movie->format_ctx, movie->file_name, iformat, &options)) < 0) {
> >          av_log(ctx, AV_LOG_ERROR,
> >                 "Failed to avformat_open_input '%s'\n", movie->file_name);
> 
> Your copy of options leaks here; it would not leak if there were no copy.
> 
> >          return ret;
> >      }
> > +    av_dict_free(&options);
> > +
> >      if ((ret = avformat_find_stream_info(movie->format_ctx, NULL)) < 0)
> >          av_log(ctx, AV_LOG_WARNING, "Failed to find stream info\n");
> >  
> > 
> 
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
diff mbox series

Patch

diff --git a/doc/filters.texi b/doc/filters.texi
index c3ccaf9..6c35788 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -28386,6 +28386,11 @@  timestamps.
 
 @item dec_threads
 Specifies the number of threads for decoding
+
+@item format_opts
+Specify format options for the opened file. Format options can be specified
+as a list of @var{key}=@var{value} pairs separated by ':'. For example,
+some protocol you need to add protocol_whitelist for the opened file.
 @end table
 
 It allows overlaying a second video on top of the main input of
diff --git a/libavfilter/src_movie.c b/libavfilter/src_movie.c
index 220a43c..5e52015 100644
--- a/libavfilter/src_movie.c
+++ b/libavfilter/src_movie.c
@@ -74,6 +74,7 @@  typedef struct MovieContext {
     int max_stream_index; /**< max stream # actually used for output */
     MovieStream *st; /**< array of all streams, one per output */
     int *out_index; /**< stream number -> output number map, or -1 */
+    AVDictionary *format_opts;
 } MovieContext;
 
 #define OFFSET(x) offsetof(MovieContext, x)
@@ -92,6 +93,7 @@  static const AVOption movie_options[]= {
     { "loop",         "set loop count",          OFFSET(loop_count),   AV_OPT_TYPE_INT,    {.i64 =  1},  0,        INT_MAX, FLAGS },
     { "discontinuity", "set discontinuity threshold", OFFSET(discontinuity_threshold), AV_OPT_TYPE_DURATION, {.i64 = 0}, 0, INT64_MAX, FLAGS },
     { "dec_threads",  "set the number of threads for decoding", OFFSET(dec_threads), AV_OPT_TYPE_INT, {.i64 =  0}, 0, INT_MAX, FLAGS },
+    { "format_opts",  "set format options for the opened file", OFFSET(format_opts), AV_OPT_TYPE_DICT, {.str = NULL}, 0, 0, FLAGS},
     { NULL },
 };
 
@@ -214,6 +216,7 @@  static av_cold int movie_common_init(AVFilterContext *ctx)
     int nb_streams = 1, ret, i;
     char default_streams[16], *stream_specs, *spec, *cursor;
     AVStream *st;
+    AVDictionary *options = NULL;
 
     if (!movie->file_name) {
         av_log(ctx, AV_LOG_ERROR, "No filename provided!\n");
@@ -243,11 +246,14 @@  static av_cold int movie_common_init(AVFilterContext *ctx)
     iformat = movie->format_name ? av_find_input_format(movie->format_name) : NULL;
 
     movie->format_ctx = NULL;
-    if ((ret = avformat_open_input(&movie->format_ctx, movie->file_name, iformat, NULL)) < 0) {
+    av_dict_copy(&options, movie->format_opts, 0);
+    if ((ret = avformat_open_input(&movie->format_ctx, movie->file_name, iformat, &options)) < 0) {
         av_log(ctx, AV_LOG_ERROR,
                "Failed to avformat_open_input '%s'\n", movie->file_name);
         return ret;
     }
+    av_dict_free(&options);
+
     if ((ret = avformat_find_stream_info(movie->format_ctx, NULL)) < 0)
         av_log(ctx, AV_LOG_WARNING, "Failed to find stream info\n");