X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavformat%2Fsegment.c;h=7fb4dc7d2124c72d8abeaafff88d2370c877e1e9;hb=c1c720d5279aa2e8e0518e2900f5f2b267ee974a;hp=81d3f1d9408bca62ceeb00e91f5be84baa43b36d;hpb=96cf0d8a9cf35f3c49860bf1c000c382dd661607;p=ffmpeg diff --git a/libavformat/segment.c b/libavformat/segment.c index 81d3f1d9408..7fb4dc7d212 100644 --- a/libavformat/segment.c +++ b/libavformat/segment.c @@ -192,6 +192,8 @@ static int set_segment_filename(AVFormatContext *s) AVFormatContext *oc = seg->avf; size_t size; int ret; + char buf[1024]; + char *new_name; if (seg->segment_idx_wrap) seg->segment_idx %= seg->segment_idx_wrap; @@ -200,18 +202,22 @@ static int set_segment_filename(AVFormatContext *s) struct tm *tm, tmpbuf; time(&now0); tm = localtime_r(&now0, &tmpbuf); - if (!strftime(oc->filename, sizeof(oc->filename), s->filename, tm)) { + if (!strftime(buf, sizeof(buf), s->url, tm)) { av_log(oc, AV_LOG_ERROR, "Could not get segment filename with strftime\n"); return AVERROR(EINVAL); } - } else if (av_get_frame_filename(oc->filename, sizeof(oc->filename), - s->filename, seg->segment_idx) < 0) { - av_log(oc, AV_LOG_ERROR, "Invalid segment filename template '%s'\n", s->filename); + } else if (av_get_frame_filename(buf, sizeof(buf), + s->url, seg->segment_idx) < 0) { + av_log(oc, AV_LOG_ERROR, "Invalid segment filename template '%s'\n", s->url); return AVERROR(EINVAL); } + new_name = av_strdup(buf); + if (!new_name) + return AVERROR(ENOMEM); + ff_format_set_url(oc, new_name); /* copy modified name in list entry */ - size = strlen(av_basename(oc->filename)) + 1; + size = strlen(av_basename(oc->url)) + 1; if (seg->entry_prefix) size += strlen(seg->entry_prefix); @@ -219,7 +225,7 @@ static int set_segment_filename(AVFormatContext *s) return ret; snprintf(seg->cur_entry.filename, size, "%s%s", seg->entry_prefix ? seg->entry_prefix : "", - av_basename(oc->filename)); + av_basename(oc->url)); return 0; } @@ -245,8 +251,8 @@ static int segment_start(AVFormatContext *s, int write_header) if ((err = set_segment_filename(s)) < 0) return err; - if ((err = s->io_open(s, &oc->pb, oc->filename, AVIO_FLAG_WRITE, NULL)) < 0) { - av_log(s, AV_LOG_ERROR, "Failed to open segment '%s'\n", oc->filename); + if ((err = s->io_open(s, &oc->pb, oc->url, AVIO_FLAG_WRITE, NULL)) < 0) { + av_log(s, AV_LOG_ERROR, "Failed to open segment '%s'\n", oc->url); return err; } if (!seg->individual_header_trailer) @@ -360,7 +366,7 @@ static int segment_end(AVFormatContext *s, int write_trailer, int is_last) if (ret < 0) av_log(s, AV_LOG_ERROR, "Failure occurred when ending segment '%s'\n", - oc->filename); + oc->url); if (seg->list) { if (seg->list_size || seg->list_type == LIST_TYPE_M3U8) { @@ -403,7 +409,7 @@ static int segment_end(AVFormatContext *s, int write_trailer, int is_last) } av_log(s, AV_LOG_VERBOSE, "segment:'%s' count:%d ended\n", - seg->avf->filename, seg->segment_count); + seg->avf->url, seg->segment_count); seg->segment_count++; if (seg->increment_tc) { @@ -726,7 +732,7 @@ static int seg_init(AVFormatContext *s) seg->reference_stream_index, av_get_media_type_string(s->streams[seg->reference_stream_index]->codecpar->codec_type)); - seg->oformat = av_guess_format(seg->format, s->filename, NULL); + seg->oformat = av_guess_format(seg->format, s->url, NULL); if (!seg->oformat) return AVERROR_MUXER_NOT_FOUND; @@ -745,9 +751,9 @@ static int seg_init(AVFormatContext *s) if (seg->write_header_trailer) { if ((ret = s->io_open(s, &oc->pb, - seg->header_filename ? seg->header_filename : oc->filename, + seg->header_filename ? seg->header_filename : oc->url, AVIO_FLAG_WRITE, NULL)) < 0) { - av_log(s, AV_LOG_ERROR, "Failed to open segment '%s'\n", oc->filename); + av_log(s, AV_LOG_ERROR, "Failed to open segment '%s'\n", oc->url); return ret; } if (!seg->individual_header_trailer) @@ -830,7 +836,7 @@ static int seg_write_header(AVFormatContext *s) } else { close_null_ctxp(&oc->pb); } - if ((ret = oc->io_open(oc, &oc->pb, oc->filename, AVIO_FLAG_WRITE, NULL)) < 0) + if ((ret = oc->io_open(oc, &oc->pb, oc->url, AVIO_FLAG_WRITE, NULL)) < 0) return ret; if (!seg->individual_header_trailer) oc->pb->seekable = 0; @@ -917,7 +923,7 @@ calc_times: if (seg->segment_frame_count == 0) { av_log(s, AV_LOG_VERBOSE, "segment:'%s' starts with packet stream:%d pts:%s pts_time:%s frame:%d\n", - seg->avf->filename, pkt->stream_index, + seg->avf->url, pkt->stream_index, av_ts2str(pkt->pts), av_ts2timestr(pkt->pts, &st->time_base), seg->frame_count); } @@ -1058,6 +1064,7 @@ static const AVOption options[] = { { NULL }, }; +#if CONFIG_SEGMENT_MUXER static const AVClass seg_class = { .class_name = "segment muxer", .item_name = av_default_item_name, @@ -1078,7 +1085,9 @@ AVOutputFormat ff_segment_muxer = { .check_bitstream = seg_check_bitstream, .priv_class = &seg_class, }; +#endif +#if CONFIG_STREAM_SEGMENT_MUXER static const AVClass sseg_class = { .class_name = "stream_segment muxer", .item_name = av_default_item_name, @@ -1099,3 +1108,4 @@ AVOutputFormat ff_stream_segment_muxer = { .check_bitstream = seg_check_bitstream, .priv_class = &sseg_class, }; +#endif