Re: [FFmpeg-devel] [PATCH v4] avformat/hlsenc: merge mpegts and fmp4 workflow to one workflow

2019-09-09 Thread Liu Steven


> 在 2019年9月8日,下午2:55,Andreas Rheinhardt  写道:
> 
> Liu Steven:
>> 
>> 
>>> 在 2019年8月9日,下午5:30,Liu Steven  写道:
>>> 
>>> 
>>> 
 在 2019年8月5日,上午10:29,Steven Liu  写道:
 
 just remove the 'i' of the v3 mail subject.
 write mpegts or fmp4 context into buffer, and flush the buffer into
 output file when split fragment. merge two format split workflow into
 one workflow
 
 Signed-off-by: Steven Liu 
>>> 
>>> ping?
>>> 
>> Pushed
> 
> This patch both created and fixed memleaks: Before this patch,
> generating hls_segment_size.m3u8 (needed for fate-hls-segment-size)
> leaks 792 B directly and 787122 B indirectly. With this patch,
> Generating hls_segment_size.m3u8 and hls_init_time.m3u8 leaks 264 B
> directly and 1056 B indirectly.
> The leaks happen in hls_write_trailer: The last dynamic buffer that is
> opened in flush_dynbuf is not freed. I wanted to add a call to
> ffio_free_dyn_buf, but then I noticed that it seems that if something
> gets written in av_write_trailer(oc) it never leaves the dynamic
> buffer, although it probably should. So I leave fixing this to those
> who know this code better than I do.

Hi Andreas,

Do you mean it should be fixed by this patch?

https://patchwork.ffmpeg.org/patch/14984/


> 
> - Andreas
> 
> PS: For the fate test run with Valgrind this means that generating the
> necessary test files fails. But the tests itself are not counted as
> failing on the website [1]. Instead, the number of tests decreased.
> 
> [1]: http://fate.ffmpeg.org/history.cgi?slot=x86_64-archlinux-gcc-valgrind
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Thanks
 Steven

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

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH v4] avformat/hlsenc: merge mpegts and fmp4 workflow to one workflow

2019-09-08 Thread Andreas Rheinhardt
Liu Steven:
> 
> 
>> 在 2019年8月9日,下午5:30,Liu Steven  写道:
>>
>>
>>
>>> 在 2019年8月5日,上午10:29,Steven Liu  写道:
>>>
>>> just remove the 'i' of the v3 mail subject.
>>> write mpegts or fmp4 context into buffer, and flush the buffer into
>>> output file when split fragment. merge two format split workflow into
>>> one workflow
>>>
>>> Signed-off-by: Steven Liu 
>>
>> ping?
>>
> Pushed

This patch both created and fixed memleaks: Before this patch,
generating hls_segment_size.m3u8 (needed for fate-hls-segment-size)
leaks 792 B directly and 787122 B indirectly. With this patch,
Generating hls_segment_size.m3u8 and hls_init_time.m3u8 leaks 264 B
directly and 1056 B indirectly.
The leaks happen in hls_write_trailer: The last dynamic buffer that is
opened in flush_dynbuf is not freed. I wanted to add a call to
ffio_free_dyn_buf, but then I noticed that it seems that if something
gets written in av_write_trailer(oc) it never leaves the dynamic
buffer, although it probably should. So I leave fixing this to those
who know this code better than I do.

- Andreas

PS: For the fate test run with Valgrind this means that generating the
necessary test files fails. But the tests itself are not counted as
failing on the website [1]. Instead, the number of tests decreased.

[1]: http://fate.ffmpeg.org/history.cgi?slot=x86_64-archlinux-gcc-valgrind
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH v4] avformat/hlsenc: merge mpegts and fmp4 workflow to one workflow

2019-08-17 Thread Liu Steven


