#8652 closed defect (fixed)
Segmentation fault with HLS var_stream_map
Reported by: | udyojiar | Owned by: | |
---|---|---|---|
Priority: | important | Component: | avformat |
Version: | git-master | Keywords: | hls crash SIGSEGV |
Cc: | Blocked By: | ||
Blocking: | Reproduced by developer: | no | |
Analyzed by developer: | no |
Description
Summary of the bug:
Hello,
I have one video I'd like to convert it to hls in two profiles with var_stream_map.
At the end of the conversation FFmpeg dies with segmentation fault.
The result is the same with ffmpeg-4.2.2 and ffmpeg-snapshot.
How to reproduce:
% ffmpeg -hwaccel vaapi -hwaccel_device /dev/dri/renderD128 -hwaccel_output_format vaapi \ -i FPS_test_1080p25_L4.1.mkv \ -filter_complex 'split[cq][cb]' \ -map '[cq]' -c:v h264_vaapi -qp 18 -map \ '[cb]' -c:v h264_vaapi -b:v 5M -maxrate 5M \ -f hls -var_stream_map "v:0_v:1" \ -master_pl_name playlist.m3u8 -master_pl_publish_rate 5 \ -use_localtime 1 -hls_segment_type mpegts -hls_time 10 \ -hls_list_size 6 -hls_flags delete_segments \ -hls_segment_filename "/dev/shm/abr/503/%v/%s.bin" \ "/dev/shm/abr/503/%v/playlist.m3u8" ffmpeg version N-97605-g422f1e3 Copyright (c) 2000-2020 the FFmpeg developers built with gcc 8 (GCC) configuration: --prefix=/home/ico/ffmpeg_build --pkg-config-flags=--static --extra-cflags=-I/home/ico/ffmpeg_build/include --extra-ldflags=-L/home/ico/ffmpeg_build/lib --extra-libs=-lpthread --extra-libs=-lm --bindir=/home/ico/bin --enable-gpl --enable-libfdk_aac --enable-libx264 --enable-vaapi --enable-nonfree libavutil 56. 43.100 / 56. 43.100 libavcodec 58. 82.100 / 58. 82.100 libavformat 58. 42.102 / 58. 42.102 libavdevice 58. 9.103 / 58. 9.103 libavfilter 7. 80.100 / 7. 80.100 libswscale 5. 6.101 / 5. 6.101 libswresample 3. 6.100 / 3. 6.100 libpostproc 55. 6.100 / 55. 6.100 Input #0, matroska,webm, from 'FPS_test_1080p25_L4.1.mkv': Metadata: encoder : libebml v1.3.0 + libmatroska v1.4.1 creation_time : 2014-09-18T20:01:03.000000Z Duration: 00:10:05.04, start: 0.000000, bitrate: 218 kb/s Stream #0:0(eng): Video: h264 (High), yuv420p(tv, bt709, progressive), 1920x1080 [SAR 1:1 DAR 16:9], 25 fps, 25 tbr, 1k tbn, 50 tbc (default) Metadata: BPS : 216733 BPS-eng : 216733 DURATION : 00:10:05.040000000 DURATION-eng : 00:10:05.040000000 NUMBER_OF_FRAMES: 15126 NUMBER_OF_FRAMES-eng: 15126 NUMBER_OF_BYTES : 16391549 NUMBER_OF_BYTES-eng: 16391549 _STATISTICS_WRITING_APP: mkvmerge v7.2.0 ('On Every Street') 32bit built on Sep 13 2014 15:42:11 _STATISTICS_WRITING_APP-eng: mkvmerge v7.2.0 ('On Every Street') 32bit built on Sep 13 2014 15:42:11 _STATISTICS_WRITING_DATE_UTC: 2014-09-18 20:01:03 _STATISTICS_WRITING_DATE_UTC-eng: 2014-09-18 20:01:03 _STATISTICS_TAGS: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES _STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES Stream #0:1(eng): Audio: mp3, 48000 Hz, stereo, fltp, 44 kb/s (default) Metadata: BPS : 34181 BPS-eng : 34181 DURATION : 00:00:01.056000000 DURATION-eng : 00:00:01.056000000 NUMBER_OF_FRAMES: 44 NUMBER_OF_FRAMES-eng: 44 NUMBER_OF_BYTES : 4512 NUMBER_OF_BYTES-eng: 4512 _STATISTICS_WRITING_APP: mkvmerge v7.2.0 ('On Every Street') 32bit built on Sep 13 2014 15:42:11 _STATISTICS_WRITING_APP-eng: mkvmerge v7.2.0 ('On Every Street') 32bit built on Sep 13 2014 15:42:11 _STATISTICS_WRITING_DATE_UTC: 2014-09-18 20:01:03 _STATISTICS_WRITING_DATE_UTC-eng: 2014-09-18 20:01:03 _STATISTICS_TAGS: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES _STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES Multiple -c, -codec, -acodec, -vcodec, -scodec or -dcodec options specified for stream 0, only the last option '-c:v h264_vaapi' will be used. Multiple -c, -codec, -acodec, -vcodec, -scodec or -dcodec options specified for stream 1, only the last option '-c:v h264_vaapi' will be used. failed to open /usr/lib64/dri/hybrid_drv_video.so Not using hybrid_drv_video.so Stream mapping: Stream #0:0 (h264) -> split split:output0 -> Stream #0:0 (h264_vaapi) split:output1 -> Stream #0:1 (h264_vaapi) Press [q] to stop, [?] for help Segmentation fault (core dumped)
Patches should be submitted to the ffmpeg-devel mailing list and not this bug tracker.
Change History (8)
comment:1 by , 4 years ago
comment:2 by , 4 years ago
Priority: | normal → important |
---|
Is a specific input file needed to reproduce?
comment:3 by , 4 years ago
I think that any input file will do. The file in example is from kodi samples "4. H.264 1080p/25.000 (MKV)" https://drive.google.com/file/d/0BwxFVkl63-lEWDUzUVUtZEw4cDA/view. At first I've tried with mpeg-ts input stream with the same result.
comment:4 by , 4 years ago
Please test this patch:
From 1ec665efd699a5915d5b2028c5971176e3b6c1bd Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> Date: Tue, 5 May 2020 00:40:44 +0200 Subject: [PATCH] avformat/hlsenc: Improve checks for invalid stream mappings The mapping of streams to the various variant streams to be created by the HLS muxer is roughly as follows: Space and tab separate variant stream group maps while the entries in each variant stream group map are separated by ','. The parsing process of each variant stream group proceeded as follows: At first the number of occurences of "a:", "v:" and "s:" in each variant stream group is calculated so that one can can allocate an array of streams with this number of entries. Then each entry is checked and the check for stream numbers was deficient: It did check that there is a number beginning after the ":", but it did not check that the number extends until the next "," (or until the end). This means that an invalid variant stream group like v:0_v:1 will not be rejected; the problem is that the variant stream in this example is supposed to have two streams associated with it (because it contains two "v:"), yet only one stream is actually associated with it (because there is no ',' to start a second stream specifier). This discrepancy led to segfaults (null pointer dereferencing) in the rest of the code (when the nonexistent second stream associated to the variant stream was involved. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> --- libavformat/hlsenc.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c index 008a3f3947..843b906203 100644 --- a/libavformat/hlsenc.c +++ b/libavformat/hlsenc.c @@ -1867,7 +1867,7 @@ fail: static int get_nth_codec_stream_index(AVFormatContext *s, enum AVMediaType codec_type, - int stream_id) + int64_t stream_id) { unsigned int stream_index, cnt; if (stream_id < 0 || stream_id > s->nb_streams - 1) @@ -1950,6 +1950,8 @@ static int parse_variant_stream_mapstring(AVFormatContext *s) nb_streams = 0; while (keyval = av_strtok(varstr, ",", &saveptr2)) { + int64_t num; + char *end; varstr = NULL; if (av_strstart(keyval, "language:", &val)) { av_free(vs->language); @@ -1998,10 +2000,12 @@ static int parse_variant_stream_mapstring(AVFormatContext *s) return AVERROR(EINVAL); } - stream_index = -1; - if (av_isdigit(*val)) - stream_index = get_nth_codec_stream_index (s, codec_type, - atoi(val)); + num = strtoll(val, &end, 10); + if (!av_isdigit(*val) || *end != '\0' || val == end) { + av_log(s, AV_LOG_ERROR, "Invalid stream number: '%s'\n", val); + return AVERROR(EINVAL); + } + stream_index = get_nth_codec_stream_index(s, codec_type, num); if (stream_index >= 0 && nb_streams < vs->nb_streams) { for (i = 0; nb_streams > 0 && i < nb_streams; i++) { -- 2.20.1
comment:5 by , 4 years ago
The suggested patch is improvement. No Segmentation fault with patch applied.
The result now is:
Press [q] to stop, [?] for help [hls @ 0x3cc7600] Invalid stream number: '0_v:1' [hls @ 0x3cc7600] Variant stream info update failed with status ffffffea Could not write header for output file #0 (incorrect codec parameters ?): Invalid argument Error initializing output stream 0:1 -- Conversion failed!
comment:6 by , 4 years ago
And that's what you deserve as you use an invalid format (the entries of a variant stream group are separated by ',', not '_'.). You probably wanted to use "v:0,v:1". What makes you believe that you used a valid format?
comment:7 by , 4 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Fixed in c801ab43c36e8c4f88121aa09af26c77bcbd671b.
Here is the output of "gdb path/to/ffmpeg(_g)" ... "bt full"