[FFmpeg-devel,12/23] avformat/matroskaenc: Add check for using explicit track number

Submitted by Andreas Rheinhardt on Nov. 6, 2019, 2:49 a.m.

Details

Message ID 20191106024922.19228-12-andreas.rheinhardt@gmail.com
State New
Headers show

Commit Message

Andreas Rheinhardt Nov. 6, 2019, 2:49 a.m.
When creating dash streams, the track number is externally prescribed
and not derived from the number of streams in the AVFormatContext. Up
until now, a track number of zero was allowed, although this is an
illegal track number.
Furthermore, it was not checked whether the number of tracks for a file
using an explicit track number was more than one, as such a file would
be invalid (it would be impossible to tell to which track a block belongs
if different tracks share the same track number).
Besides that, use the macro MAX_TRACKS macro for the maximum of
dash_track_number.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
 libavformat/matroskaenc.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Patch hide | download patch | download mbox

diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index aacd602221..dd25172eeb 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -2649,6 +2649,9 @@  static int mkv_init(struct AVFormatContext *s)
         track->track_num = mkv->is_dash ? mkv->dash_track_number : nb_tracks;
     }
 
+    if (mkv->is_dash && nb_tracks != 1)
+        return AVERROR(EINVAL);
+
     if (nb_tracks > MAX_TRACKS) {
         av_log(s, AV_LOG_ERROR,
                "%d > "AV_STRINGIFY(MAX_TRACKS)" tracks (excluding attachments)"
@@ -2711,7 +2714,7 @@  static const AVOption options[] = {
     { "cluster_size_limit",  "Store at most the provided amount of bytes in a cluster. ",                                     OFFSET(cluster_size_limit), AV_OPT_TYPE_INT  , { .i64 = -1 }, -1, INT_MAX,   FLAGS },
     { "cluster_time_limit",  "Store at most the provided number of milliseconds in a cluster.",                               OFFSET(cluster_time_limit), AV_OPT_TYPE_INT64, { .i64 = -1 }, -1, INT64_MAX, FLAGS },
     { "dash", "Create a WebM file conforming to WebM DASH specification", OFFSET(is_dash), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, FLAGS },
-    { "dash_track_number", "Track number for the DASH stream", OFFSET(dash_track_number), AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 127, FLAGS },
+    { "dash_track_number", "Track number for the DASH stream", OFFSET(dash_track_number), AV_OPT_TYPE_INT, { .i64 = 1 }, 1, MAX_TRACKS, FLAGS },
     { "live", "Write files assuming it is a live stream.", OFFSET(is_live), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, FLAGS },
     { "allow_raw_vfw", "allow RAW VFW mode", OFFSET(allow_raw_vfw), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, FLAGS },
     { "write_crc32", "write a CRC32 element inside every Level 1 element", OFFSET(write_crc), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1, FLAGS },