[FFmpeg-devel] [PATCH] avformat/hlsenc: Check ret on avformat_write_header

Brendan McGrath redmcg at redmandi.dyndns.org
Wed Jan 24 03:24:19 EET 2018


Encoding currently fails when using hls_ts_options with the fmp4
segment type.

This is due to the fact that avformat_write_header does not process
the passed options when the avformat is already initialized.

When using fmp4, the hls_ts_options are parsed and the avformat
initialized within hls_mux_init.

This patch checks the return of avformat_write_header so that if
it is greater than zero (indicating the avformat is already
initialized) then it does not error.

Signed-off-by: Brendan McGrath <redmcg at redmandi.dyndns.org>
---
I'm not sure if hls_ts_options is supposed to be used with fmp4 as the
description is currently:
hls_ts_options    <string>     E....... set hls mpegts list of options for the container format used for hls

If it is (and the code within hls_mux_init seems to indicate that it is) - then this
patch fixes that (and the next will change the description - perhaps the option should
be renamed too?).

I also considered checking if ret was < 0 and erroring immediately rather than relying
on av_dict_count. But I wasn't sure if that check had been intentionally left out
so the av_dict_free would take place.

Let me know if the preference is for another if statement for ret < 0.

 libavformat/hlsenc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index 42e437f..d83d3b9 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -1878,7 +1878,7 @@ static int hls_write_header(AVFormatContext *s)
 
         av_dict_copy(&options, hls->format_options, 0);
         ret = avformat_write_header(vs->avf, &options);
-        if (av_dict_count(options)) {
+        if (ret <= 0 && av_dict_count(options)) {
             av_log(s, AV_LOG_ERROR, "Some of provided format options in '%s' are not recognized\n", hls->format_options_str);
             ret = AVERROR(EINVAL);
             av_dict_free(&options);
-- 
2.7.4



More information about the ffmpeg-devel mailing list