Re: [FFmpeg-devel] [PATCH] avformat/hlsenc: move init operations from write_header to init
> > > >On 12/4/17, 3:20 PM, "Steven Liu"wrote: > > > >Signed-off-by: Steven Liu > >--- > > libavformat/hlsenc.c | 681 ++- > > 1 file changed, 345 insertions(+), 336 deletions(-) > > > >diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c > >index aeeed5bcd2..852663d28f 100644 > >--- a/libavformat/hlsenc.c > >+++ b/libavformat/hlsenc.c > >@@ -1636,329 +1636,12 @@ static int hls_write_header(AVFormatContext *s) > > { > > HLSContext *hls = s->priv_data; > > int ret, i, j; > >-char *p = NULL; > >-const char *pattern = "%d.ts"; > >-const char *pattern_localtime_fmt = get_default_pattern_localtime_fmt(s); > >-const char *vtt_pattern = "%d.vtt"; > > AVDictionary *options = NULL; > >-int basename_size = 0; > >-int vtt_basename_size = 0, m3u8_name_size = 0; > > VariantStream *vs = NULL; > >-int fmp4_init_filename_len = strlen(hls->fmp4_init_filename) + 1; > >- > >-ret = update_variant_stream_info(s); > >-if (ret < 0) { > >-av_log(s, AV_LOG_ERROR, "Variant stream info update failed with >status %x\n", > >-ret); > >-goto fail; > >-} > >- > >-//TODO: Updates needed to encryption functionality with periodic re-key >when more than one variant streams are present > >-if (hls->nb_varstreams > 1 && hls->flags & HLS_PERIODIC_REKEY) { > >-ret = AVERROR(EINVAL); > >-av_log(s, AV_LOG_ERROR, "Periodic re-key not supported when more than >one variant streams are present\n"); > >-goto fail; > >-} > >- > >-if (hls->master_pl_name) { > >-ret = update_master_pl_info(s); > >-if (ret < 0) { > >-av_log(s, AV_LOG_ERROR, "Master stream info update failed with >status %x\n", > >-ret); > >-goto fail; > >-} > >-} > >- > >-if (hls->segment_type == SEGMENT_TYPE_FMP4) { > >-pattern = "%d.m4s"; > >-} > >-if ((hls->start_sequence_source_type == >HLS_START_SEQUENCE_AS_SECONDS_SINCE_EPOCH) || > >-(hls->start_sequence_source_type == >HLS_START_SEQUENCE_AS_FORMATTED_DATETIME)) { > >-time_t t = time(NULL); // we will need it in either case > >-if (hls->start_sequence_source_type == >HLS_START_SEQUENCE_AS_SECONDS_SINCE_EPOCH) { > >-hls->start_sequence = (int64_t)t; > >-} else if (hls->start_sequence_source_type == >HLS_START_SEQUENCE_AS_FORMATTED_DATETIME) { > >-char b[15]; > >-struct tm *p, tmbuf; > >-if (!(p = localtime_r(, ))) > >-return AVERROR(ENOMEM); > >-if (!strftime(b, sizeof(b), "%Y%m%d%H%M%S", p)) > >-return AVERROR(ENOMEM); > >-hls->start_sequence = strtoll(b, NULL, 10); > >-} > >-av_log(hls, AV_LOG_DEBUG, "start_number evaluated to %"PRId64"\n", >hls->start_sequence); > >-} > > > > for (i = 0; i < hls->nb_varstreams; i++) { > > vs = >var_streams[i]; > > > >-vs->sequence = hls->start_sequence; > >-hls->recording_time = (hls->init_time ? hls->init_time : hls->time) * >AV_TIME_BASE; > >-vs->start_pts = AV_NOPTS_VALUE; > >-vs->end_pts = AV_NOPTS_VALUE; > >-vs->current_segment_final_filename_fmt[0] = '\0'; > >- > >-if (hls->flags & HLS_SPLIT_BY_TIME && hls->flags & >HLS_INDEPENDENT_SEGMENTS) { > >-// Independent segments cannot be guaranteed when splitting by time > >-hls->flags &= ~HLS_INDEPENDENT_SEGMENTS; > >-av_log(s, AV_LOG_WARNING, > >- "'split_by_time' and 'independent_segments' cannot be enabled >together. " > >- "Disabling 'independent_segments' flag\n"); > >-} > >- > >-if (hls->flags & HLS_PROGRAM_DATE_TIME) { > >-time_t now0; > >-time(); > >-vs->initial_prog_date_time = now0; > >-} > >- > >-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); > >-goto fail; > >-} > >-} > >- > >-for (j = 0; j < vs->nb_streams; j++) { > >-vs->has_video += > >-vs->streams[j]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO; > >-vs->has_subtitle += > >-vs->streams[j]->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE; > >-} > >- > >-if (vs->has_video > 1) > >-av_log(s, AV_LOG_WARNING, > >- "More than a single video stream present, " > >- "expect issues decoding it.\n"); > >- > >-if (hls->segment_type == SEGMENT_TYPE_FMP4) { > >-vs->oformat = av_guess_format("mp4", NULL, NULL); > >-} else { > >-vs->oformat = av_guess_format("mpegts", NULL, NULL); > >-} > >- > >-if (!vs->oformat) { > >-
[FFmpeg-devel] [PATCH] avformat/hlsenc: move init operations from write_header to init
Signed-off-by: Steven Liu--- libavformat/hlsenc.c | 681 ++- 1 file changed, 345 insertions(+), 336 deletions(-) diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c index aeeed5bcd2..852663d28f 100644 --- a/libavformat/hlsenc.c +++ b/libavformat/hlsenc.c @@ -1636,329 +1636,12 @@ static int hls_write_header(AVFormatContext *s) { HLSContext *hls = s->priv_data; int ret, i, j; -char *p = NULL; -const char *pattern = "%d.ts"; -const char *pattern_localtime_fmt = get_default_pattern_localtime_fmt(s); -const char *vtt_pattern = "%d.vtt"; AVDictionary *options = NULL; -int basename_size = 0; -int vtt_basename_size = 0, m3u8_name_size = 0; VariantStream *vs = NULL; -int fmp4_init_filename_len = strlen(hls->fmp4_init_filename) + 1; - -ret = update_variant_stream_info(s); -if (ret < 0) { -av_log(s, AV_LOG_ERROR, "Variant stream info update failed with status %x\n", -ret); -goto fail; -} - -//TODO: Updates needed to encryption functionality with periodic re-key when more than one variant streams are present -if (hls->nb_varstreams > 1 && hls->flags & HLS_PERIODIC_REKEY) { -ret = AVERROR(EINVAL); -av_log(s, AV_LOG_ERROR, "Periodic re-key not supported when more than one variant streams are present\n"); -goto fail; -} - -if (hls->master_pl_name) { -ret = update_master_pl_info(s); -if (ret < 0) { -av_log(s, AV_LOG_ERROR, "Master stream info update failed with status %x\n", -ret); -goto fail; -} -} - -if (hls->segment_type == SEGMENT_TYPE_FMP4) { -pattern = "%d.m4s"; -} -if ((hls->start_sequence_source_type == HLS_START_SEQUENCE_AS_SECONDS_SINCE_EPOCH) || -(hls->start_sequence_source_type == HLS_START_SEQUENCE_AS_FORMATTED_DATETIME)) { -time_t t = time(NULL); // we will need it in either case -if (hls->start_sequence_source_type == HLS_START_SEQUENCE_AS_SECONDS_SINCE_EPOCH) { -hls->start_sequence = (int64_t)t; -} else if (hls->start_sequence_source_type == HLS_START_SEQUENCE_AS_FORMATTED_DATETIME) { -char b[15]; -struct tm *p, tmbuf; -if (!(p = localtime_r(, ))) -return AVERROR(ENOMEM); -if (!strftime(b, sizeof(b), "%Y%m%d%H%M%S", p)) -return AVERROR(ENOMEM); -hls->start_sequence = strtoll(b, NULL, 10); -} -av_log(hls, AV_LOG_DEBUG, "start_number evaluated to %"PRId64"\n", hls->start_sequence); -} for (i = 0; i < hls->nb_varstreams; i++) { vs = >var_streams[i]; -vs->sequence = hls->start_sequence; -hls->recording_time = (hls->init_time ? hls->init_time : hls->time) * AV_TIME_BASE; -vs->start_pts = AV_NOPTS_VALUE; -vs->end_pts = AV_NOPTS_VALUE; -vs->current_segment_final_filename_fmt[0] = '\0'; - -if (hls->flags & HLS_SPLIT_BY_TIME && hls->flags & HLS_INDEPENDENT_SEGMENTS) { -// Independent segments cannot be guaranteed when splitting by time -hls->flags &= ~HLS_INDEPENDENT_SEGMENTS; -av_log(s, AV_LOG_WARNING, - "'split_by_time' and 'independent_segments' cannot be enabled together. " - "Disabling 'independent_segments' flag\n"); -} - -if (hls->flags & HLS_PROGRAM_DATE_TIME) { -time_t now0; -time(); -vs->initial_prog_date_time = now0; -} - -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); -goto fail; -} -} - -for (j = 0; j < vs->nb_streams; j++) { -vs->has_video += -vs->streams[j]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO; -vs->has_subtitle += -vs->streams[j]->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE; -} - -if (vs->has_video > 1) -av_log(s, AV_LOG_WARNING, - "More than a single video stream present, " - "expect issues decoding it.\n"); - -if (hls->segment_type == SEGMENT_TYPE_FMP4) { -vs->oformat = av_guess_format("mp4", NULL, NULL); -} else { -vs->oformat = av_guess_format("mpegts", NULL, NULL); -} - -if (!vs->oformat) { -ret = AVERROR_MUXER_NOT_FOUND; -goto fail; -} - -if(vs->has_subtitle) { -vs->vtt_oformat = av_guess_format("webvtt", NULL, NULL); -if (!vs->oformat) { -ret = AVERROR_MUXER_NOT_FOUND; -goto fail; -} -} - -if (hls->segment_filename) { -basename_size = strlen(hls->segment_filename) + 1; -if (hls->nb_varstreams > 1) { -basename_size +=