Re: [FFmpeg-devel] [PATCH 2/2] lavf/concatdef: pass options to nested input

2015-03-05 Thread Zhang Rui
2015-03-05 20:34 GMT+08:00 Nicolas George geo...@nsup.org:
 Le quintidi 15 ventôse, an CCXXIII, Zhang Rui a écrit :

 Your solution is enough for my case.
 And as you said, my patch may be not desirable.

 I believe it depends on the use case, and it is not completely obvious which
 side your example falls on.

In my situation, all segments are deployed on same http server,
and need same options. So both sides are OK for me.

In my own project, I would use read_header2 to specify options
for all segments which is convenient, and use per-file option for
special situations.

I'm also trying to introduce read_header2 into libavformat/hls.c,
which has been setting internal input options manually, incompletely
and dependently.
Obviously, we have no chance, and may have no need to set per-file
ffmpeg option in hls.

But I'm not sure read_headers2 is OK as an ffmpeg API,
Besides your concern about same options for all segments,
There is also a concern about same options for upper and lower inputs.

Would you mind to share more ideas about read_headers2 callback?

 But in the meantime I have started implementing per-file options for the
 concat demuxer, see the attached patch.

Looks great to me.
Do you have more WIP / plans / ideas on concatdec to share?
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 2/2] lavf/concatdef: pass options to nested input

2015-03-05 Thread Nicolas George
Le quintidi 15 ventôse, an CCXXIII, Zhang Rui a écrit :
 Subject: [FFmpeg-devel] [PATCH 2/2] lavf/concatdef: pass options to

concatdec I suppose?

 ---
  libavformat/concatdec.c | 24 +---
  1 file changed, 17 insertions(+), 7 deletions(-)

Can you explain the use case you have in mind? The current code, if I
understand correctly, uses the same options for all concatenated segments,
which may or may not desirable.

My intent, regarding options, was to allow per-file options in the concat
script. Maybe something like that:

  file seg1.vob
  option analyzeduration 50M

  file seg2.vob
  option analyzeduration 20M

  ...

Regards,

-- 
  Nicolas George


signature.asc
Description: Digital signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 2/2] lavf/concatdef: pass options to nested input

2015-03-05 Thread Nicolas George
Le quintidi 15 ventôse, an CCXXIII, Zhang Rui a écrit :
 I'm using concatdec for streaming http segments.
 which need options like timeout, user_agent.

Ok.

 Your solution is enough for my case.
 And as you said, my patch may be not desirable.

I believe it depends on the use case, and it is not completely obvious which
side your example falls on.

But in the meantime I have started implementing per-file options for the
concat demuxer, see the attached patch.

Regards,

-- 
  Nicolas George
From fbbc4d5a4f99a0c58af63477a4daf056ceeea479 Mon Sep 17 00:00:00 2001
From: Nicolas George geo...@nsup.org
Date: Thu, 5 Mar 2015 13:31:35 +0100
Subject: [PATCH] lavf/concatdec: add per-file options. [WIP]

Signed-off-by: Nicolas George geo...@nsup.org
---
 libavformat/concatdec.c | 23 ++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/libavformat/concatdec.c b/libavformat/concatdec.c