> 在 2019年8月9日,下午5:30,Liu Steven  写道:
> 
> 
> 
>> 在 2019年8月5日,上午10:29,Steven Liu  写道:
>> 
>> just remove the 'i' of the v3 mail subject.
>> write mpegts or fmp4 context into buffer, and flush the buffer into
>> output file when split fragment. merge two format split workflow into
>> one workflow
>> 
>> Signed-off-by: Steven Liu 
>> ---
>> libavformat/hlsenc.c | 251 +--
>> 1 file changed, 124 insertions(+), 127 deletions(-)
>> 
>> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
>> index 51310fb528..f6f9c8161d 100644
>> --- a/libavformat/hlsenc.c
>> +++ b/libavformat/hlsenc.c
>> @@ -815,7 +815,7 @@ static int hls_mux_init(AVFormatContext *s, 
>> VariantStream *vs)
>>vs->start_pos = 0;
>>vs->new_start = 1;
>> 
>> -if (hls->segment_type == SEGMENT_TYPE_FMP4) {
>> +if (hls->segment_type == SEGMENT_TYPE_FMP4 && hls->max_seg_size > 0) {
>>if (hls->http_persistent > 0) {
>>//TODO: Support fragment fmp4 for http persistent in HLS muxer.
>>av_log(s, AV_LOG_WARNING, "http persistent mode is currently 
>> unsupported for fragment mp4 in the HLS muxer.\n");
>> @@ -824,34 +824,38 @@ static int hls_mux_init(AVFormatContext *s, 
>> VariantStream *vs)
>>av_log(s, AV_LOG_WARNING, "Multi-file byterange mode is currently 
>> unsupported in the HLS muxer.\n");
>>return AVERROR_PATCHWELCOME;
>>}
>> +}
>> 
>> -vs->packets_written = 0;
>> -vs->init_range_length = 0;
>> -set_http_options(s, , hls);
>> -if ((ret = avio_open_dyn_buf(>pb)) < 0)
>> -return ret;
>> +vs->packets_written = 0;
>> +vs->init_range_length = 0;
>> +set_http_options(s, , hls);
>> +if ((ret = avio_open_dyn_buf(>pb)) < 0)
>> +return ret;
>> 
>> +if (hls->segment_type == SEGMENT_TYPE_FMP4) {
>>if (byterange_mode) {
>>ret = hlsenc_io_open(s, >out, vs->basename, );
>>} else {
>>ret = hlsenc_io_open(s, >out, vs->base_output_dirname, 
>> );
>>}
>> -av_dict_free();
>> +}
>> +av_dict_free();
>> +if (ret < 0) {
>> +av_log(s, AV_LOG_ERROR, "Failed to open segment '%s'\n", 
>> vs->fmp4_init_filename);
>> +return ret;
>> +}
>> +
>> +if (hls->format_options_str) {
>> +ret = av_dict_parse_string(>format_options, 
>> hls->format_options_str, "=", ":", 0);
>>if (ret < 0) {
>> -av_log(s, AV_LOG_ERROR, "Failed to open segment '%s'\n", 
>> vs->fmp4_init_filename);
>> +av_log(s, AV_LOG_ERROR, "Could not parse format options list 
>> '%s'\n",
>> +   hls->format_options_str);
>>return ret;
>>}
>> +}
>> 
>> -if (hls->format_options_str) {
>> -ret = av_dict_parse_string(>format_options, 
>> hls->format_options_str, "=", ":", 0);
>> -if (ret < 0) {
>> -av_log(s, AV_LOG_ERROR, "Could not parse format options 
>> list '%s'\n",
>> -   hls->format_options_str);
>> -return ret;
>> -}
>> -}
>> -
>> -av_dict_copy(, hls->format_options, 0);
>> +av_dict_copy(, hls->format_options, 0);
>> +if (hls->segment_type == SEGMENT_TYPE_FMP4) {
>>av_dict_set(, "fflags", "-autobsf", 0);
>>av_dict_set(, "movflags", "+frag_custom+dash+delay_moov", 
>> AV_DICT_APPEND);
>>ret = avformat_init_output(oc, );
>> @@ -862,9 +866,9 @@ static int hls_mux_init(AVFormatContext *s, 
>> VariantStream *vs)
>>av_dict_free();
>>return AVERROR(EINVAL);
>>}
>> -avio_flush(oc->pb);
>> -av_dict_free();
>>}
>> +avio_flush(oc->pb);
>> +av_dict_free();
>>return 0;
>> }
>> 
>> @@ -1435,7 +1439,6 @@ static int hls_window(AVFormatContext *s, int last, 
>> VariantStream *vs)
>> {
>>HLSContext *hls = s->priv_data;
>>HLSSegment *en;
>> -AVFormatContext *oc = vs->avf;
>>int target_duration = 0;
>>int ret = 0;
>>char temp_filename[MAX_URL_SIZE];
>> @@ -1471,7 +1474,7 @@ static int hls_window(AVFormatContext *s, int last, 
>> VariantStream *vs)
>> 
>>set_http_options(s, , hls);
>>snprintf(temp_filename, sizeof(temp_filename), use_temp_file ? "%s.tmp" : 
>> "%s", vs->m3u8_name);
>> -if ((ret = hlsenc_io_open(s, (byterange_mode || hls->segment_type == 
>> SEGMENT_TYPE_FMP4) ? >m3u8_out : >pb, temp_filename, )) < 
>> 0) {
>> +if ((ret = hlsenc_io_open(s, (byterange_mode || hls->segment_type == 
>> SEGMENT_TYPE_FMP4) ? >m3u8_out : >out, temp_filename, )) < 
>> 0) {
>>if (hls->ignore_io_errors)
>>ret = 0;
>>goto fail;
>> @@ -1483,33 +1486,33 @@ static int hls_window(AVFormatContext *s, int last, 
>> VariantStream *vs)
>>}
>> 
>>vs->discontinuity_set = 0;
>> -ff_hls_write_playlist_header((byterange_mode || hls->segment_type == 
>> SEGMENT_TYPE_FMP4) ? hls->m3u8_out : oc->pb, hls->version, 

Re: [FFmpeg-devel] [PATCH v4] avformat/hlsenc: merge mpegts and fmp4 workflow to one workflow

2019-08-09 Thread Liu Steven


> 在 2019年8月5日,上午10:29,Steven Liu  写道:
> 
> just remove the 'i' of the v3 mail subject.
> write mpegts or fmp4 context into buffer, and flush the buffer into
> output file when split fragment. merge two format split workflow into
> one workflow
> 
> Signed-off-by: Steven Liu 
> ---
> libavformat/hlsenc.c | 251 +--
> 1 file changed, 124 insertions(+), 127 deletions(-)
> 
> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
> index 51310fb528..f6f9c8161d 100644
> --- a/libavformat/hlsenc.c
> +++ b/libavformat/hlsenc.c
> @@ -815,7 +815,7 @@ static int hls_mux_init(AVFormatContext *s, VariantStream 
> *vs)
> vs->start_pos = 0;
> vs->new_start = 1;
> 
> -if (hls->segment_type == SEGMENT_TYPE_FMP4) {
> +if (hls->segment_type == SEGMENT_TYPE_FMP4 && hls->max_seg_size > 0) {
> if (hls->http_persistent > 0) {
> //TODO: Support fragment fmp4 for http persistent in HLS muxer.
> av_log(s, AV_LOG_WARNING, "http persistent mode is currently 
> unsupported for fragment mp4 in the HLS muxer.\n");
> @@ -824,34 +824,38 @@ static int hls_mux_init(AVFormatContext *s, 
> VariantStream *vs)
> av_log(s, AV_LOG_WARNING, "Multi-file byterange mode is currently 
> unsupported in the HLS muxer.\n");
> return AVERROR_PATCHWELCOME;
> }
> +}
> 
> -vs->packets_written = 0;
> -vs->init_range_length = 0;
> -set_http_options(s, , hls);
> -if ((ret = avio_open_dyn_buf(>pb)) < 0)
> -return ret;
> +vs->packets_written = 0;
> +vs->init_range_length = 0;
> +set_http_options(s, , hls);
> +if ((ret = avio_open_dyn_buf(>pb)) < 0)
> +return ret;
> 
> +if (hls->segment_type == SEGMENT_TYPE_FMP4) {
> if (byterange_mode) {
> ret = hlsenc_io_open(s, >out, vs->basename, );
> } else {
> ret = hlsenc_io_open(s, >out, vs->base_output_dirname, 
> );
> }
> -av_dict_free();
> +}
> +av_dict_free();
> +if (ret < 0) {
> +av_log(s, AV_LOG_ERROR, "Failed to open segment '%s'\n", 
> vs->fmp4_init_filename);
> +return ret;
> +}
> +
> +if (hls->format_options_str) {
> +ret = av_dict_parse_string(>format_options, 
> hls->format_options_str, "=", ":", 0);
> if (ret < 0) {
> -av_log(s, AV_LOG_ERROR, "Failed to open segment '%s'\n", 
> vs->fmp4_init_filename);
> +av_log(s, AV_LOG_ERROR, "Could not parse format options list 
> '%s'\n",
> +   hls->format_options_str);
> return ret;
> }
> +}
> 
> -if (hls->format_options_str) {
> -ret = av_dict_parse_string(>format_options, 
> hls->format_options_str, "=", ":", 0);
> -if (ret < 0) {
> -av_log(s, AV_LOG_ERROR, "Could not parse format options list 
> '%s'\n",
> -   hls->format_options_str);
> -return ret;
> -}
> -}
> -
> -av_dict_copy(, hls->format_options, 0);
> +av_dict_copy(, hls->format_options, 0);
> +if (hls->segment_type == SEGMENT_TYPE_FMP4) {
> av_dict_set(, "fflags", "-autobsf", 0);
> av_dict_set(, "movflags", "+frag_custom+dash+delay_moov", 
> AV_DICT_APPEND);
> ret = avformat_init_output(oc, );
> @@ -862,9 +866,9 @@ static int hls_mux_init(AVFormatContext *s, VariantStream 
> *vs)
> av_dict_free();
> return AVERROR(EINVAL);
> }
> -avio_flush(oc->pb);
> -av_dict_free();
> }
> +avio_flush(oc->pb);
> +av_dict_free();
> return 0;
> }
> 
> @@ -1435,7 +1439,6 @@ static int hls_window(AVFormatContext *s, int last, 
> VariantStream *vs)
> {
> HLSContext *hls = s->priv_data;
> HLSSegment *en;
> -AVFormatContext *oc = vs->avf;
> int target_duration = 0;
> int ret = 0;
> char temp_filename[MAX_URL_SIZE];
> @@ -1471,7 +1474,7 @@ static int hls_window(AVFormatContext *s, int last, 
> VariantStream *vs)
> 
> set_http_options(s, , hls);
> snprintf(temp_filename, sizeof(temp_filename), use_temp_file ? "%s.tmp" : 
> "%s", vs->m3u8_name);
> -if ((ret = hlsenc_io_open(s, (byterange_mode || hls->segment_type == 
> SEGMENT_TYPE_FMP4) ? >m3u8_out : >pb, temp_filename, )) < 0) 
> {
> +if ((ret = hlsenc_io_open(s, (byterange_mode || hls->segment_type == 
> SEGMENT_TYPE_FMP4) ? >m3u8_out : >out, temp_filename, )) < 
> 0) {
> if (hls->ignore_io_errors)
> ret = 0;
> goto fail;
> @@ -1483,33 +1486,33 @@ static int hls_window(AVFormatContext *s, int last, 
> VariantStream *vs)
> }
> 
> vs->discontinuity_set = 0;
> -ff_hls_write_playlist_header((byterange_mode || hls->segment_type == 
> SEGMENT_TYPE_FMP4) ? hls->m3u8_out : oc->pb, hls->version, hls->allowcache,
> +ff_hls_write_playlist_header((byterange_mode || hls->segment_type == 
> SEGMENT_TYPE_FMP4) ? hls->m3u8_out : vs->out, 

[FFmpeg-devel] [PATCH v4] avformat/hlsenc: merge mpegts and fmp4 workflow to one workflow

2019-08-04 Thread Steven Liu
just remove the 'i' of the v3 mail subject.
write mpegts or fmp4 context into buffer, and flush the buffer into
output file when split fragment. merge two format split workflow into
one workflow

Signed-off-by: Steven Liu 
---
 libavformat/hlsenc.c | 251 +--
 1 file changed, 124 insertions(+), 127 deletions(-)

diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index 51310fb528..f6f9c8161d 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -815,7 +815,7 @@ static int hls_mux_init(AVFormatContext *s, VariantStream 
*vs)
 vs->start_pos = 0;
 vs->new_start = 1;
 
-if (hls->segment_type == SEGMENT_TYPE_FMP4) {
+if (hls->segment_type == SEGMENT_TYPE_FMP4 && hls->max_seg_size > 0) {
 if (hls->http_persistent > 0) {
 //TODO: Support fragment fmp4 for http persistent in HLS muxer.
 av_log(s, AV_LOG_WARNING, "http persistent mode is currently 
unsupported for fragment mp4 in the HLS muxer.\n");
@@ -824,34 +824,38 @@ static int hls_mux_init(AVFormatContext *s, VariantStream 
*vs)
 av_log(s, AV_LOG_WARNING, "Multi-file byterange mode is currently 
unsupported in the HLS muxer.\n");
 return AVERROR_PATCHWELCOME;
 }
+}
 
-vs->packets_written = 0;
-vs->init_range_length = 0;
-set_http_options(s, , hls);
-if ((ret = avio_open_dyn_buf(>pb)) < 0)
-return ret;
+vs->packets_written = 0;
+vs->init_range_length = 0;
+set_http_options(s, , hls);
+if ((ret = avio_open_dyn_buf(>pb)) < 0)
+return ret;
 
+if (hls->segment_type == SEGMENT_TYPE_FMP4) {
 if (byterange_mode) {
 ret = hlsenc_io_open(s, >out, vs->basename, );
 } else {
 ret = hlsenc_io_open(s, >out, vs->base_output_dirname, 
);
 }
-av_dict_free();
+}
+av_dict_free();
+if (ret < 0) {
+av_log(s, AV_LOG_ERROR, "Failed to open segment '%s'\n", 
vs->fmp4_init_filename);
+return ret;
+}
+
+if (hls->format_options_str) {
+ret = av_dict_parse_string(>format_options, 
hls->format_options_str, "=", ":", 0);
 if (ret < 0) {
-av_log(s, AV_LOG_ERROR, "Failed to open segment '%s'\n", 
vs->fmp4_init_filename);
+av_log(s, AV_LOG_ERROR, "Could not parse format options list 
'%s'\n",
+   hls->format_options_str);
 return ret;
 }
+}
 
-if (hls->format_options_str) {
-ret = av_dict_parse_string(>format_options, 
hls->format_options_str, "=", ":", 0);
-if (ret < 0) {
-av_log(s, AV_LOG_ERROR, "Could not parse format options list 
'%s'\n",
-   hls->format_options_str);
-return ret;
-}
-}
-
-av_dict_copy(, hls->format_options, 0);
+av_dict_copy(, hls->format_options, 0);
+if (hls->segment_type == SEGMENT_TYPE_FMP4) {
 av_dict_set(, "fflags", "-autobsf", 0);
 av_dict_set(, "movflags", "+frag_custom+dash+delay_moov", 
AV_DICT_APPEND);
 ret = avformat_init_output(oc, );
@@ -862,9 +866,9 @@ static int hls_mux_init(AVFormatContext *s, VariantStream 
*vs)
 av_dict_free();
 return AVERROR(EINVAL);
 }
-avio_flush(oc->pb);
-av_dict_free();
 }
+avio_flush(oc->pb);
+av_dict_free();
 return 0;
 }
 
@@ -1435,7 +1439,6 @@ static int hls_window(AVFormatContext *s, int last, 
VariantStream *vs)
 {
 HLSContext *hls = s->priv_data;
 HLSSegment *en;
-AVFormatContext *oc = vs->avf;
 int target_duration = 0;
 int ret = 0;
 char temp_filename[MAX_URL_SIZE];
@@ -1471,7 +1474,7 @@ static int hls_window(AVFormatContext *s, int last, 
VariantStream *vs)
 
 set_http_options(s, , hls);
 snprintf(temp_filename, sizeof(temp_filename), use_temp_file ? "%s.tmp" : 
"%s", vs->m3u8_name);
-if ((ret = hlsenc_io_open(s, (byterange_mode || hls->segment_type == 
SEGMENT_TYPE_FMP4) ? >m3u8_out : >pb, temp_filename, )) < 0) {
+if ((ret = hlsenc_io_open(s, (byterange_mode || hls->segment_type == 
SEGMENT_TYPE_FMP4) ? >m3u8_out : >out, temp_filename, )) < 0) {
 if (hls->ignore_io_errors)
 ret = 0;
 goto fail;
@@ -1483,33 +1486,33 @@ static int hls_window(AVFormatContext *s, int last, 
VariantStream *vs)
 }
 
 vs->discontinuity_set = 0;
-ff_hls_write_playlist_header((byterange_mode || hls->segment_type == 
SEGMENT_TYPE_FMP4) ? hls->m3u8_out : oc->pb, hls->version, hls->allowcache,
+ff_hls_write_playlist_header((byterange_mode || hls->segment_type == 
SEGMENT_TYPE_FMP4) ? hls->m3u8_out : vs->out, hls->version, hls->allowcache,
  target_duration, sequence, hls->pl_type, 
hls->flags & HLS_I_FRAMES_ONLY);
 
 if((hls->flags & HLS_DISCONT_START) && sequence==hls->start_sequence && 
vs->discontinuity_set==0 ){
-