From patchwork Wed Nov 6 02:49:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 16124 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id B3736447DB1 for ; Wed, 6 Nov 2019 04:50:53 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A4A3E68B08F; Wed, 6 Nov 2019 04:50:53 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.50]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id CBBB368B062 for ; Wed, 6 Nov 2019 04:50:50 +0200 (EET) Received: by mail-wm1-f50.google.com with SMTP id a17so488557wmb.0 for ; Tue, 05 Nov 2019 18:50:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=J46CskWB0rdbJiv42B4NYqKSW00gdb8EOF1LpJQA0Bg=; b=vDFZeUBhAYU2l0HYjByMsk5Q+xKXWz0mdkJtO4m44oUZ9XHQsvQxAOojIhQChhXHvA /kujvVGjbs3/LJau90z3BXyLv4cdlUgfTeEeGwSv0xQn/Ys7USFyixPXkaXKBGT6MSJC g7sss92kiJYWUtAs0au9R5SWBkEMmU+TIlHhGRcGUiJbnJANiKpJRfXAC8nY33V1MW8v dxdvfW5njBy24MmsqNccmsx72o/hhosFPOaBPIVbk1+IZiXAtdIbquGu/6pV1jZJIth1 AnAwJrqfh32qc+Pn5+RrOVLeLnaYV4PI7uorKK6v/aRfleFBPfcQnAyPJnnHLRI3KkLT hfDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=J46CskWB0rdbJiv42B4NYqKSW00gdb8EOF1LpJQA0Bg=; b=Ism39a53ZE3tCcuvHok/qSRMlWxWNjb9/i7PcMfSlrdIFW0T12eBRzlvyXxYkvT+0l dTBvxJx7a1IYqCIrgXhLzenXFhupls3SpELikDokW4g7oWFKgvCGZXwKZc2UYRvj6DCU rPpXJbapuGAY3740u0WoHaP15JDieaDpPrqG6XP57Oc5v8EjKe0LM7V6Y0/iVTpZVGjn T1kPeWUNxu0n4Inha2PfngnhAH1B+jI0qv+t0rBngYsJpO5ULJDfW8nYxc860eQ1iKB7 pMfPq1tTrNQ/82EwnEh1JcSwbaGAXutndhPKh0inffh3e6MM4ZY9v0aqPmnUF/UojP8P DbNw== X-Gm-Message-State: APjAAAUPSvqyZ15UPDLSyNc+9NT/LjYiH+s4/GhcCt79vEzHCRSMyvAI UBdgbvlMzW3x3V0ZJmJULBDjGzCX X-Google-Smtp-Source: APXvYqzG32e9BlgUuwW/bKZGjrz/1oRI1R0t63BC9/8TAP877RNMS7kTjCUIK3PRClT3yBsu3c0QDw== X-Received: by 2002:a1c:453:: with SMTP id 80mr320582wme.5.1573008649914; Tue, 05 Nov 2019 18:50:49 -0800 (PST) Received: from sblaptop.fritz.box (ipbcc08937.dynamic.kabel-deutschland.de. [188.192.137.55]) by smtp.gmail.com with ESMTPSA id l13sm1281710wmh.12.2019.11.05.18.50.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Nov 2019 18:50:49 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Wed, 6 Nov 2019 03:49:12 +0100 Message-Id: <20191106024922.19228-13-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191106024922.19228-1-andreas.rheinhardt@gmail.com> References: <20191106024922.19228-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 13/23] avformat/matroskaenc: Improve cues in case of no-video X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" The Matroska muxer currently only adds CuePoints in three cases: a) For video keyframes. b) For the first audio frame in a new cluster if in dash-mode. c) For subtitles. This means that ordinary Matroska audio files won't have any cues which impedes seeking. This commit changes this. For every track in a file without video track it is checked and tracked whether a cue entry has already been added for said track for the current cluster. This is used to add a cue entry for each first packet of each track in each cluster. Implements #3149. Signed-off-by: Andreas Rheinhardt --- libavformat/matroskaenc.c | 21 ++++++++++++--------- tests/ref/fate/aac-autobsf-adtstoasc | 4 ++-- tests/ref/lavf/mka | 4 ++-- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c index dd25172eeb..bc94ed53ae 100644 --- a/libavformat/matroskaenc.c +++ b/libavformat/matroskaenc.c @@ -2138,6 +2138,10 @@ static void mkv_end_cluster(AVFormatContext *s) MatroskaMuxContext *mkv = s->priv_data; end_ebml_master_crc32(s->pb, &mkv->cluster_bc, mkv); + if (!mkv->have_video) { + for (int i = 0; i < s->nb_streams; i++) + mkv->tracks[i].has_cue = 0; + } mkv->cluster_pos = -1; avio_flush(s->pb); } @@ -2250,7 +2254,7 @@ static int mkv_check_new_extra_data(AVFormatContext *s, AVPacket *pkt) return 0; } -static int mkv_write_packet_internal(AVFormatContext *s, AVPacket *pkt, int add_cue) +static int mkv_write_packet_internal(AVFormatContext *s, AVPacket *pkt) { MatroskaMuxContext *mkv = s->priv_data; AVIOContext *pb; @@ -2294,10 +2298,12 @@ static int mkv_write_packet_internal(AVFormatContext *s, AVPacket *pkt, int add_ if (par->codec_type != AVMEDIA_TYPE_SUBTITLE) { mkv_write_block(s, pb, MATROSKA_ID_SIMPLEBLOCK, pkt, keyframe); - if ((s->pb->seekable & AVIO_SEEKABLE_NORMAL) && (par->codec_type == AVMEDIA_TYPE_VIDEO && keyframe || add_cue)) { + if ((s->pb->seekable & AVIO_SEEKABLE_NORMAL) && keyframe && + (par->codec_type == AVMEDIA_TYPE_VIDEO || !mkv->have_video && !track->has_cue)) { ret = mkv_add_cuepoint(mkv->cues, pkt->stream_index, ts, mkv->cluster_pos, relative_packet_pos, -1); if (ret < 0) return ret; + track->has_cue = 1; } } else { if (par->codec_id == AV_CODEC_ID_WEBVTT) { @@ -2364,8 +2370,7 @@ static int mkv_write_packet(AVFormatContext *s, AVPacket *pkt) // on seeing key frames. start_new_cluster = keyframe; } else if (mkv->is_dash && codec_type == AVMEDIA_TYPE_AUDIO && - (mkv->cluster_pos == -1 || - cluster_time > mkv->cluster_time_limit)) { + cluster_time > mkv->cluster_time_limit) { // For DASH audio, we create a Cluster based on cluster_time_limit start_new_cluster = 1; } else if (!mkv->is_dash && @@ -2389,9 +2394,7 @@ static int mkv_write_packet(AVFormatContext *s, AVPacket *pkt) // check if we have an audio packet cached if (mkv->cur_audio_pkt.size > 0) { - // for DASH audio, a CuePoint has to be added when there is a new cluster. - ret = mkv_write_packet_internal(s, &mkv->cur_audio_pkt, - mkv->is_dash ? start_new_cluster : 0); + ret = mkv_write_packet_internal(s, &mkv->cur_audio_pkt); av_packet_unref(&mkv->cur_audio_pkt); if (ret < 0) { av_log(s, AV_LOG_ERROR, @@ -2406,7 +2409,7 @@ static int mkv_write_packet(AVFormatContext *s, AVPacket *pkt) if (pkt->size > 0) ret = av_packet_ref(&mkv->cur_audio_pkt, pkt); } else - ret = mkv_write_packet_internal(s, pkt, 0); + ret = mkv_write_packet_internal(s, pkt); return ret; } @@ -2435,7 +2438,7 @@ static int mkv_write_trailer(AVFormatContext *s) // check if we have an audio packet cached if (mkv->cur_audio_pkt.size > 0) { - ret = mkv_write_packet_internal(s, &mkv->cur_audio_pkt, 0); + ret = mkv_write_packet_internal(s, &mkv->cur_audio_pkt); if (ret < 0) { av_log(s, AV_LOG_ERROR, "Could not write cached audio packet ret:%d\n", ret); diff --git a/tests/ref/fate/aac-autobsf-adtstoasc b/tests/ref/fate/aac-autobsf-adtstoasc index 2f361d678c..adc47bfeb6 100644 --- a/tests/ref/fate/aac-autobsf-adtstoasc +++ b/tests/ref/fate/aac-autobsf-adtstoasc @@ -1,5 +1,5 @@ -3bb278ab6ca22a00c3f14bd00f887332 *tests/data/fate/aac-autobsf-adtstoasc.matroska -6611 tests/data/fate/aac-autobsf-adtstoasc.matroska +8a02d889ba2d238cdd7fe1092c6b82ba *tests/data/fate/aac-autobsf-adtstoasc.matroska +6639 tests/data/fate/aac-autobsf-adtstoasc.matroska #extradata 0: 2, 0x0030001c #tb 0: 1/1000 #media_type 0: audio diff --git a/tests/ref/lavf/mka b/tests/ref/lavf/mka index ede6398ca8..496dc74be6 100644 --- a/tests/ref/lavf/mka +++ b/tests/ref/lavf/mka @@ -1,3 +1,3 @@ -2ad63aec397720fe3e173476bc10c2a1 *tests/data/lavf/lavf.mka -43568 tests/data/lavf/lavf.mka +848c3866224d103aa7d7c1cef0fd13cc *tests/data/lavf/lavf.mka +43596 tests/data/lavf/lavf.mka tests/data/lavf/lavf.mka CRC=0x3a1da17e