index f07cfd7..d0a7f1e 100644
--- a/libavformat/concatdec.c
+++ b/libavformat/concatdec.c
@@ -44,6 +44,7 @@ typedef struct {
 int64_t duration;
 ConcatStream *streams;
 int nb_streams;
+AVDictionary *options;
 } ConcatFile;
 
 typedef struct {
@@ -279,6 +280,7 @@ static int open_file(AVFormatContext *avf, unsigned fileno)
 {
 ConcatContext *cat = avf-priv_data;
 ConcatFile *file = cat-files[fileno];
+AVDictionary *options = NULL;
 int ret;
 
 if (cat-avf)
@@ -290,15 +292,17 @@ static int open_file(AVFormatContext *avf, unsigned fileno)
 
 cat-avf-interrupt_callback = avf-interrupt_callback;
 
+av_dict_copy(options, file-options, 0);
 if ((ret = ff_copy_whitelists(cat-avf, avf))  0)
 return ret;
 
-if ((ret = avformat_open_input(cat-avf, file-url, NULL, NULL))  0 ||
+if ((ret = avformat_open_input(cat-avf, file-url, NULL, options))  0 ||
 (ret = avformat_find_stream_info(cat-avf, NULL))  0) {
 av_log(avf, AV_LOG_ERROR, Impossible to open '%s'\n, file-url);
 avformat_close_input(cat-avf);
 return ret;
 }
+/* TODO report unused options */
 cat-cur_file = file;
 if (file-start_time == AV_NOPTS_VALUE)
 file-start_time = !fileno ? 0 :
@@ -332,6 +336,7 @@ static int concat_read_header(AVFormatContext *avf)
 int ret, line = 0, i;
 unsigned nb_files_alloc = 0;
 ConcatFile *file = NULL;
+AVDictionary *common_options = NULL, **options = common_options;
 int64_t time = 0;
 
 while (1) {
@@ -351,6 +356,8 @@ static int concat_read_header(AVFormatContext *avf)
 }
 if ((ret = add_file(avf, filename, file, nb_files_alloc))  0)
 goto fail;
+av_dict_copy(file-options, common_options, 0);
+options = file-options;
 } else if (!strcmp(keyword, duration)) {
 char *dur_str = get_keyword(cursor);
 int64_t dur;
@@ -376,6 +383,18 @@ static int concat_read_header(AVFormatContext *avf)
 }
 avf-streams[avf-nb_streams - 1]-id =
 strtol(get_keyword(cursor), NULL, 0);
+} else if (!strcmp(keyword, option)) {
+char *key = get_keyword(cursor);
+char *val = av_get_token((const char **)cursor, SPACE_CHARS);
+if (!val) {
+av_log(avf, AV_LOG_ERROR, Line %d: option value required\n, line);
+FAIL(AVERROR_INVALIDDATA);
+}
+ret = av_dict_set(options, key, val, AV_DICT_DONT_STRDUP_VAL);
+if (ret  0) {
+av_free(val);
+goto fail;
+}
 } else if (!strcmp(keyword, ffconcat)) {
 char *ver_kw  = get_keyword(cursor);
 char *ver_val = get_keyword(cursor);
@@ -395,6 +414,7 @@ static int concat_read_header(AVFormatContext *avf)
 goto fail;
 if (!cat-nb_files)
 FAIL(AVERROR_INVALIDDATA);
+av_dict_free(common_options);
 
 for (i = 0; i  cat-nb_files; i++) {
 if (cat-files[i].start_time == AV_NOPTS_VALUE)
@@ -417,6 +437,7 @@ static int concat_read_header(AVFormatContext *avf)
 return 0;
 
 fail:
+av_dict_free(common_options);
 concat_read_close(avf);
 return ret;
 }
-- 
2.1.4



signature.asc
Description: Digital signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH 2/2] lavf/concatdef: pass options to nested input

2015-03-05 Thread Zhang Rui
---
 libavformat/concatdec.c | 24 +---
 1 file changed, 17 insertions(+), 7 deletions(-)

diff --git a/libavformat/concatdec.c b/libavformat/concatdec.c
index f07cfd7..a6bf6ee 100644
--- a/libavformat/concatdec.c
+++ b/libavformat/concatdec.c
@@ -56,6 +56,7 @@ typedef struct {
 int seekable;
 ConcatMatchMode stream_match_mode;
 unsigned auto_convert;
+AVDictionary *options;
 } ConcatContext;
 
 static int concat_probe(AVProbeData *probe)
@@ -280,6 +281,7 @@ static int open_file(AVFormatContext *avf, unsigned fileno)
 ConcatContext *cat = avf-priv_data;
 ConcatFile *file = cat-files[fileno];
 int ret;
+AVDictionary *tmp = NULL;
 
 if (cat-avf)
 avformat_close_input(cat-avf);
@@ -293,11 +295,14 @@ static int open_file(AVFormatContext *avf, unsigned 
fileno)
 if ((ret = ff_copy_whitelists(cat-avf, avf))  0)
 return ret;
 
-if ((ret = avformat_open_input(cat-avf, file-url, NULL, NULL))  0 ||
-(ret = avformat_find_stream_info(cat-avf, NULL))  0) {
+if (cat-options)
+av_dict_copy(tmp, cat-options, 0);
+
+if ((ret = avformat_open_input(cat-avf, file-url, NULL, tmp))  0 ||
+(ret = avformat_find_stream_info(cat-avf, tmp))  0) {
 av_log(avf, AV_LOG_ERROR, Impossible to open '%s'\n, file-url);
 avformat_close_input(cat-avf);
-return ret;
+goto fail;
 }
 cat-cur_file = file;
 if (file-start_time == AV_NOPTS_VALUE)
@@ -305,8 +310,10 @@ static int open_file(AVFormatContext *avf, unsigned fileno)
cat-files[fileno - 1].start_time +
cat-files[fileno - 1].duration;
 if ((ret = match_streams(avf))  0)
-return ret;
-return 0;
+goto fail;
+fail:
+av_dict_free(tmp);
+return ret;
 }
 
 static int concat_read_close(AVFormatContext *avf)
@@ -320,11 +327,12 @@ static int concat_read_close(AVFormatContext *avf)
 av_freep(cat-files[i].url);
 av_freep(cat-files[i].streams);
 }
