From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id AC88245D24 for ; Wed, 5 Apr 2023 21:52:59 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 46CCF68B7DE; Thu, 6 Apr 2023 00:52:57 +0300 (EEST) Received: from iq.passwd.hu (unknown [217.27.212.140]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 8B467688313 for ; Thu, 6 Apr 2023 00:52:50 +0300 (EEST) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 7373DE8B5C for ; Wed, 5 Apr 2023 23:52:39 +0200 (CEST) X-Virus-Scanned: amavisd-new at passwd.hu Received: from iq.passwd.hu ([127.0.0.1]) by localhost (iq.passwd.hu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id V_po7OOfgNAp for ; Wed, 5 Apr 2023 23:52:34 +0200 (CEST) Received: from iq (iq [217.27.212.140]) by iq.passwd.hu (Postfix) with ESMTPS id 1130BE8627 for ; Wed, 5 Apr 2023 23:52:34 +0200 (CEST) Date: Wed, 5 Apr 2023 23:52:34 +0200 (CEST) From: Marton Balint To: FFmpeg development discussions and patches In-Reply-To: <20230403212823.890-1-dheitmueller@ltnglobal.com> Message-ID: <48b77d7-cc59-21b4-9ab2-202b74a56c9f@passwd.hu> References: <20230403212823.890-1-dheitmueller@ltnglobal.com> MIME-Version: 1.0 Subject: Re: [FFmpeg-devel] [PATCH v4] decklink: Add support for compressed AC-3 output over SDI 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 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: On Mon, 3 Apr 2023, Devin Heitmueller wrote: > Extend the decklink output to include support for compressed AC-3, > encapsulated using the SMPTE ST 377:2015 standard. > > This functionality can be exercised by using the "copy" codec when > the input audio stream is AC-3. For example: > > ./ffmpeg -i ~/foo.ts -codec:a copy -f decklink 'UltraStudio Mini Monitor' > > Note that the default behavior continues to be to do PCM output, > which means without specifying the copy codec a stream containing > AC-3 will be decoded and downmixed to stereo audio before output. > > Thanks to Marton Balint for providing feedback. > > Signed-off-by: Devin Heitmueller > --- > libavdevice/decklink_enc.cpp | 97 ++++++++++++++++++++++++++++++------ > 1 file changed, 82 insertions(+), 15 deletions(-) > > diff --git a/libavdevice/decklink_enc.cpp b/libavdevice/decklink_enc.cpp > index 8d423f6b6e..9ee1925fd0 100644 [...] > --- a/libavdevice/decklink_enc.cpp > +++ b/libavdevice/decklink_enc.cpp > +/* Wrap the AC-3 packet into an S337 payload that is in S16LE format which can be easily > + injected into the PCM stream. Note: despite the function name, only AC-3 is implemented */ > +static int create_s337_payload(AVPacket *pkt, enum AVCodecID codec_id, uint8_t **outbuf, int *outsize) Actually you can remove the codec_id parameter as well... > +{ > + // Note: if the packet is an odd-number of bytes, we need to make > + // the actual payload one byte larger to ensure it ends on an S16LE boundary > + int payload_size = pkt->size + (pkt->size % 2) + 8; FFALIGN(pkt->size, 2). But you'd want FFALIGN(pkt->size, 4) because you want the buffer size to be divisable by 4 because later decklink needs a sample count... > + uint16_t bitcount = pkt->size * 8; Is this supposed to be aligned too? I see similar code in libavformat/spdifenc.c and FFALIGN(pkt->size, 2) << 3 is used there. > + uint8_t *s337_payload; > + PutByteContext pb; > + > + /* Sanity check: According to SMPTE ST 340:2015 Sec 4.1, the AC-3 sync frame will > + exactly match the 1536 samples of baseband (PCM) audio that it represents. */ > + if (pkt->size > 1536) > + return AVERROR(EINVAL); > + > + /* Encapsulate AC3 syncframe into SMPTE 337 packet */ > + s337_payload = (uint8_t *) av_malloc(payload_size); > + if (s337_payload == NULL) > + return AVERROR(ENOMEM); > + bytestream2_init_writer(&pb, s337_payload, payload_size); > + bytestream2_put_le16u(&pb, 0xf872); /* Sync word 1 */ > + bytestream2_put_le16u(&pb, 0x4e1f); /* Sync word 1 */ > + bytestream2_put_le16u(&pb, 0x0001); /* Burst Info, including data type (1=ac3) */ > + bytestream2_put_le16u(&pb, bitcount); /* Length code */ > + for (int i = 0; i < (pkt->size - 1); i += 2) > + bytestream2_put_le16u(&pb, (pkt->data[i] << 8) | pkt->data[i+1]); > + if (pkt->size % 2) pkt->size & 1 > + bytestream2_put_le16u(&pb, pkt->data[pkt->size - 1] << 8); > + And you likely want a bytestream2_put_le16(&pb, 0) in the end so even the end of the 4-byte aligned buffer is properly zeroed. Thanks, Marton _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".