diff mbox

[FFmpeg-devel,1/1] avformat/dashenc: Added configuration to override HTTP User-Agent

Message ID 1510132974-16590-1-git-send-email-kjeyapal@akamai.com
State Accepted
Commit d24e08e978792e09d212018677d1c0b8208ecef8
Headers show

Commit Message

Jeyapal, Karthick Nov. 8, 2017, 9:22 a.m. UTC
---
 doc/muxers.texi       |  2 ++
 libavformat/dashenc.c | 22 +++++++++++++++++++---
 2 files changed, 21 insertions(+), 3 deletions(-)

Comments

Steven Liu Nov. 20, 2017, 7:30 a.m. UTC | #1
> 在 2017年11月8日,17:22,Karthick J <kjeyapal@akamai.com> 写道:
> 
> ---
> doc/muxers.texi       |  2 ++
> libavformat/dashenc.c | 22 +++++++++++++++++++---
> 2 files changed, 21 insertions(+), 3 deletions(-)
> 
> diff --git a/doc/muxers.texi b/doc/muxers.texi
> index 91bbe67..412fede 100644
> --- a/doc/muxers.texi
> +++ b/doc/muxers.texi
> @@ -247,6 +247,8 @@ DASH-templated name to used for the initialization segment. Default is "init-str
> DASH-templated name to used for the media segments. Default is "chunk-stream$RepresentationID$-$Number%05d$.m4s"
> @item -utc_timing_url @var{utc_url}
> URL of the page that will return the UTC timestamp in ISO format. Example: "https://time.akamai.com/?iso"
> +@item -http_user_agent @var{user_agent}
> +Override User-Agent field in HTTP header. Applicable only for HTTP output.
> @item -adaptation_sets @var{adaptation_sets}
> Assign streams to AdaptationSets. Syntax is "id=x,streams=a,b,c id=y,streams=d,e" with x and y being the IDs
> of the adaptation sets and a,b,c,d and e are the indices of the mapped streams.
> diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c
> index 7813f44..a68f7fb 100644
> --- a/libavformat/dashenc.c
> +++ b/libavformat/dashenc.c
> @@ -100,6 +100,7 @@ typedef struct DASHContext {
>     const char *init_seg_name;
>     const char *media_seg_name;
>     const char *utc_timing_url;
> +    const char *user_agent;
> } DASHContext;
> 
> static struct codec_string {
> @@ -210,6 +211,12 @@ static int flush_dynbuf(OutputStream *os, int *range_length)
>     return avio_open_dyn_buf(&os->ctx->pb);
> }
> 
> +static void set_http_options(AVDictionary **options, DASHContext *c)
> +{
> +    if (c->user_agent)
> +        av_dict_set(options, "user_agent", c->user_agent, 0);
> +}
> +
> static int flush_init_segment(AVFormatContext *s, OutputStream *os)
> {
>     DASHContext *c = s->priv_data;
> @@ -575,16 +582,19 @@ static int write_manifest(AVFormatContext *s, int final)
>     int use_rename = proto && !strcmp(proto, "file");
>     static unsigned int warned_non_file = 0;
>     AVDictionaryEntry *title = av_dict_get(s->metadata, "title", NULL, 0);
> +    AVDictionary *opts = NULL;
> 
>     if (!use_rename && !warned_non_file++)
>         av_log(s, AV_LOG_ERROR, "Cannot use rename on non file protocol, this may lead to races and temporary partial files\n");
> 
>     snprintf(temp_filename, sizeof(temp_filename), use_rename ? "%s.tmp" : "%s", s->filename);
> -    ret = s->io_open(s, &out, temp_filename, AVIO_FLAG_WRITE, NULL);
> +    set_http_options(&opts, c);
> +    ret = s->io_open(s, &out, temp_filename, AVIO_FLAG_WRITE, &opts);
>     if (ret < 0) {
>         av_log(s, AV_LOG_ERROR, "Unable to open %s for writing\n", temp_filename);
>         return ret;
>     }
> +    av_dict_free(&opts);
>     avio_printf(out, "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
>     avio_printf(out, "<MPD xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"
>                 "\txmlns=\"urn:mpeg:dash:schema:mpd:2011\"\n"
> @@ -768,9 +778,11 @@ static int dash_init(AVFormatContext *s)
>             ff_dash_fill_tmpl_params(os->initfile, sizeof(os->initfile), c->init_seg_name, i, 0, os->bit_rate, 0);
>         }
>         snprintf(filename, sizeof(filename), "%s%s", c->dirname, os->initfile);
> -        ret = s->io_open(s, &os->out, filename, AVIO_FLAG_WRITE, NULL);
> +        set_http_options(&opts, c);
> +        ret = s->io_open(s, &os->out, filename, AVIO_FLAG_WRITE, &opts);
>         if (ret < 0)
>             return ret;
> +        av_dict_free(&opts);
>         os->init_start_pos = 0;
> 
>         if (!strcmp(os->format_name, "mp4")) {
> @@ -974,12 +986,15 @@ static int dash_flush(AVFormatContext *s, int final, int stream)
>         }
> 
>         if (!c->single_file) {
> +            AVDictionary *opts = NULL;
>             ff_dash_fill_tmpl_params(filename, sizeof(filename), c->media_seg_name, i, os->segment_index, os->bit_rate, os->start_pts);
>             snprintf(full_path, sizeof(full_path), "%s%s", c->dirname, filename);
>             snprintf(temp_path, sizeof(temp_path), use_rename ? "%s.tmp" : "%s", full_path);
> -            ret = s->io_open(s, &os->out, temp_path, AVIO_FLAG_WRITE, NULL);
> +            set_http_options(&opts, c);
> +            ret = s->io_open(s, &os->out, temp_path, AVIO_FLAG_WRITE, &opts);
>             if (ret < 0)
>                 break;
> +            av_dict_free(&opts);
>             if (!strcmp(os->format_name, "mp4"))
>                 write_styp(os->ctx->pb);
>         } else {
> @@ -1188,6 +1203,7 @@ static const AVOption options[] = {
>     { "init_seg_name", "DASH-templated name to used for the initialization segment", OFFSET(init_seg_name), AV_OPT_TYPE_STRING, {.str = "init-stream$RepresentationID$.m4s"}, 0, 0, E },
>     { "media_seg_name", "DASH-templated name to used for the media segments", OFFSET(media_seg_name), AV_OPT_TYPE_STRING, {.str = "chunk-stream$RepresentationID$-$Number%05d$.m4s"}, 0, 0, E },
>     { "utc_timing_url", "URL of the page that will return the UTC timestamp in ISO format", OFFSET(utc_timing_url), AV_OPT_TYPE_STRING, { 0 }, 0, 0, E },
> +    { "http_user_agent", "override User-Agent field in HTTP header", OFFSET(user_agent), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, E},
What about dash_user_agent? The reason is http_user_agent maybe get mean HTTP Protocol user_agent, but this is used in dashenc.
> .    { NULL },
> };
> 
> -- 
> 1.9.1
> 
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Jeyapal, Karthick Nov. 20, 2017, 7:59 a.m. UTC | #2
>On 11/20/17, 1:01 PM, "刘歧" <lq@chinaffmpeg.org> wrote:

>> 在 2017年11月8日,17:22,Karthick J <kjeyapal@akamai.com> 写道:

>> +    { "http_user_agent", "override User-Agent field in HTTP header", OFFSET(user_agent), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, E},

>What about dash_user_agent? The reason is http_user_agent maybe get mean HTTP Protocol user_agent, but this is used in dashenc.


I kept http_user_agent to maintain uniformity with hlsenc option. 
http://ffmpeg.org/pipermail/ffmpeg-devel/2017-September/215642.html

In that way, irrespective of hls or dash output format, http_user_agent would apply for both.

Regards,
Karthick
Steven Liu Nov. 20, 2017, 8:17 a.m. UTC | #3
> 在 2017年11月20日,15:59,Jeyapal, Karthick <kjeyapal@akamai.com> 写道:
> 
>> On 11/20/17, 1:01 PM, "刘歧" <lq@chinaffmpeg.org> wrote:
>>> 在 2017年11月8日,17:22,Karthick J <kjeyapal@akamai.com> 写道:
>>> +    { "http_user_agent", "override User-Agent field in HTTP header", OFFSET(user_agent), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, E},
>> What about dash_user_agent? The reason is http_user_agent maybe get mean HTTP Protocol user_agent, but this is used in dashenc.
> 
> I kept http_user_agent to maintain uniformity with hlsenc option. 
> http://ffmpeg.org/pipermail/ffmpeg-devel/2017-September/215642.html
> 
> In that way, irrespective of hls or dash output format, http_user_agent would apply for both.
that should modify to hls_user_agent too. because that is clarified the option is used in dash or hls, isn’t it?
 
> 
> Regards,
> Karthick
> 
> 
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Jeyapal, Karthick Nov. 20, 2017, 11:31 a.m. UTC | #4
>On 11/20/17, 1:47 PM, "刘歧" <lq@chinaffmpeg.org> wrote:



>> 在 2017年11月20日,15:59,Jeyapal, Karthick <kjeyapal@akamai.com> 写道:

>> 

>>> On 11/20/17, 1:01 PM, "刘歧" <lq@chinaffmpeg.org> wrote:

>>>> 在 2017年11月8日,17:22,Karthick J <kjeyapal@akamai.com> 写道:

>>>> +    { "http_user_agent", "override User-Agent field in HTTP header", OFFSET(user_agent), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, E},

>>> What about dash_user_agent? The reason is http_user_agent maybe get mean HTTP Protocol user_agent, but this is used in dashenc.

>> 

>> I kept http_user_agent to maintain uniformity with hlsenc option. 

>> http://ffmpeg.org/pipermail/ffmpeg-devel/2017-September/215642.html

>> 

>> In that way, irrespective of hls or dash output format, http_user_agent would apply for both.

>that should modify to hls_user_agent too. because that is clarified the option is used in dash or hls, isn’t it?


Sure. I am ok with dash_user_agent as well. 
I have attached a new patch with the option renamed to dash_user_agent.

Thanks and regards,
Karthick
Steven Liu Nov. 20, 2017, 11:49 a.m. UTC | #5
> 在 2017年11月20日,19:31,Jeyapal, Karthick <kjeyapal@akamai.com> 写道:
> 
>> On 11/20/17, 1:47 PM, "刘歧" <lq@chinaffmpeg.org> wrote:
> 
> 
>>> 在 2017年11月20日,15:59,Jeyapal, Karthick <kjeyapal@akamai.com> 写道:
>>> 
>>>> On 11/20/17, 1:01 PM, "刘歧" <lq@chinaffmpeg.org> wrote:
>>>>> 在 2017年11月8日,17:22,Karthick J <kjeyapal@akamai.com> 写道:
>>>>> +    { "http_user_agent", "override User-Agent field in HTTP header", OFFSET(user_agent), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, E},
>>>> What about dash_user_agent? The reason is http_user_agent maybe get mean HTTP Protocol user_agent, but this is used in dashenc.
>>> 
>>> I kept http_user_agent to maintain uniformity with hlsenc option. 
>>> http://ffmpeg.org/pipermail/ffmpeg-devel/2017-September/215642.html
>>> 
>>> In that way, irrespective of hls or dash output format, http_user_agent would apply for both.
>> that should modify to hls_user_agent too. because that is clarified the option is used in dash or hls, isn’t it?
> 
> Sure. I am ok with dash_user_agent as well. 
> I have attached a new patch with the option renamed to dash_user_agent.
> 
> Thanks and regards,
> Karthick
> 
> 
> 
> 
> <0001-avformat-dashenc-Added-configuration-to-override-HTT.patch>_______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

should be ok
Carl Eugen Hoyos Nov. 20, 2017, 1:03 p.m. UTC | #6
2017-11-20 9:17 GMT+01:00 刘歧 <lq@chinaffmpeg.org>:
>
>> 在 2017年11月20日,15:59,Jeyapal, Karthick <kjeyapal@akamai.com> 写道:
>>
>>> On 11/20/17, 1:01 PM, "刘歧" <lq@chinaffmpeg.org> wrote:
>>>> 在 2017年11月8日,17:22,Karthick J <kjeyapal@akamai.com> 写道:
>>>> +    { "http_user_agent", "override User-Agent field in HTTP header",
>>>>  OFFSET(user_agent), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, E},
>>> What about dash_user_agent? The reason is http_user_agent maybe get
>>> mean HTTP Protocol user_agent, but this is used in dashenc.
>>
>> I kept http_user_agent to maintain uniformity with hlsenc option.
>> http://ffmpeg.org/pipermail/ffmpeg-devel/2017-September/215642.html
>>
>> In that way, irrespective of hls or dash output format, http_user_agent
>> would apply for both.
>
> that should modify to hls_user_agent too. because that is clarified the option
> is used in dash or hls, isn’t it?

I consider it a huge advantage for users if options in different modules use
the same option name if they do the same thing.

Is it possible to create confusion if the options share the same name?

Carl Eugen
Steven Liu Nov. 20, 2017, 2 p.m. UTC | #7
> 在 2017年11月20日,下午9:03,Carl Eugen Hoyos <ceffmpeg@gmail.com> 写道:
> 
> 2017-11-20 9:17 GMT+01:00 刘歧 <lq@chinaffmpeg.org>:
>> 
>>>>> 在 2017年11月20日,15:59,Jeyapal, Karthick <kjeyapal@akamai.com> 写道:
>>>> 
>>>>> On 11/20/17, 1:01 PM, "刘歧" <lq@chinaffmpeg.org> wrote:
>>>>> 在 2017年11月8日,17:22,Karthick J <kjeyapal@akamai.com> 写道:
>>>>> +    { "http_user_agent", "override User-Agent field in HTTP header",
>>>>> OFFSET(user_agent), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, E},
>>>> What about dash_user_agent? The reason is http_user_agent maybe get
>>>> mean HTTP Protocol user_agent, but this is used in dashenc.
>>> 
>>> I kept http_user_agent to maintain uniformity with hlsenc option.
>>> http://ffmpeg.org/pipermail/ffmpeg-devel/2017-September/215642.html
>>> 
>>> In that way, irrespective of hls or dash output format, http_user_agent
>>> would apply for both.
>> 
>> that should modify to hls_user_agent too. because that is clarified the option
>> is used in dash or hls, isn’t it?
> 
> I consider it a huge advantage for users if options in different modules use
> the same option name if they do the same thing.
> 
> Is it possible to create confusion if the options share the same name?
for example: -timeout use rtmp or http i cannot understand the timeout is used in tcp or rtmp or http, which protocol will use it? Because there have same option name in tcp and rtmp, I think clear module private option is better.

> 
> Carl Eugen
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://f
Carl Eugen Hoyos Nov. 20, 2017, 2:03 p.m. UTC | #8
2017-11-20 15:00 GMT+01:00 Steven Liu <lq@chinaffmpeg.org>:
>
>
>> 在 2017年11月20日,下午9:03,Carl Eugen Hoyos <ceffmpeg@gmail.com> 写道:
>>
>> 2017-11-20 9:17 GMT+01:00 刘歧 <lq@chinaffmpeg.org>:
>>>
>>>>>> 在 2017年11月20日,15:59,Jeyapal, Karthick <kjeyapal@akamai.com> 写道:
>>>>>
>>>>>> On 11/20/17, 1:01 PM, "刘歧" <lq@chinaffmpeg.org> wrote:
>>>>>> 在 2017年11月8日,17:22,Karthick J <kjeyapal@akamai.com> 写道:
>>>>>> +    { "http_user_agent", "override User-Agent field in HTTP header",
>>>>>> OFFSET(user_agent), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, E},
>>>>> What about dash_user_agent? The reason is http_user_agent maybe get
>>>>> mean HTTP Protocol user_agent, but this is used in dashenc.
>>>>
>>>> I kept http_user_agent to maintain uniformity with hlsenc option.
>>>> http://ffmpeg.org/pipermail/ffmpeg-devel/2017-September/215642.html
>>>>
>>>> In that way, irrespective of hls or dash output format, http_user_agent
>>>> would apply for both.
>>>
>>> that should modify to hls_user_agent too. because that is clarified the option
>>> is used in dash or hls, isn’t it?
>>
>> I consider it a huge advantage for users if options in different modules use
>> the same option name if they do the same thing.
>>
>> Is it possible to create confusion if the options share the same name?

Sorry for the bad wording:
Is it possible for "http_user_agent" to create confusion because options
with this name are used in different demuxers?

Carl Eugen
Steven Liu Nov. 20, 2017, 2:11 p.m. UTC | #9
> 在 2017年11月20日,下午10:03,Carl Eugen Hoyos <ceffmpeg@gmail.com> 写道:
> 
> 2017-11-20 15:00 GMT+01:00 Steven Liu <lq@chinaffmpeg.org>:
>> 
>> 
>>> 在 2017年11月20日,下午9:03,Carl Eugen Hoyos <ceffmpeg@gmail.com> 写道:
>>> 
>>> 2017-11-20 9:17 GMT+01:00 刘歧 <lq@chinaffmpeg.org>:
>>>> 
>>>>>>>> 在 2017年11月20日,15:59,Jeyapal, Karthick <kjeyapal@akamai.com> 写道:
>>>>>>> 
>>>>>>> On 11/20/17, 1:01 PM, "刘歧" <lq@chinaffmpeg.org> wrote:
>>>>>>> 在 2017年11月8日,17:22,Karthick J <kjeyapal@akamai.com> 写道:
>>>>>>> +    { "http_user_agent", "override User-Agent field in HTTP header",
>>>>>>> OFFSET(user_agent), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, E},
>>>>>> What about dash_user_agent? The reason is http_user_agent maybe get
>>>>>> mean HTTP Protocol user_agent, but this is used in dashenc.
>>>>> 
>>>>> I kept http_user_agent to maintain uniformity with hlsenc option.
>>>>> http://ffmpeg.org/pipermail/ffmpeg-devel/2017-September/215642.html
>>>>> 
>>>>> In that way, irrespective of hls or dash output format, http_user_agent
>>>>> would apply for both.
>>>> 
>>>> that should modify to hls_user_agent too. because that is clarified the option
>>>> is used in dash or hls, isn’t it?
>>> 
>>> I consider it a huge advantage for users if options in different modules use
>>> the same option name if they do the same thing.
>>> 
>>> Is it possible to create confusion if the options share the same name?
> 
> Sorry for the bad wording:
> Is it possible for "http_user_agent" to create confusion because options
> with this name are used in different demuxers?
It’s used for dash, isn’t it clear than http_user_agent? If not use -f dash, just only use http_user_agent, what will happen, I think that will get confusion, because hls have the same name, looks like timeout option.
> 
> Carl Eugen
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Hendrik Leppkes Nov. 20, 2017, 3:12 p.m. UTC | #10
On Mon, Nov 20, 2017 at 3:11 PM, Steven Liu <lq@chinaffmpeg.org> wrote:
>
>
>> 在 2017年11月20日,下午10:03,Carl Eugen Hoyos <ceffmpeg@gmail.com> 写道:
>>
>> 2017-11-20 15:00 GMT+01:00 Steven Liu <lq@chinaffmpeg.org>:
>>>
>>>
>>>> 在 2017年11月20日,下午9:03,Carl Eugen Hoyos <ceffmpeg@gmail.com> 写道:
>>>>
>>>> 2017-11-20 9:17 GMT+01:00 刘歧 <lq@chinaffmpeg.org>:
>>>>>
>>>>>>>>> 在 2017年11月20日,15:59,Jeyapal, Karthick <kjeyapal@akamai.com> 写道:
>>>>>>>>
>>>>>>>> On 11/20/17, 1:01 PM, "刘歧" <lq@chinaffmpeg.org> wrote:
>>>>>>>> 在 2017年11月8日,17:22,Karthick J <kjeyapal@akamai.com> 写道:
>>>>>>>> +    { "http_user_agent", "override User-Agent field in HTTP header",
>>>>>>>> OFFSET(user_agent), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, E},
>>>>>>> What about dash_user_agent? The reason is http_user_agent maybe get
>>>>>>> mean HTTP Protocol user_agent, but this is used in dashenc.
>>>>>>
>>>>>> I kept http_user_agent to maintain uniformity with hlsenc option.
>>>>>> http://ffmpeg.org/pipermail/ffmpeg-devel/2017-September/215642.html
>>>>>>
>>>>>> In that way, irrespective of hls or dash output format, http_user_agent
>>>>>> would apply for both.
>>>>>
>>>>> that should modify to hls_user_agent too. because that is clarified the option
>>>>> is used in dash or hls, isn’t it?
>>>>
>>>> I consider it a huge advantage for users if options in different modules use
>>>> the same option name if they do the same thing.
>>>>
>>>> Is it possible to create confusion if the options share the same name?
>>
>> Sorry for the bad wording:
>> Is it possible for "http_user_agent" to create confusion because options
>> with this name are used in different demuxers?
> It’s used for dash, isn’t it clear than http_user_agent? If not use -f dash, just only use http_user_agent, what will happen, I think that will get confusion, because hls have the same name, looks like timeout option.

If two components have the same option that does exactly the same
thing, it should also be named the same. Especially if those two
components are also quite similar - ie. two streaming protocol
demuxers/muxers.

- Hendrik
Steven Liu Nov. 20, 2017, 3:54 p.m. UTC | #11
2017-11-20 23:12 GMT+08:00 Hendrik Leppkes <h.leppkes@gmail.com>:
> On Mon, Nov 20, 2017 at 3:11 PM, Steven Liu <lq@chinaffmpeg.org> wrote:
>>
>>
>>> 在 2017年11月20日,下午10:03,Carl Eugen Hoyos <ceffmpeg@gmail.com> 写道:
>>>
>>> 2017-11-20 15:00 GMT+01:00 Steven Liu <lq@chinaffmpeg.org>:
>>>>
>>>>
>>>>> 在 2017年11月20日,下午9:03,Carl Eugen Hoyos <ceffmpeg@gmail.com> 写道:
>>>>>
>>>>> 2017-11-20 9:17 GMT+01:00 刘歧 <lq@chinaffmpeg.org>:
>>>>>>
>>>>>>>>>> 在 2017年11月20日,15:59,Jeyapal, Karthick <kjeyapal@akamai.com> 写道:
>>>>>>>>>
>>>>>>>>> On 11/20/17, 1:01 PM, "刘歧" <lq@chinaffmpeg.org> wrote:
>>>>>>>>> 在 2017年11月8日,17:22,Karthick J <kjeyapal@akamai.com> 写道:
>>>>>>>>> +    { "http_user_agent", "override User-Agent field in HTTP header",
>>>>>>>>> OFFSET(user_agent), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, E},
>>>>>>>> What about dash_user_agent? The reason is http_user_agent maybe get
>>>>>>>> mean HTTP Protocol user_agent, but this is used in dashenc.
>>>>>>>
>>>>>>> I kept http_user_agent to maintain uniformity with hlsenc option.
>>>>>>> http://ffmpeg.org/pipermail/ffmpeg-devel/2017-September/215642.html
>>>>>>>
>>>>>>> In that way, irrespective of hls or dash output format, http_user_agent
>>>>>>> would apply for both.
>>>>>>
>>>>>> that should modify to hls_user_agent too. because that is clarified the option
>>>>>> is used in dash or hls, isn’t it?
>>>>>
>>>>> I consider it a huge advantage for users if options in different modules use
>>>>> the same option name if they do the same thing.
>>>>>
>>>>> Is it possible to create confusion if the options share the same name?
>>>
>>> Sorry for the bad wording:
>>> Is it possible for "http_user_agent" to create confusion because options
>>> with this name are used in different demuxers?
>> It’s used for dash, isn’t it clear than http_user_agent? If not use -f dash, just only use http_user_agent, what will happen, I think that will get confusion, because hls have the same name, looks like timeout option.
>
> If two components have the same option that does exactly the same
> thing, it should also be named the same. Especially if those two
> components are also quite similar - ie. two streaming protocol
> demuxers/muxers.
Ok, i see, then use the previous version  is ok.
>
> - Hendrik
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Michael Niedermayer Nov. 20, 2017, 9:13 p.m. UTC | #12
On Mon, Nov 20, 2017 at 11:54:47PM +0800, Steven Liu wrote:
> 2017-11-20 23:12 GMT+08:00 Hendrik Leppkes <h.leppkes@gmail.com>:
> > On Mon, Nov 20, 2017 at 3:11 PM, Steven Liu <lq@chinaffmpeg.org> wrote:
> >>
> >>
> >>> 在 2017年11月20日,下午10:03,Carl Eugen Hoyos <ceffmpeg@gmail.com> 写道:
> >>>
> >>> 2017-11-20 15:00 GMT+01:00 Steven Liu <lq@chinaffmpeg.org>:
> >>>>
> >>>>
> >>>>> 在 2017年11月20日,下午9:03,Carl Eugen Hoyos <ceffmpeg@gmail.com> 写道:
> >>>>>
> >>>>> 2017-11-20 9:17 GMT+01:00 刘歧 <lq@chinaffmpeg.org>:
> >>>>>>
> >>>>>>>>>> 在 2017年11月20日,15:59,Jeyapal, Karthick <kjeyapal@akamai.com> 写道:
> >>>>>>>>>
> >>>>>>>>> On 11/20/17, 1:01 PM, "刘歧" <lq@chinaffmpeg.org> wrote:
> >>>>>>>>> 在 2017年11月8日,17:22,Karthick J <kjeyapal@akamai.com> 写道:
> >>>>>>>>> +    { "http_user_agent", "override User-Agent field in HTTP header",
> >>>>>>>>> OFFSET(user_agent), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, E},
> >>>>>>>> What about dash_user_agent? The reason is http_user_agent maybe get
> >>>>>>>> mean HTTP Protocol user_agent, but this is used in dashenc.
> >>>>>>>
> >>>>>>> I kept http_user_agent to maintain uniformity with hlsenc option.
> >>>>>>> http://ffmpeg.org/pipermail/ffmpeg-devel/2017-September/215642.html
> >>>>>>>
> >>>>>>> In that way, irrespective of hls or dash output format, http_user_agent
> >>>>>>> would apply for both.
> >>>>>>
> >>>>>> that should modify to hls_user_agent too. because that is clarified the option
> >>>>>> is used in dash or hls, isn’t it?
> >>>>>
> >>>>> I consider it a huge advantage for users if options in different modules use
> >>>>> the same option name if they do the same thing.
> >>>>>
> >>>>> Is it possible to create confusion if the options share the same name?
> >>>
> >>> Sorry for the bad wording:
> >>> Is it possible for "http_user_agent" to create confusion because options
> >>> with this name are used in different demuxers?
> >> It’s used for dash, isn’t it clear than http_user_agent? If not use -f dash, just only use http_user_agent, what will happen, I think that will get confusion, because hls have the same name, looks like timeout option.
> >
> > If two components have the same option that does exactly the same
> > thing, it should also be named the same. Especially if those two
> > components are also quite similar - ie. two streaming protocol
> > demuxers/muxers.
> Ok, i see, then use the previous version  is ok.

ok, will apply the previous one unless someone else is quicker

[...]
diff mbox

Patch

diff --git a/doc/muxers.texi b/doc/muxers.texi
index 91bbe67..412fede 100644
--- a/doc/muxers.texi
+++ b/doc/muxers.texi
@@ -247,6 +247,8 @@  DASH-templated name to used for the initialization segment. Default is "init-str
 DASH-templated name to used for the media segments. Default is "chunk-stream$RepresentationID$-$Number%05d$.m4s"
 @item -utc_timing_url @var{utc_url}
 URL of the page that will return the UTC timestamp in ISO format. Example: "https://time.akamai.com/?iso"
+@item -http_user_agent @var{user_agent}
+Override User-Agent field in HTTP header. Applicable only for HTTP output.
 @item -adaptation_sets @var{adaptation_sets}
 Assign streams to AdaptationSets. Syntax is "id=x,streams=a,b,c id=y,streams=d,e" with x and y being the IDs
 of the adaptation sets and a,b,c,d and e are the indices of the mapped streams.
diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c
index 7813f44..a68f7fb 100644
--- a/libavformat/dashenc.c
+++ b/libavformat/dashenc.c
@@ -100,6 +100,7 @@  typedef struct DASHContext {
     const char *init_seg_name;
     const char *media_seg_name;
     const char *utc_timing_url;
+    const char *user_agent;
 } DASHContext;
 
 static struct codec_string {
@@ -210,6 +211,12 @@  static int flush_dynbuf(OutputStream *os, int *range_length)
     return avio_open_dyn_buf(&os->ctx->pb);
 }
 
+static void set_http_options(AVDictionary **options, DASHContext *c)
+{
+    if (c->user_agent)
+        av_dict_set(options, "user_agent", c->user_agent, 0);
+}
+
 static int flush_init_segment(AVFormatContext *s, OutputStream *os)
 {
     DASHContext *c = s->priv_data;
@@ -575,16 +582,19 @@  static int write_manifest(AVFormatContext *s, int final)
     int use_rename = proto && !strcmp(proto, "file");
     static unsigned int warned_non_file = 0;
     AVDictionaryEntry *title = av_dict_get(s->metadata, "title", NULL, 0);
+    AVDictionary *opts = NULL;
 
     if (!use_rename && !warned_non_file++)
         av_log(s, AV_LOG_ERROR, "Cannot use rename on non file protocol, this may lead to races and temporary partial files\n");
 
     snprintf(temp_filename, sizeof(temp_filename), use_rename ? "%s.tmp" : "%s", s->filename);
-    ret = s->io_open(s, &out, temp_filename, AVIO_FLAG_WRITE, NULL);
+    set_http_options(&opts, c);
+    ret = s->io_open(s, &out, temp_filename, AVIO_FLAG_WRITE, &opts);
     if (ret < 0) {
         av_log(s, AV_LOG_ERROR, "Unable to open %s for writing\n", temp_filename);
         return ret;
     }
+    av_dict_free(&opts);
     avio_printf(out, "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
     avio_printf(out, "<MPD xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"
                 "\txmlns=\"urn:mpeg:dash:schema:mpd:2011\"\n"
@@ -768,9 +778,11 @@  static int dash_init(AVFormatContext *s)
             ff_dash_fill_tmpl_params(os->initfile, sizeof(os->initfile), c->init_seg_name, i, 0, os->bit_rate, 0);
         }
         snprintf(filename, sizeof(filename), "%s%s", c->dirname, os->initfile);
-        ret = s->io_open(s, &os->out, filename, AVIO_FLAG_WRITE, NULL);
+        set_http_options(&opts, c);
+        ret = s->io_open(s, &os->out, filename, AVIO_FLAG_WRITE, &opts);
         if (ret < 0)
             return ret;
+        av_dict_free(&opts);
         os->init_start_pos = 0;
 
         if (!strcmp(os->format_name, "mp4")) {
@@ -974,12 +986,15 @@  static int dash_flush(AVFormatContext *s, int final, int stream)
         }
 
         if (!c->single_file) {
+            AVDictionary *opts = NULL;
             ff_dash_fill_tmpl_params(filename, sizeof(filename), c->media_seg_name, i, os->segment_index, os->bit_rate, os->start_pts);
             snprintf(full_path, sizeof(full_path), "%s%s", c->dirname, filename);
             snprintf(temp_path, sizeof(temp_path), use_rename ? "%s.tmp" : "%s", full_path);
-            ret = s->io_open(s, &os->out, temp_path, AVIO_FLAG_WRITE, NULL);
+            set_http_options(&opts, c);
+            ret = s->io_open(s, &os->out, temp_path, AVIO_FLAG_WRITE, &opts);
             if (ret < 0)
                 break;
+            av_dict_free(&opts);
             if (!strcmp(os->format_name, "mp4"))
                 write_styp(os->ctx->pb);
         } else {
@@ -1188,6 +1203,7 @@  static const AVOption options[] = {
     { "init_seg_name", "DASH-templated name to used for the initialization segment", OFFSET(init_seg_name), AV_OPT_TYPE_STRING, {.str = "init-stream$RepresentationID$.m4s"}, 0, 0, E },
     { "media_seg_name", "DASH-templated name to used for the media segments", OFFSET(media_seg_name), AV_OPT_TYPE_STRING, {.str = "chunk-stream$RepresentationID$-$Number%05d$.m4s"}, 0, 0, E },
     { "utc_timing_url", "URL of the page that will return the UTC timestamp in ISO format", OFFSET(utc_timing_url), AV_OPT_TYPE_STRING, { 0 }, 0, 0, E },
+    { "http_user_agent", "override User-Agent field in HTTP header", OFFSET(user_agent), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, E},
     { NULL },
 };