[FFmpeg-devel] [PATCH] avformat/hlsenc: Duplicated segment filenames and use_localtime_mkdir
Steven Liu
lingjiujianke at gmail.com
Sun Jan 1 14:24:21 EET 2017
2017-01-01 20:14 GMT+08:00 Bodecs Bela <bodecsb at vivanet.hu>:
>
>
> 2017.01.01. 12:57 keltezéssel, Steven Liu írta:
>
>> 2017-01-01 19:40 GMT+08:00 Bodecs Bela <bodecsb at vivanet.hu>:
>>
>> Dear All,
>>>
>>> current implementation of finding duplicated segment filenames may fail
>>> if
>>> use_localtime_mkdir and use_localtime are in effect and segment_filename
>>> option expression contains subdirectories with date/time specifiers in
>>> them.
>>> This patch fixes this false behaviour.
>>>
>>>
>>> thank you,
>>>
>>> Bela
>>>
>>>
>>> _______________________________________________
>>> ffmpeg-devel mailing list
>>> ffmpeg-devel at ffmpeg.org
>>> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>>>
>>>
>>> +static HLSSegment *find_segment_by_filename(HLSSegment *segment, const
>> char *filename)
>> +{
>> + while (segment) {
>> + if (!strcmp(segment->filename,filename))
>> + return segment;
>> + segment = segment->next;
>> + }
>> + return (HLSSegment *) NULL;
>> +}
>> +
>> use av_strcasecmp will better。
>>
> yes, I have changed it.
>
> _______________________________________________
>> ffmpeg-devel mailing list
>> ffmpeg-devel at ffmpeg.org
>> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>>
>
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> ---
libavformat/hlsenc.c | 50
++++++++++++++------------------------------------
1 file changed, 14 insertions(+), 36 deletions(-)
diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index 57fc9c1..591ab73 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -367,6 +367,16 @@ static int hls_mux_init(AVFormatContext *s)
return 0;
}
+static HLSSegment *find_segment_by_filename(HLSSegment *segment, const
char *filename)
+{
+ while (segment) {
+ if (!av_strcasecmp(segment->filename,filename))
+ return segment;
+ segment = segment->next;
+ }
+ return (HLSSegment *) NULL;
+}
+
/* Create a new segment and append it to the segment list */
static int hls_append_segment(struct AVFormatContext *s, HLSContext *hls,
double duration,
int64_t pos, int64_t size)
@@ -383,6 +393,10 @@ static int hls_append_segment(struct AVFormatContext
*s, HLSContext *hls, double
if (hls->use_localtime_mkdir) {
filename = hls->avf->filename;
}
+ if (find_segment_by_filename(hls->segments, filename)
+ || find_segment_by_filename(hls->old_segments, en->filename)) {
+ av_log(hls, AV_LOG_WARNING, "Duplicated segment filename detected:
%s\n", filename);
+ }
av_strlcpy(en->filename, filename, sizeof(en->filename));
if(hls->has_subtitle)
@@ -659,38 +673,6 @@ fail:
return ret;
}
-static HLSSegment *find_segment_by_filename(HLSSegment *segment, const
char *filename)
-{
- /* filename may contain rel/abs path, but segments store only basename
*/
- char *p = NULL, *dirname = NULL, *path = NULL;
- int path_size;
- HLSSegment *ret_segment = NULL;
- dirname = av_strdup(filename);
- if (!dirname)
- return NULL;
- p = (char *)av_basename(dirname); // av_dirname would return . in case
of no dir
- *p = '\0'; // maybe empty
-
- while (segment) {
- path_size = strlen(dirname) + strlen(segment->filename) + 1;
- path = av_malloc(path_size);
- if (!path)
- goto end;
- av_strlcpy(path, dirname, path_size);
- av_strlcat(path, segment->filename, path_size);
- if (!strcmp(path,filename)) {
- ret_segment = segment;
- av_free(path);
- goto end;
- }
- av_free(path);
- segment = segment->next;
- }
-end:
- av_free(dirname);
- return ret_segment;
-}
-
static int hls_start(AVFormatContext *s)
{
HLSContext *c = s->priv_data;
@@ -736,10 +718,6 @@ static int hls_start(AVFormatContext *s)
}
av_free(filename);
}
- if (find_segment_by_filename(c->segments, oc->filename)
- || find_segment_by_filename(c->old_segments,
oc->filename)) {
- av_log(c, AV_LOG_WARNING, "Duplicated segment filename
detected: %s\n", oc->filename);
- }
if (c->use_localtime_mkdir) {
const char *dir;
char *fn_copy = av_strdup(oc->filename);
--
applied!
Thanks
More information about the ffmpeg-devel
mailing list