From patchwork Thu Nov 15 04:27:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 11031 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 EC4DE44C963 for ; Thu, 15 Nov 2018 06:27:48 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C54B9689A8E; Thu, 15 Nov 2018 06:27:10 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qk1-f196.google.com (mail-qk1-f196.google.com [209.85.222.196]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5A55C680A1F for ; Thu, 15 Nov 2018 06:27:04 +0200 (EET) Received: by mail-qk1-f196.google.com with SMTP id q70so12393677qkh.6 for ; Wed, 14 Nov 2018 20:27:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=vcWvYWCUWYETOKduYkXhgtFhMXNG625ISOssi/3EsKo=; b=Tu+G2BjIfDFi6h4gLlOASgIf+MNw3twupdOCEeKm8WH5OK/fyAX7uZiNVrchaEBy0X NZID7AHCb8vx040xiGv6ap0gM1HPOb14IyDyQl/Ap3angNZaHOgserhhGDl6L/yhNNPr mLnHjB23NuRm1R3OeWa1A7eGopwzHBtbyBNvl7zqvpu21uO36r/1GziSOd6NDCLBK+4n dJYRt0DZ/9MxqhOrMasBxZI1OlpqVi6XWgYxbpkPyZDYPJmBIinZCN8MXuN67qmneocM PncuB86q+DO4Rn31+xbeRysY4UCgcfuh5ve15wvJXVVKcrhdHOgoENqWdMUl/PknSu7F kshQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=vcWvYWCUWYETOKduYkXhgtFhMXNG625ISOssi/3EsKo=; b=HKXu1XTI+vzZnoGmeLsMvJntSlOVedi7h+Y437k+ZPAnlhzEIOCRGdUkYrjNw5U8Tk GDZfpgwvheXnR86b+GGw8+vPgTL4+GzYQGW6Nh+TO/i9kvhgz2qHhZI7EpFqbdSzDBeZ bRv0dPEzK7+SiBczW/GAwQBu5UCUuPlIO6bg6L6Sol1LnROD5/M/f7k5TLkxRTrzwifZ PXnAq3QHpVQxg5ehkZSqCbkzgZxa7ym28Ml4Q18fndWJo6aTx0zAePUC/GsULMLf4mda wAdVbSX9jw9+aed7Z5IkDsgS4A3Wyxa1i7Enkf9gyz76Qf2y7JCILkNn7lzmhg4NoaRA jVLQ== X-Gm-Message-State: AGRZ1gI9KSwXKVw7QHN+iBuRC35M+oWmUL/gnxv3bDlEVXyoE/8+jmA9 m5dgphEISbM7L+Kp4T6FYUKgQ4zX X-Google-Smtp-Source: AJdET5crbEf2hjsOtb4sb93h82Ysd8HK4vl2Pr21Q3/sN1SvgjHgAVf0qzyRTKt3M8mvPzUtvsM3MQ== X-Received: by 2002:a0c:9359:: with SMTP id e25mr4677995qve.203.1542256061133; Wed, 14 Nov 2018 20:27:41 -0800 (PST) Received: from localhost.localdomain ([179.38.149.118]) by smtp.gmail.com with ESMTPSA id 49sm9107290qtz.55.2018.11.14.20.27.39 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Nov 2018 20:27:40 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Thu, 15 Nov 2018 01:27:12 -0300 Message-Id: <20181115042712.9132-1-jamrial@gmail.com> X-Mailer: git-send-email 2.19.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avcodec/cbs_av1: don't abort when splitting Temporal Units containing OBUs with no obu_size field 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" The ISOBMFF and Matroska specs allow the last OBU in a Sample/Block to have obu_has_size_field equal to 0. Signed-off-by: James Almer --- See https://0x0.st/sUsU.mp4 It apparently can't be decoded with either aom or dav1d atm, but the latter should be able to soon. You can try remuxing it using the av1_metadata bsf after this patch while at it, since the code to write obu_size fields unconditionally is still in place, and that should make it decodable with either library. For some reason cbs_av1_read_unit() is already able to handle OBUs with no obu_size field. It was only cbs_av1_split_fragment() bailing out with them. libavcodec/cbs_av1.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/libavcodec/cbs_av1.c b/libavcodec/cbs_av1.c index ed5211be19..e02bc7027a 100644 --- a/libavcodec/cbs_av1.c +++ b/libavcodec/cbs_av1.c @@ -788,13 +788,6 @@ static int cbs_av1_split_fragment(CodedBitstreamContext *ctx, if (err < 0) goto fail; - if (!header.obu_has_size_field) { - av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid OBU for raw " - "stream: size field must be present.\n"); - err = AVERROR_INVALIDDATA; - goto fail; - } - if (get_bits_left(&gbc) < 8) { av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid OBU: fragment " "too short (%zu bytes).\n", size); @@ -802,9 +795,12 @@ static int cbs_av1_split_fragment(CodedBitstreamContext *ctx, goto fail; } - err = cbs_av1_read_leb128(ctx, &gbc, "obu_size", &obu_size); - if (err < 0) - goto fail; + if (header.obu_has_size_field) { + err = cbs_av1_read_leb128(ctx, &gbc, "obu_size", &obu_size); + if (err < 0) + goto fail; + } else + obu_size = size - 1 - header.obu_extension_flag; pos = get_bits_count(&gbc); av_assert0(pos % 8 == 0 && pos / 8 <= size);