+av_dict_free(cat-options);
 av_freep(cat-files);
 return 0;
 }
 
-static int concat_read_header(AVFormatContext *avf)
+static int concat_read_header(AVFormatContext *avf, AVDictionary **options)
 {
 ConcatContext *cat = avf-priv_data;
 uint8_t buf[4096];
@@ -412,6 +420,8 @@ static int concat_read_header(AVFormatContext *avf)
 
 cat-stream_match_mode = avf-nb_streams ? MATCH_EXACT_ID :
MATCH_ONE_TO_ONE;
+if (options)
+av_dict_copy(cat-options, *options, 0);
 if ((ret = open_file(avf, 0))  0)
 goto fail;
 return 0;
@@ -644,7 +654,7 @@ AVInputFormat ff_concat_demuxer = {
 .long_name  = NULL_IF_CONFIG_SMALL(Virtual concatenation script),
 .priv_data_size = sizeof(ConcatContext),
 .read_probe = concat_probe,
-.read_header= concat_read_header,
+.read_header2   = concat_read_header,
 .read_packet= concat_read_packet,
 .read_close = concat_read_close,
 .read_seek2 = concat_seek,
-- 
2.0.0

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 2/2] lavf/concatdef: pass options to nested input

2015-03-05 Thread Zhang Rui
2015-03-05 19:06 GMT+08:00 Nicolas George geo...@nsup.org:
 Le quintidi 15 ventôse, an CCXXIII, Zhang Rui a écrit :
 Subject: [FFmpeg-devel] [PATCH 2/2] lavf/concatdef: pass options to

 concatdec I suppose?

Sorry, my fault.


 ---
  libavformat/concatdec.c | 24 +---
  1 file changed, 17 insertions(+), 7 deletions(-)

 Can you explain the use case you have in mind? The current code, if I
 understand correctly, uses the same options for all concatenated segments,
 which may or may not desirable.

I'm using concatdec for streaming http segments.
which need options like timeout, user_agent.


 My intent, regarding options, was to allow per-file options in the concat
 script. Maybe something like that:

   file seg1.vob
   option analyzeduration 50M

   file seg2.vob
   option analyzeduration 20M

Your solution is enough for my case.
And as you said, my patch may be not desirable.

Thank you.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel