From patchwork Tue Sep 10 14:06:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: martin schitter X-Patchwork-Id: 51491 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:612c:41b1:b0:48e:c0f8:d0de with SMTP id le49csp374370vqb; Tue, 10 Sep 2024 05:34:12 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWWnNUQpgxzaS/czcKeG0vH/f+7XlPlAYCcjRfKeWLoAEcSvoqRpD1DQ7EgPpkg/9ByyP1aq2y86xONO2V+pzyz@gmail.com X-Google-Smtp-Source: AGHT+IGAY4dB1aMC8mnc/KejBzyFZg8paJJEGjqNiW+r/D4FDxzD3T298Mm5kTmprTroK1NVrMct X-Received: by 2002:a17:907:7f16:b0:a8a:9054:8394 with SMTP id a640c23a62f3a-a8ffa866000mr65213866b.0.1725971651931; Tue, 10 Sep 2024 05:34:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1725971651; cv=none; d=google.com; s=arc-20240605; b=NVk3gBeUQKwpLYDjUFWshx3iDNJDTOtrkfxMJyJEaO4bA0BxCVJNXOi4qRKm6O0rRC YKsy9OvZ0tK1iaELyZU2IJ8GqLzSi//6QNRD09nWKe66Cfgverxg2Nx3dts8M/R1LKx+ Tq4z+NK//EqfXw4LonAlaPAWqoProXJi5vdu9GS87y0hOUlZDXJ7XAvxVv+TyBf9Wbmj FBAbADYo+absB4oEWbhIdv/pv4fxYu03OAFuD2B+ZyqAl1D2xnSqHzXPJ3miEX+ymvhj 5H/3W65orR7A1TPlTno2gavVd2wxkjEvPmULiHS0XJHsQQxBxUYXkrYlASQJ2HqKbBNG Z1Lw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:message-id:date:to:from :dkim-signature:delivered-to; bh=JMQR4pGtvbhJQUPIRPiba8gSXarxzpG3HgmAWizQdbc=; fh=igg3JDwkSkAbPTwY6V0OsEq0RUkG4DKWC8fVJg4GhMY=; b=BntZMQ50M06iiIjRSMWYhqF0+ejOH6anEwLC92K7YZ+p9Kr3uk/JuQfm6rDX8eKhg9 9ppxJ30LnCAw4Bq1Cw2HOL2TUPHF4XD0M9omG+NczRByJiZrnOPg2XP5UKD+2OWR3uqS x8/Exh75A5KpxBdURrf70Pss+7Nbybbkx+6RYzsdREl0qoI/09tde2+/vsMyjlx2gpkx 5TVduJyz1dYFAnOAyWpWGFfnVild8nCwzetXh/vin0gERC3S0iuBnlgI7m+lFn9N+kte CDzozRT7sITN9NElooMAQdrB7WfUrQsck4obbTD21y3EFoDgeU8Fxp02QQjCafE2Q/k9 wueA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@mur.at header.s=dkim2 header.b=g5E9Tj1F; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mur.at Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id a640c23a62f3a-a8d25856f80si512676766b.149.2024.09.10.05.34.11; Tue, 10 Sep 2024 05:34:11 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@mur.at header.s=dkim2 header.b=g5E9Tj1F; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mur.at Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id F2E0068DFCB; Tue, 10 Sep 2024 15:08:33 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from efeu.mur.at (efeu.mur.at [89.106.208.42]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 02C3568DDC1 for ; Tue, 10 Sep 2024 15:08:26 +0300 (EEST) Received: from localhost.localdomain (lan1.raspi.ma39.ffgraz.net [10.12.1.243]) by efeu.mur.at (Postfix) with ESMTPSA id 9320C45E50; Tue, 10 Sep 2024 14:08:26 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=mur.at; s=dkim2; t=1725970106; bh=Lp1QBkNuk97swOBP462mc2TOEaQ7RMVfaNt9mKVLsJs=; h=From:To:Cc:Subject:Date:From; b=g5E9Tj1F/vLBJAyHxWM4IBdxc/R5B3ZpFfARlQdzY0k333EZpjBglM45vTaiuN7z1 WOdbk1bdLMQd8yviIsd1yW9EDvOANEYuoskU+dwQ6h+luAXun7/0ifNyNWlalpennx Bvm2NtH1cuuu0bsNBoUmWgCxrE1Lmfli5hA860vTDDAOEK3pLGFGFMPcI43iDOnita P8lEgGBEm2yUp6adM+WB5FgR0oR/0aAw6dky/SLiTB1c5deolljx+qGyynkDsoRAy8 fTLZZVOyh3QWAMTfTWmoTT0b0Ul4KHtp7QyYbxIWnNK+bAaDOsm9uA67Ua7eKffgut GWpZ/4VKNB6qo4XrU57oxcKHS72cvVr1Ont1j68Ccepwy/PmFd5a1XvEbLvH/frhTr hLSAq8mOmNECASM6LY7ecRk4P35hxED1Z9IaYbV7/u9Yr629B2W2sBHcTlkAP2ULUQ Q/Vw7s3XkBowmq/6Dzi3yzQ211X25AFelzFAA3nP3bhEyk7ofDU From: Martin Schitter To: ffmpeg-devel@ffmpeg.org Date: Tue, 10 Sep 2024 16:06:01 +0200 Message-ID: <20240910140603.741345-3-ms+git@mur.at> X-Mailer: git-send-email 2.45.2 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v4 1/4] libavcodec/dnxuc_parser: DNxUncompressed essence parser X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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: Martin Schitter Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: ynJVz9YYLjby --- libavcodec/dnxuc_parser.c | 124 ++++++++++++++++++++++++++++++++++++++ libavcodec/parsers.c | 1 + 2 files changed, 125 insertions(+) create mode 100644 libavcodec/dnxuc_parser.c diff --git a/libavcodec/dnxuc_parser.c b/libavcodec/dnxuc_parser.c new file mode 100644 index 0000000..55d5763 --- /dev/null +++ b/libavcodec/dnxuc_parser.c @@ -0,0 +1,124 @@ +/* + * Avid DNxUncomressed / SMPTE RDD 50 parser + * Copyright (c) 2024 Martin Schitter + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/* + This parser for DNxUncompressed video data is mostly based on + reverse engineering of output generated by DaVinci Resolve 19 + but was later also checked against the SMPTE RDD 50 specification. + + Limitations: Multiple image planes are not supported. +*/ + +#include "avcodec.h" +#include "libavutil/intreadwrite.h" + +typedef struct DNxUcParseContext { + uint32_t fourcc_tag; + uint32_t width; + uint32_t height; + uint32_t nr_bytes; +} DNxUcParseContext; + +/* +DNxUncompressed frame data comes wrapped in nested boxes of metadata +(box structure: len + fourcc marker + data): + +[0-4] len of outer essence unit box (typically 37 bytes of header + frame data) +[4-7] fourcc 'pack' + +[8-11] len of "signal info box" (always 21) +[12-15] fourcc 'sinf' +[16-19] frame width / line packing size +[20-23] frame hight / nr of lines +[24-27] fourcc pixel format indicator +[28] frame_layout (0: progressive, 1: interlaced) + +[29-32] len of "signal data box" (nr of frame data bytes + 8) +[33-36] fourcc 'sdat' +[37-..] frame data + +A sequence of 'signal info'+'signal data' box pairs wrapped in +'icmp'(=image component) boxes can be utilized to compose more +complex multi plane images. +This feature is only partially supported in the present implementation. +We never pick more than the first pair of info and image data enclosed +in this way. +*/ + +static int dnxuc_parse(AVCodecParserContext *s, + AVCodecContext *avctx, + const uint8_t **poutbuf, int *poutbuf_size, + const uint8_t *buf, int buf_size) +{ + char fourcc_buf[5]; + const int HEADER_SIZE = 37; + int icmp_offset = 0; + + DNxUcParseContext *pc; + pc = (DNxUcParseContext *) s->priv_data; + + if (!buf_size) { + return 0; + } + if (buf_size > 16 && MKTAG('i','c','m','p') == AV_RL32(buf+12)){ + icmp_offset += 8; + } + if ( buf_size < 37 + icmp_offset /* check metadata structure expectations */ + || MKTAG('p','a','c','k') != AV_RL32(buf+4+icmp_offset) + || MKTAG('s','i','n','f') != AV_RL32(buf+12+icmp_offset) + || MKTAG('s','d','a','t') != AV_RL32(buf+33+icmp_offset)){ + av_log(avctx, AV_LOG_ERROR, "can't read DNxUncompressed metadata.\n"); + *poutbuf_size = 0; + return buf_size; + } + + pc->fourcc_tag = AV_RL32(buf+24+icmp_offset); + pc->width = AV_RL32(buf+16+icmp_offset); + pc->height = AV_RL32(buf+20+icmp_offset); + pc->nr_bytes = AV_RL32(buf+29+icmp_offset) - 8; + + if (!avctx->codec_tag) { + av_fourcc_make_string(fourcc_buf, pc->fourcc_tag); + av_log(avctx, AV_LOG_INFO, "dnxuc_parser: '%s' %dx%d %dbpp %d\n", + fourcc_buf, + pc->width, pc->height, + (pc->nr_bytes*8)/(pc->width*pc->height), + pc->nr_bytes); + avctx->codec_tag = pc->fourcc_tag; + } + + if (pc->nr_bytes > buf_size - HEADER_SIZE + icmp_offset){ + av_log(avctx, AV_LOG_ERROR, "Insufficient size of image essence data.\n"); + *poutbuf_size = 0; + return buf_size; + } + + *poutbuf = buf + HEADER_SIZE + icmp_offset; + *poutbuf_size = pc->nr_bytes; + + return buf_size; +} + +const AVCodecParser ff_dnxuc_parser = { + .codec_ids = { AV_CODEC_ID_DNXUC }, + .priv_data_size = sizeof(DNxUcParseContext), + .parser_parse = dnxuc_parse, +}; diff --git a/libavcodec/parsers.c b/libavcodec/parsers.c index 5128009..8bfd2db 100644 --- a/libavcodec/parsers.c +++ b/libavcodec/parsers.c @@ -35,6 +35,7 @@ extern const AVCodecParser ff_cri_parser; extern const AVCodecParser ff_dca_parser; extern const AVCodecParser ff_dirac_parser; extern const AVCodecParser ff_dnxhd_parser; +extern const AVCodecParser ff_dnxuc_parser; extern const AVCodecParser ff_dolby_e_parser; extern const AVCodecParser ff_dpx_parser; extern const AVCodecParser ff_dvaudio_parser; From patchwork Tue Sep 10 14:06:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: martin schitter X-Patchwork-Id: 51490 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:612c:41b1:b0:48e:c0f8:d0de with SMTP id le49csp374369vqb; Tue, 10 Sep 2024 05:34:12 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWfZB2EpAmnFzx0b0Lvid4dhehAuT4WdOfuFiJenHv1axWGAHzGqDcrYj5LlW37536BH8VEt5kSS0mw8Evd8Jtg@gmail.com X-Google-Smtp-Source: AGHT+IGhi6+s37JSrdle++g0cGJlyVvM+1xVEXUvW2fjwf0uq3eewGm6pycFbv8MECfEACnYRmN8 X-Received: by 2002:a17:907:72d4:b0:a8a:9054:83af with SMTP id a640c23a62f3a-a8ffade15famr32564566b.10.1725971651811; Tue, 10 Sep 2024 05:34:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1725971651; cv=none; d=google.com; s=arc-20240605; b=aSq4PjTu287puFRaNMrohsW9U39x6FEyEXYtIaWk3dd6psQ/RLM+TQpZMAZLPvkJ6u F0fKb7dYi+yQXmwZ2VW2Sx17f3ARYjvvI6J5dKE3jommS3u34k0ej++BYoOb60yniY1E WRUlc1bH43TaUjli9BpyxGTUBP3A+rg+3MIQvLUFMXz4nrXHcpCytgP8WfZNqII6NGAJ ZAQF6H01/nwlGVwFVbrBxBhoqzlRnj9NR0+bTki3f5XJxNpALs4h1e0TWjN2J5Xr8ICb 6C81McyrwBql+M2L+i7wCDavkIIkXWO0ufes3qDT7sQDxfWj38FTLw9ap2JVLupEBMXR eyFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=+3NlTemKMitE8KKMkOOsWSf971CNwBis3GMgjMFkIus=; fh=igg3JDwkSkAbPTwY6V0OsEq0RUkG4DKWC8fVJg4GhMY=; b=Mt/sHBkDF6P2QNTD53I3DLVgxFawDKi2Tvff0j1i+uzDFMNAEbXE0r6VxFS5+KGK05 E5YmgDBKE7XeWWxtiZdGdLvP9S9fo+Eq75NI9Y35sy4OXvO0/fgY2XUvgHslU2OjuncO RX2zOmIZLAp+lFQwCildMe05S9gsIJ3JwSz+TFhSRxH5cqGRA/DFilR4gglmgPS78rRq 5EyiAE+xO6JxA2KQqS158sh33W4ZiptiWIp1kGLr+vlvWclX2xRGK3+Gqsbasjfnuao5 ghSK+wqCIiQit+XLLCwdS93TuIeoSHeA9Z+OK7lcjSMo6J+cs5FZiwmb/uGqLhTc0xlx md1Q==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@mur.at header.s=dkim2 header.b=JX6xj2ab; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mur.at Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id a640c23a62f3a-a8d25c60a91si562663766b.401.2024.09.10.05.34.11; Tue, 10 Sep 2024 05:34:11 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@mur.at header.s=dkim2 header.b=JX6xj2ab; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mur.at Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id F1C5668DFA7; Tue, 10 Sep 2024 15:08:34 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from efeu.mur.at (efeu.mur.at [89.106.208.42]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 11DD568DDDF for ; Tue, 10 Sep 2024 15:08:27 +0300 (EEST) Received: from localhost.localdomain (lan1.raspi.ma39.ffgraz.net [10.12.1.243]) by efeu.mur.at (Postfix) with ESMTPSA id AF334461F1; Tue, 10 Sep 2024 14:08:26 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=mur.at; s=dkim2; t=1725970106; bh=WPVWQZ6cku9EMGwIG0ZqMbukh63epzyEdBd+nmJCiAo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JX6xj2ab7mfoHa/MzdMg9Uoh1mKqPU05D/NhMDF+1f3RloaLvvrumodRetEWqZBQF BmZaEgjGurZoAzTOkGRXC46SLEwU37i+B1qRASjazITWvfmC08SgbyrXE+1P/MWO3N abodP4JzsaDo55ZnvdO1mxzwGj+zSP8Kw6Yj4U/qCofNZeeqyk0Kv+0lvEZUUykRBz Yf4zlY8WbKnycCAc26vpdD/bpSzgD+YfEAibqWuvyTk/xvXIe2S67yT9tbt6dW1NZo KJDQySC2TUh1tvlucg3agMQ5DIGv6r0FflsYSlrpwi9ZbhMSA7qEQCMxPl76yuLyGn YT1OwcBKpNzkjru5iSQrCrqMGvtzrHmfeer137RQipfCEXcaHfYPeymOdF8aUQkMS5 tiGQuGrA6pUmCMfDWuAgw7GuDNRJ5geOSmJCQ1jTFi4AXFOSPbzxmMgK9EHtYAFSF0 dP8DRDvrCXiqgCXmIPlgthID4/NSp+mVh+V4tnI9A/gPlCOHo7o From: Martin Schitter To: ffmpeg-devel@ffmpeg.org Date: Tue, 10 Sep 2024 16:06:02 +0200 Message-ID: <20240910140603.741345-4-ms+git@mur.at> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240910140603.741345-3-ms+git@mur.at> References: <20240910140603.741345-3-ms+git@mur.at> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v4 2/4] libavformat/mxf: DNxUncompressed MXF related changes X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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: Martin Schitter Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: aN6E6NrDQuDr --- libavformat/mxf.c | 1 + libavformat/mxfdec.c | 1 + 2 files changed, 2 insertions(+) diff --git a/libavformat/mxf.c b/libavformat/mxf.c index a73e40e..35fb73e 100644 --- a/libavformat/mxf.c +++ b/libavformat/mxf.c @@ -61,6 +61,7 @@ const MXFCodecUL ff_mxf_codec_uls[] = { { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x71,0x00,0x00,0x00 }, 13, AV_CODEC_ID_DNXHD }, /* SMPTE VC-3/DNxHD */ { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x03,0x02,0x00,0x00 }, 14, AV_CODEC_ID_DNXHD }, /* SMPTE VC-3/DNxHD */ { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0E,0x04,0x02,0x01,0x02,0x04,0x01,0x00 }, 16, AV_CODEC_ID_DNXHD }, /* SMPTE VC-3/DNxHD Legacy Avid Media Composer MXF */ + { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0E,0x04,0x02,0x01,0x02,0x1E,0x01,0x00 }, 16, AV_CODEC_ID_DNXUC }, /* DNxUncompressed/SMPTE RDD 50 */ { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0A,0x04,0x01,0x02,0x02,0x01,0x32,0x00,0x00 }, 14, AV_CODEC_ID_H264 }, /* H.264/MPEG-4 AVC Intra */ { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0A,0x04,0x01,0x02,0x02,0x01,0x31,0x11,0x01 }, 14, AV_CODEC_ID_H264 }, /* H.264/MPEG-4 AVC SPS/PPS in-band */ { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0A,0x04,0x01,0x02,0x01,0x01,0x02,0x02,0x01 }, 16, AV_CODEC_ID_V210 }, /* V210 */ diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c index ac63c0d..142b3e6 100644 --- a/libavformat/mxfdec.c +++ b/libavformat/mxfdec.c @@ -1597,6 +1597,7 @@ static const MXFCodecUL mxf_picture_essence_container_uls[] = { { { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x07,0x0d,0x01,0x03,0x01,0x02,0x0c,0x01,0x00 }, 14, AV_CODEC_ID_JPEG2000, NULL, 14, J2KWrap }, { { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x02,0x0d,0x01,0x03,0x01,0x02,0x10,0x60,0x01 }, 14, AV_CODEC_ID_H264, NULL, 15 }, /* H.264 */ { { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x02,0x0d,0x01,0x03,0x01,0x02,0x11,0x01,0x00 }, 14, AV_CODEC_ID_DNXHD, NULL, 14 }, /* VC-3 */ + { { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x02,0x0d,0x01,0x03,0x01,0x02,0x1e,0x01,0x00 }, 14, AV_CODEC_ID_DNXUC, NULL, 14 }, /* DNxUncompressed / SMPTE RDD 50 */ { { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x02,0x0d,0x01,0x03,0x01,0x02,0x12,0x01,0x00 }, 14, AV_CODEC_ID_VC1, NULL, 14 }, /* VC-1 */ { { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x02,0x0d,0x01,0x03,0x01,0x02,0x14,0x01,0x00 }, 14, AV_CODEC_ID_TIFF, NULL, 14 }, /* TIFF */ { { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x02,0x0d,0x01,0x03,0x01,0x02,0x15,0x01,0x00 }, 14, AV_CODEC_ID_DIRAC, NULL, 14 }, /* VC-2 */ From patchwork Tue Sep 10 14:06:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: martin schitter X-Patchwork-Id: 51488 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:612c:41b1:b0:48e:c0f8:d0de with SMTP id le49csp359346vqb; Tue, 10 Sep 2024 05:08:58 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXahWMjmMxS0TEBzKJndHxsd2Yv47QB+NWA2d+JmdBPBpgqb2/3ONHi4BMnLHbfjX5/0aN80ciCK/OQVZqURD4t@gmail.com X-Google-Smtp-Source: AGHT+IHXQaNtsSq1MpGJjxkYAFZw9GOm4yR/aH/ejjWxD6A73ZCiNY2F6EDVL/dT+jTN5JRq7WrN X-Received: by 2002:a05:6402:5383:b0:5c2:7740:b3bd with SMTP id 4fb4d7f45d1cf-5c3dc793bc2mr8654964a12.14.1725970138320; Tue, 10 Sep 2024 05:08:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1725970138; cv=none; d=google.com; s=arc-20240605; b=ZjvZkdx+++QUjPN/nW9AJZh5WqOJ1/1pXD3YXY6ylKyamxlkcKlY8/6fuE6k62FYpc jfqP3l56ty7eQ3loCKT6paOR8om0csimT7xJ7liFQ52LgLSIiC8a56shgr6U+wWLJeXe 8xAWkCmUXqSqoL1PK7se2whoARo050S3kib8w0fJMR3JpnDNyoUZuQA8uC3abIC0C8KA jXPVFTwjtvtd4uE4s11+TyhwlXTTMSUNnRNKSZz3l5iAj/Qo3c6ZIe5bhSV1G5DkjPCh nfGEHJmVjRNfdyxnkIwMy+48J+414UpSY7cHFYdE9zgMxNGC5IslolqLtT5HxLIF6J6e zTFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=IAGSl/Uk9Ig7TjF4xe3bY4C0/UDc6/pDSFU1gzMNH9U=; fh=igg3JDwkSkAbPTwY6V0OsEq0RUkG4DKWC8fVJg4GhMY=; b=HRtbNITb0zvSgBq72QoDRdfTFc4viK0U2q+HPqSmtjs8QVRXlcZY/ksxRMfYGe/go2 WMggOuPqGfIp9U2zNgG9kA/aMKO47YQhZ/f86W2PyPN4SBpYXUzIE1AdqF0oBhLwJ85S FowJZJ94AnX+Zr4Qwssf1BP4XRXihFc6yWpHliRl0md/1KB3p+FxqOR+50oyzvP7FJqT RwkpDglp5dNPpy/d10C7EXIXHOxjmEiQrASwjjdyBUkE1tTZgLwDcsmo4r2iVLfBOQUd noFocvF3h4oUjiOKwlPFLUSBz/KlYJljv2R6ZkQTxedROTGmAvSn2KJFs3MpHoRWriNf NmLw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@mur.at header.s=dkim2 header.b=tJny5C0n; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mur.at Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id 4fb4d7f45d1cf-5c3ebda96absi5290274a12.514.2024.09.10.05.08.57; Tue, 10 Sep 2024 05:08:58 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@mur.at header.s=dkim2 header.b=tJny5C0n; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mur.at Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4DB8068DFED; Tue, 10 Sep 2024 15:08:36 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from efeu.mur.at (efeu.mur.at [89.106.208.42]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 30A2168DDF5 for ; Tue, 10 Sep 2024 15:08:27 +0300 (EEST) Received: from localhost.localdomain (lan1.raspi.ma39.ffgraz.net [10.12.1.243]) by efeu.mur.at (Postfix) with ESMTPSA id CDCDE461F2; Tue, 10 Sep 2024 14:08:26 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=mur.at; s=dkim2; t=1725970106; bh=ioi6G+2ytLZ1VtONTYKT+3FFlwi1+8sist6CaWt9gSY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tJny5C0nL8UQ0AoL7Sxw+u6OH1uTu5OMk96xQJXczlyU0tcc4yuR5+5XkcqlLIglR cederQ4qSzqP1AucX7BCsNtbDqlqPXFG7DFHwVI9s6lxMwT0GinALGQAiPqclo+H5S rrVxnTmWuCmaXYbcSEHViXLBmc4K0l+YjSMA0rQcQJwI0hu7RDJpMrH/M3qSxwtZ/A 3flMK6kz48a1CIWgMGRLzPCS0UiKGFK8Pe+NHOfNHy/QsENJd8LgHKv9rlTGfzDuOA /IBGjgKx+DaweNCNer5H7onauVfYV81efflwFAjVYVzkisGbnarCBxwwGJ1JxhdVK8 r0rqJNmW9QxNi8TjbZOYQjjI+JNgKQmFLrdnYSx3bVJIZ3QfwiLphubfvMlP2P2GRO lpN0GoGLL+5lBqhPnN8EU3BG442zcWVQs21gESqpUjfhji4mu65YcKeDDPN/0HWELh 4uo/fk4F5aAatsS4zUQF4BD7zwZn2LbAkrwrOfTu6rTMhd5EQx8 From: Martin Schitter To: ffmpeg-devel@ffmpeg.org Date: Tue, 10 Sep 2024 16:06:03 +0200 Message-ID: <20240910140603.741345-5-ms+git@mur.at> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240910140603.741345-3-ms+git@mur.at> References: <20240910140603.741345-3-ms+git@mur.at> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v4 3/4] libavformat/dnxucdec: DNxUncompressed decoder X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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: Martin Schitter Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: +SJ/oNp01b2L --- libavcodec/allcodecs.c | 1 + libavcodec/codec_desc.c | 7 + libavcodec/codec_id.h | 1 + libavcodec/dnxucdec.c | 391 ++++++++++++++++++++++++++++++++++++++++ libavcodec/version.c | 2 +- 5 files changed, 401 insertions(+), 1 deletion(-) create mode 100644 libavcodec/dnxucdec.c diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c index d773ac3..1a3c084 100644 --- a/libavcodec/allcodecs.c +++ b/libavcodec/allcodecs.c @@ -93,6 +93,7 @@ extern const FFCodec ff_dfa_decoder; extern const FFCodec ff_dirac_decoder; extern const FFCodec ff_dnxhd_encoder; extern const FFCodec ff_dnxhd_decoder; +extern const FFCodec ff_dnxuc_decoder; extern const FFCodec ff_dpx_encoder; extern const FFCodec ff_dpx_decoder; extern const FFCodec ff_dsicinvideo_decoder; diff --git a/libavcodec/codec_desc.c b/libavcodec/codec_desc.c index a28ef68..27bf105 100644 --- a/libavcodec/codec_desc.c +++ b/libavcodec/codec_desc.c @@ -1959,6 +1959,13 @@ static const AVCodecDescriptor codec_descriptors[] = { .long_name = NULL_IF_CONFIG_SMALL("LEAD MCMP"), .props = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSY, }, + { + .id = AV_CODEC_ID_DNXUC, + .type = AVMEDIA_TYPE_VIDEO, + .name = "dnxuc", + .long_name = NULL_IF_CONFIG_SMALL("DNxUncompressed / SMPTE RDD 50"), + .props = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSLESS, + }, /* various PCM "codecs" */ { diff --git a/libavcodec/codec_id.h b/libavcodec/codec_id.h index 0ab1e34..c8f8072 100644 --- a/libavcodec/codec_id.h +++ b/libavcodec/codec_id.h @@ -322,6 +322,7 @@ enum AVCodecID { AV_CODEC_ID_RTV1, AV_CODEC_ID_VMIX, AV_CODEC_ID_LEAD, + AV_CODEC_ID_DNXUC, /* various PCM "codecs" */ AV_CODEC_ID_FIRST_AUDIO = 0x10000, ///< A dummy id pointing at the start of audio codecs diff --git a/libavcodec/dnxucdec.c b/libavcodec/dnxucdec.c new file mode 100644 index 0000000..8fffd0a --- /dev/null +++ b/libavcodec/dnxucdec.c @@ -0,0 +1,391 @@ +/* + * Avid DNxUncomressed / SMPTE RDD 50 decoder + * Copyright (c) 2024 Martin Schitter + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/* + This decoder for DNxUncompressed video data is mostly based on + reverse engineering of output generated by DaVinci Resolve 19 + but was later also checked against the SMPTE RDD 50 specification. + + Not all DNxUncompressed pixel format variants are supported, + but at least an elementary base set is already usable: + + - YUV 4:2:2 8/10/12bit + - RGB 8/10/12bit/half/float + +*/ + +#include "avcodec.h" +#include "codec_internal.h" +#include "decode.h" +#include "libavutil/imgutils.h" +#include "thread.h" + +static av_cold int dnxuc_decode_init(AVCodecContext *avctx) +{ + return 0; +} + + +static int pass_though(AVCodecContext *avctx, AVFrame *frame, const AVPacket *avpkt) +{ + /* there is no need to copy as the data already match + * a known pixel format */ + + frame->buf[0] = av_buffer_ref(avpkt->buf); + + if (!frame->buf[0]) { + return AVERROR(ENOMEM); + } + + return av_image_fill_arrays(frame->data, frame->linesize, avpkt->data, + avctx->pix_fmt, avctx->width, avctx->height, 1); +} + +static int float2planes(AVCodecContext *avctx, AVFrame *frame, const AVPacket *pkt) +{ + int x, y, lw; + const size_t sof = 4; + + lw = frame->width; + + for(y = 0; y < frame->height; y++){ + for(x = 0; x < frame->width; x++){ + memcpy(&frame->data[2][sof*(lw*y + x)], &pkt->data[sof* 3*(lw*y + x)], sof); + memcpy(&frame->data[0][sof*(lw*y + x)], &pkt->data[sof*(3*(lw*y + x) + 1)], sof); + memcpy(&frame->data[1][sof*(lw*y + x)], &pkt->data[sof*(3*(lw*y + x) + 2)], sof); + } + } + return pkt->size; +} + +static int half_add_alpha(AVCodecContext *avctx, AVFrame *frame, const AVPacket *pkt) +{ + /* ffmpeg doesn't provide RGB half bit depth without alpha channel right now + * we simply add an opaque alpha layer as workaround */ + + int x, y, lw; + const size_t soh = 2; + const uint16_t opaque = 0x3c00; + + lw = frame->width; + + for(y = 0; y < frame->height; y++){ + for(x = 0; x < frame->width; x++){ + memcpy(&frame->data[0][soh*4*(lw*y + x)], &pkt->data[soh*3*(lw*y + x)], soh*3); + memcpy(&frame->data[0][soh*(4*(lw*y + x) + 3)], &opaque, soh); + } + } + return pkt->size; +} + +/* DNxUncompressed utilizes a very dense bitpack representation of 10bit and 12bit pixel data. + +Lines of Image data, which look like in their ordinary 8bit counterpart, contain the most +significant upper bits of the pixel data. These sections alternate with shorter segments in +which the complementary least significant bits of information get packed in a gapless sequence. + ++----------------------+ +----------------------+ +------------------------+ +----------~ +| 8 m.s.bits of R[1] | | 8 m.s.bits of G[1] | | 8 m.s.bits of B[1] | | msb R[2] ... one line ++----------------------+ +----------------------+ +------------------------+ +----------~ + ++---------------------------------------------------------------+ +-----------~ +| +------------+ +------------+ +------------+ +--------------+ | | +--------~ +| | 2 lsb R[2] | | 2 lsb B[1] | | 2 lsb G[1] | | 2 lsb R[1] | | | | G[3]lsb ... LSB bits for line +| +------------+ +------------+ +------------+ +--------------+ | | +--------~ ++---------------------------- one byte ------------------------ + +-----------~ + +next line of MSB bytes... */ + +static int unpack_rg10(AVCodecContext *avctx, AVFrame *frame, const AVPacket *pkt) +{ + int x, y, lw, msp, pack, lsp, p_off; + uint16_t r,g,b; + + lw = frame->width; + + for(y = 0; y < frame->height; y++){ + for(x = 0; x < frame->width; x++){ + msp = pkt->data[y*3*(lw + lw/4) + 3*x]; + p_off = y*(3*(lw + lw/4)) + 3*lw + 3*x/4; + pack = pkt->data[p_off]; + lsp = (pack >> (3*x%4)*2) & 0x3; + r = (msp << 2) + lsp; + // av_log(0, AV_LOG_DEBUG, "r: %04x, %02x, %02x, %02x, %d\n", + // r, msp, lsp, pack, p_off); + + msp = pkt->data[y*3*(lw + lw/4) + 3*x + 1]; + p_off = y*(3*(lw + lw/4)) + 3*lw + (3*x+1)/4; + pack = pkt->data[p_off]; + lsp = (pack >> ((3*x+1)%4)*2) & 0x3; + g = (msp << 2) + lsp; + // av_log(0, AV_LOG_DEBUG, "g: %04x, %02x, %02x, %02x, %d\n", + // g, msp, lsp, pack, p_off); + + msp = pkt->data[y*3*(lw + lw/4) + 3*x + 2]; + p_off = y*(3*(lw + lw/4)) + 3*lw + (3*x+2)/4; + pack = pkt->data[p_off]; + lsp = (pack >> ((3*x+2)%4)*2) & 0x3; + b = (msp << 2) + lsp; + // av_log(0, AV_LOG_DEBUG, "b: %04x, %02x, %02x, %02x, %d\n\n", + // b, msp, lsp, pack, p_off); + + memcpy(&frame->data[2][2*(y*lw + x)], &r, 2); + memcpy(&frame->data[0][2*(y*lw + x)], &g, 2); + memcpy(&frame->data[1][2*(y*lw + x)], &b, 2); + } + } + return pkt->size; +} + +static int unpack_rg12(AVCodecContext *avctx, AVFrame *frame, const AVPacket *pkt) +{ + int x, y, lw, msp, pack, lsp, p_off; + uint16_t r,g,b; + + lw = frame->width; + + for(y = 0; y < frame->height; y++){ + for(x = 0; x < frame->width; x++){ + msp = pkt->data[y*3*(lw + lw/2) + 3*x]; + p_off = y*(3*(lw + lw/2)) + 3*lw + 3*x/2; + pack = pkt->data[p_off]; + lsp = (pack >> (3*x%2)*4) & 0xf; + r = (msp << 4) + lsp; + // av_log(0, AV_LOG_DEBUG, "r: %04x, %02x, %02x, %02x, %d\n", + // r, msp, lsp, pack, p_off); + + msp = pkt->data[y*3*(lw + lw/2) + 3*x + 1]; + p_off =y*(3*(lw + lw/2)) + 3*lw + (3*x+1)/2; + pack = pkt->data[p_off]; + lsp = (pack >> ((3*x+1)%2)*4) & 0xf; + g = (msp << 4) + lsp; + // av_log(0, AV_LOG_DEBUG, "g: %04x, %02x, %02x, %02x, %d\n", + // g, msp, lsp, pack, p_off); + + msp = pkt->data[y*3*(lw + lw/2) + 3*x + 2]; + p_off = y*(3*(lw + lw/2)) + 3*lw + (3*x+2)/2; + pack = pkt->data[p_off]; + lsp = (pack >> ((3*x+2)%2)*4) & 0xf; + b = (msp << 4) + lsp; + // av_log(0, AV_LOG_DEBUG, "b: %04x, %02x, %02x, %02x, %d\n\n", + // b, msp, lsp, pack, p_off); + + memcpy(&frame->data[2][2*(y*lw + x)], &r, 2); + memcpy(&frame->data[0][2*(y*lw + x)], &g, 2); + memcpy(&frame->data[1][2*(y*lw + x)], &b, 2); + } + } + return pkt->size; +} + + +static int unpack_y210(AVCodecContext *avctx, AVFrame *frame, const AVPacket *pkt) +{ + int x, y, lw, msp, pack, lsp, p_off; + uint16_t y1, y2, u, v; + + lw = frame->width; + + for(y = 0; y < frame->height; y++){ + for(x = 0; x < frame->width; x += 2){ + + p_off = y*(2*(lw + lw/4)) + 2*lw + x/2; + pack = pkt->data[p_off]; + + msp = pkt->data[y*2*(lw + lw/4) + 2*x]; + lsp = pack & 0x3; + u = (msp << 2) + lsp; + // av_log(0, AV_LOG_DEBUG, " u: %04x, %02x, %02x, %02x, %d\n", + // u, msp, lsp, pack, p_off); + + msp = pkt->data[y*2*(lw + lw/4) + 2*x + 1]; + lsp = (pack >> 2) & 0x3; + y1 = (msp << 2) + lsp; + // av_log(0, AV_LOG_DEBUG, "y1: %04x, %02x, %02x, %02x, %d\n", + // y1, msp, lsp, pack, p_off); + + msp = pkt->data[y*2*(lw + lw/4) + 2*x + 2]; + lsp = (pack >> 4) & 0x3; + v = (msp << 2) + lsp; + // av_log(0, AV_LOG_DEBUG, " v: %04x, %02x, %02x, %02x, %d\n", + // v, msp, lsp, pack, p_off); + + msp = pkt->data[y*2*(lw + lw/4) + 2*x + 3]; + lsp = (pack >> 6) & 0x3; + y2 = (msp << 2) + lsp; + // av_log(0, AV_LOG_DEBUG, "y2: %04x, %02x, %02x, %02x, %d\n\n", + // y2, msp, lsp, pack, p_off); + + memcpy(&frame->data[0][2*(y*lw + x)], &y1, 2); + memcpy(&frame->data[0][2*(y*lw + x+1)], &y2, 2); + memcpy(&frame->data[1][2*(y*lw/2 + x/2)], &u, 2); + memcpy(&frame->data[2][2*(y*lw/2 + x/2)], &v, 2); + } + } + return pkt->size; +} + + +static int unpack_y212(AVCodecContext *avctx, AVFrame *frame, const AVPacket *pkt) +{ + int x, y, lw, msp, pack, lsp, p_off; + uint16_t y1, y2, u, v; + + lw = frame->width; + + for(y = 0; y < frame->height; y++){ + for(x = 0; x < frame->width; x += 2){ + + p_off = y*(2*(lw + lw/2)) + 2*lw + x; + pack = pkt->data[p_off]; + + msp = pkt->data[y*2*(lw + lw/2) + 2*x]; + lsp = pack & 0xf; + u = (msp << 4) + lsp; + // av_log(0, AV_LOG_DEBUG, " u: %04x, %02x, %02x, %02x, %d\n", + // u, msp, lsp, pack, p_off); + + msp = pkt->data[y*2*(lw + lw/2) + 2*x + 1]; + lsp = (pack >> 4) & 0xf; + y1 = (msp << 4) + lsp; + // av_log(0, AV_LOG_DEBUG, "y1: %04x, %02x, %02x, %02x, %d\n", + // y1, msp, lsp, pack, p_off); + + p_off = y*(2*(lw + lw/2)) + 2*lw + x+1; + pack = pkt->data[p_off]; + + msp = pkt->data[y*2*(lw + lw/2) + 2*x + 2]; + lsp = pack & 0xf; + v = (msp << 4) + lsp; + // av_log(0, AV_LOG_DEBUG, " v: %04x, %02x, %02x, %02x, %d\n", + // v, msp, lsp, pack, p_off); + + msp = pkt->data[y*2*(lw + lw/2) + 2*x + 3]; + lsp = (pack >> 4) & 0xf; + y2 = (msp << 4) + lsp; + // av_log(0, AV_LOG_DEBUG, "y2: %04x, %02x, %02x, %02x, %d\n\n", + // y2, msp, lsp, pack, p_off); + + memcpy(&frame->data[0][2*(y*lw + x)], &y1, 2); + memcpy(&frame->data[0][2*(y*lw + x+1)], &y2, 2); + memcpy(&frame->data[1][2*(y*lw/2 + x/2)], &u, 2); + memcpy(&frame->data[2][2*(y*lw/2 + x/2)], &v, 2); + } + } + return pkt->size; +} + +static int check_pkt_size(AVCodecContext *avctx, AVPacket *avpkt, int bpp) +{ + int needed = ((avctx->width * bpp + 7) / 8) * avctx->height; + if (avpkt->size < needed){ + av_log(avctx, AV_LOG_ERROR, + "Insufficient size of AVPacket data (pkg size: %d needed: %d)\n", avpkt->size, needed); + return AVERROR_EXIT; + } + return 0; +} + +static int fmt_frame(AVCodecContext *avctx, AVFrame *frame, AVPacket *avpkt, + enum AVPixelFormat pix_fmt, int src_bpp, + int (*frame_handler)(AVCodecContext *avctx, AVFrame *frame, const AVPacket *avpkt)) +{ + int ret; + avctx->pix_fmt = pix_fmt; + + ret = check_pkt_size(avctx, avpkt, src_bpp); + if (ret) + return ret; + + ret = ff_thread_get_buffer(avctx, frame, 0); + if (ret < 0) + return ret; + + return frame_handler(avctx, frame, avpkt); +} + +static int dnxuc_decode_frame(AVCodecContext *avctx, AVFrame *frame, + int *got_frame, AVPacket *avpkt) +{ + char fourcc_buf[5]; + int ret; + + av_fourcc_make_string(fourcc_buf, avctx->codec_tag); + if ((avctx->width % 2) && ((fourcc_buf[0] == 'y' && fourcc_buf[1] == '2') + ||(fourcc_buf[1] == 'y' && fourcc_buf[2] == '2'))){ + av_log(avctx, AV_LOG_ERROR, + "Image width must be a multiple of 2 for YUV 4:2:2 DNxUncompressed!\n"); + return AVERROR_EXIT; + } + + switch (avctx->codec_tag) { + case MKTAG('r','g','0','8'): + ret = fmt_frame(avctx, frame, avpkt, AV_PIX_FMT_RGB24, 24, pass_though); + break; + case MKTAG('r','g','1','0'): + ret = fmt_frame(avctx, frame, avpkt, AV_PIX_FMT_GBRP10LE, 30, unpack_rg10); + break; + case MKTAG('r','g','1','2'): + ret = fmt_frame(avctx, frame, avpkt, AV_PIX_FMT_GBRP12LE, 36, unpack_rg12); + break; + case MKTAG(' ','r','g','h'): + ret = fmt_frame(avctx, frame, avpkt, AV_PIX_FMT_RGBAF16LE, 48, half_add_alpha); + break; + case MKTAG(' ','r','g','f'): + ret = fmt_frame(avctx, frame, avpkt, AV_PIX_FMT_GBRPF32LE, 96, float2planes); + break; + + case MKTAG('y','2','0','8'): + ret = fmt_frame(avctx, frame, avpkt, AV_PIX_FMT_UYVY422, 16, pass_though); + break; + case MKTAG('y','2','1','0'): + ret = fmt_frame(avctx, frame, avpkt, AV_PIX_FMT_YUV422P10LE, 20, unpack_y210); + break; + case MKTAG('y','2','1','2'): + ret = fmt_frame(avctx, frame, avpkt, AV_PIX_FMT_YUV422P12LE, 24, unpack_y212); + break; + + default: + av_log(avctx, AV_LOG_ERROR, + "Unsupported DNxUncompressed pixel format variant: '%s'\n", + fourcc_buf); + return AVERROR(ENOSYS); + } + + if (ret < 0) { + av_buffer_unref(&frame->buf[0]); + return ret; + } + + *got_frame = 1; + + return avpkt->size; +} + +const FFCodec ff_dnxuc_decoder = { + .p.name = "dnxuc", + CODEC_LONG_NAME("DNxUncompressed (SMPTE RDD 50)"), + .p.type = AVMEDIA_TYPE_VIDEO, + .p.id = AV_CODEC_ID_DNXUC, + .init = dnxuc_decode_init, + FF_CODEC_DECODE_CB(dnxuc_decode_frame), + .p.capabilities = AV_CODEC_CAP_FRAME_THREADS, +}; diff --git a/libavcodec/version.c b/libavcodec/version.c index 27f9432..03dd95e 100644 --- a/libavcodec/version.c +++ b/libavcodec/version.c @@ -31,7 +31,7 @@ const char av_codec_ffversion[] = "FFmpeg version " FFMPEG_VERSION; unsigned avcodec_version(void) { - static_assert(AV_CODEC_ID_LEAD == 269 && + static_assert(AV_CODEC_ID_DNXUC == 270 && AV_CODEC_ID_PCM_SGA == 65572 && AV_CODEC_ID_ADPCM_XMD == 69683 && AV_CODEC_ID_CBD2_DPCM == 81928 && From patchwork Tue Sep 10 14:06:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: martin schitter X-Patchwork-Id: 51489 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:612c:41b1:b0:48e:c0f8:d0de with SMTP id le49csp359467vqb; Tue, 10 Sep 2024 05:09:09 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVhe4pcM0FaUMpyQoPoimvfh533vOHaNi39Gm95mbnbEW5s+S94DGqya719kM6ibXNeM/LM4JaehwD1Sv8R6sQu@gmail.com X-Google-Smtp-Source: AGHT+IEdPtqImv4QyauaCrSpjDvl8sDghmgtdrG7ZM7QU+I4OP3ePk3K6iqtMUcrtmX/1nN7+1Nu X-Received: by 2002:a17:907:97c6:b0:a8a:9054:83b5 with SMTP id a640c23a62f3a-a8ffab887ffmr19849466b.3.1725970149077; Tue, 10 Sep 2024 05:09:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1725970149; cv=none; d=google.com; s=arc-20240605; b=ge95IUHhLM7b4IJI1OaskqEJL2tv4ye8klnMz0Kb8NCoK1qjmgcz1fuvWe53v5fsQc KtdeQT0VUCmLYHCIiJl5fS38CwT3fIsZDDSpL7RQNCRgY69SC+OcTxH6ImdnAaMPtHko IUa1j9alTgnv/xe0UVyYIgGDjNXnqO06Ko70g8uSpZL5ua8O56dwNmOBZspwjtPBGtBQ nLxi8e0iWK/VFKDnPkVQFmdjdLdSoWHLSBQB9Moq7/2WYR8G6wjPbIATTP9OlfY5lvhz s2utVSCE15l/OvAFs4D+gZ9RnuYJXEiCMz1FHpExW3JLWPcRHGr7kxpFk1Fh0Klre8Z5 FbMg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=j+bJYzL51cyhBVBPWmUf7VeorfpXHJ/p7scV0ZJZq2c=; fh=igg3JDwkSkAbPTwY6V0OsEq0RUkG4DKWC8fVJg4GhMY=; b=BowRwHpzd5MROGSgry1b11WCVTR3QVo9AqqiRjDFiGZZYXWx2k85AQE+frV3w6WRb7 1O+ehx8Xzg6Uyhcm9B2mAVsqsqRkuDEAUsrZDqCh4lEYS0tiY0DFM/La26BnD8Ju0Mpt zIPTlxOiexSojTzF1pY/LO9M9BGWxtOh5Ovy4ZSPQQRxh+J4uasSfOv9zgqojPasJ3fB 19mlGssRkxT/c56yFKl78LqyRIUWrjijn2uMHQzOq9NlniQ1eHoesLoVkkpkTSYDgJe9 9U7gMknVkiDgi5sc0IrZqWciwsrXGxFG4my0TAajWanvXM949sjx3gz8B4a3sL4mRbth g+XQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@mur.at header.s=dkim2 header.b=Agmb4bUu; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mur.at Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id a640c23a62f3a-a8d25d67ce2si554628566b.772.2024.09.10.05.09.08; Tue, 10 Sep 2024 05:09:09 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@mur.at header.s=dkim2 header.b=Agmb4bUu; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mur.at Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id AA8CE68DFFB; Tue, 10 Sep 2024 15:08:37 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from efeu.mur.at (efeu.mur.at [89.106.208.42]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4AB0268DDC1 for ; Tue, 10 Sep 2024 15:08:27 +0300 (EEST) Received: from localhost.localdomain (lan1.raspi.ma39.ffgraz.net [10.12.1.243]) by efeu.mur.at (Postfix) with ESMTPSA id ED5F246207; Tue, 10 Sep 2024 14:08:26 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=mur.at; s=dkim2; t=1725970107; bh=D3QN5MVWhg7AU5UpMiUNm01sl5vfIFfumYS+IoP3F/M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Agmb4bUut4UOhsJDT4H9fqrIxzGMAWB0sidOH9OnhiW5edJvHq3dWBrUrGLRJVoim COSjJvGgqWtBS6gkq/DMnZkGDlrO3mj9ZuWrBoSm1MxoPiwwBVv2U8grMlykHxGBPX ZO+UA8w++i7hLziTiJ3r4wlC34c88PJAEigD+SHPjJa0oYjg6kHFykUyBNGRUimzsB +R8Nv/lPyBKVcONRxXjpYq0FQanN9Tde0kK+mS6qBHiwO/9hnTQEg/L4DGi9HE4cR8 X4Lw8IffU+84QrwQf4WVm1RPTFaopzoUyYaceCj5LtB95zWKdLUTfGtzD4Net8Lhzx J3dbDueemaaH8VP7Q7K/KRpVaXg/oW9iaY7/8EGQdZ6oYlJRNesBlijizLfSCOz1oo Ae3VkOO3u09v4U7++bUjgFXwso07HM/kMKLblb/NBwhMBO3bb9WtVucfs16rsr+qKO I1Cxk2rMKHXJ4ueW8NCyRetno03T/jEb+gPY37PbnzneY5eIDQV From: Martin Schitter To: ffmpeg-devel@ffmpeg.org Date: Tue, 10 Sep 2024 16:06:04 +0200 Message-ID: <20240910140603.741345-6-ms+git@mur.at> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240910140603.741345-3-ms+git@mur.at> References: <20240910140603.741345-3-ms+git@mur.at> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v4 4/4] libavformat: DNxUncompressed aux files X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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: Martin Schitter Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: h0Q+YoulNGAA --- Changelog | 1 + doc/general_contents.texi | 1 + libavcodec/Makefile | 1 + 3 files changed, 3 insertions(+) diff --git a/Changelog b/Changelog index 7237648..0464bee 100644 --- a/Changelog +++ b/Changelog @@ -20,6 +20,7 @@ version : - Intel QSV-accelerated VVC decoding - MediaCodec AAC/AMR-NB/AMR-WB/MP3 decoding - YUV colorspace negotiation for codecs and filters, obsoleting YUVJ +- DNxUncompressed (SMPTE RDD 50) decoder version 7.0: diff --git a/doc/general_contents.texi b/doc/general_contents.texi index e7cf4f8..1593124 100644 --- a/doc/general_contents.texi +++ b/doc/general_contents.texi @@ -619,6 +619,7 @@ library: @item raw DFPWM @tab X @tab X @item raw Dirac @tab X @tab X @item raw DNxHD @tab X @tab X +@itme raw DNxUncompressed @tab @tab X @item raw DTS @tab X @tab X @item raw DTS-HD @tab @tab X @item raw E-AC-3 @tab X @tab X diff --git a/libavcodec/Makefile b/libavcodec/Makefile index 1d27e55..eee98ed 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -325,6 +325,7 @@ OBJS-$(CONFIG_DFPWM_DECODER) += dfpwmdec.o OBJS-$(CONFIG_DFPWM_ENCODER) += dfpwmenc.o OBJS-$(CONFIG_DNXHD_DECODER) += dnxhddec.o dnxhddata.o OBJS-$(CONFIG_DNXHD_ENCODER) += dnxhdenc.o dnxhddata.o +OBJS-$(CONFIG_DNXUC_DECODER) += dnxucdec.o dnxuc_parser.o OBJS-$(CONFIG_DOLBY_E_DECODER) += dolby_e.o dolby_e_parse.o kbdwin.o OBJS-$(CONFIG_DPX_DECODER) += dpx.o OBJS-$(CONFIG_DPX_ENCODER) += dpxenc.o