From: Devin Heitmueller <devin.heitmueller@ltnglobal.com>
To: ffmpeg-devel@ffmpeg.org
Cc: Devin Heitmueller <dheitmueller@ltnglobal.com>
Subject: [FFmpeg-devel] [PATCH] decklink: Add support for output of Active Format Description (AFD)
Date: Mon, 27 Mar 2023 15:58:10 -0400
Message-ID: <20230327195810.2240-1-dheitmueller@ltnglobal.com> (raw)
Implement support for including AFD in decklink output when putting
out 10-bit VANC data.
Updated to reflect feedback in 2018 from Marton Balint <cus@passwd.hu>,
Carl Eugen Hoyos <ceffmpeg@gmail.com> and Aaron Levinson
<alevinsn_dev@levland.net>. Also includes fixes to set the AR field
based on the SAR, as well as now sending the AFD info in both fields
for interlaced formats.
Signed-off-by: Devin Heitmueller <dheitmueller@ltnglobal.com>
---
libavdevice/decklink_enc.cpp | 91 +++++++++++++++++++++++++++++++++++-
1 file changed, 89 insertions(+), 2 deletions(-)
diff --git a/libavdevice/decklink_enc.cpp b/libavdevice/decklink_enc.cpp
index a63aeaa088..309cea8a48 100644
--- a/libavdevice/decklink_enc.cpp
+++ b/libavdevice/decklink_enc.cpp
@@ -412,8 +412,94 @@ static void construct_cc(AVFormatContext *avctx, struct decklink_ctx *ctx,
}
}
+/* See SMPTE ST 2016-3:2009 */
+static void construct_afd(AVFormatContext *avctx, struct decklink_ctx *ctx,
+ AVPacket *pkt, struct klvanc_line_set_s *vanc_lines,
+ AVStream *st)
+{
+ struct klvanc_packet_afd_s *afd = NULL;
+ uint16_t *afd_words = NULL;
+ uint16_t len;
+ size_t size;
+ int f1_line = 12, f2_line = 0, ret;
+
+ const uint8_t *data = av_packet_get_side_data(pkt, AV_PKT_DATA_AFD, &size);
+ if (!data || size == 0)
+ return;
+
+ ret = klvanc_create_AFD(&afd);
+ if (ret) {
+ return;
+ }
+
+ ret = klvanc_set_AFD_val(afd, data[0]);
+ if (ret) {
+ av_log(avctx, AV_LOG_ERROR, "Invalid AFD value specified: %d\n",
+ data[0]);
+ klvanc_destroy_AFD(afd);
+ return;
+ }
+
+ /* Compute the AR flag based on the DAR (see ST 2016-1:2009 Sec 9.1). Note, we treat
+ anything below 1.4 as 4:3 (as opposed to the standard 1.33), because there are lots
+ of streams in the field that aren't *exactly* 4:3 but a tiny bit larger after doing
+ the math... */
+ if (av_cmp_q((AVRational) {st->codecpar->width * st->codecpar->sample_aspect_ratio.num,
+ st->codecpar->height * st->codecpar->sample_aspect_ratio.den}, (AVRational) {14, 10}) == 1)
+ afd->aspectRatio = ASPECT_16x9;
+ else
+ afd->aspectRatio = ASPECT_4x3;
+
+ ret = klvanc_convert_AFD_to_words(afd, &afd_words, &len);
+ if (ret) {
+ av_log(avctx, AV_LOG_ERROR, "Failed converting AFD packet to words\n");
+ goto out;
+ }
+
+ ret = klvanc_line_insert(ctx->vanc_ctx, vanc_lines, afd_words, len, f1_line, 0);
+ if (ret) {
+ av_log(avctx, AV_LOG_ERROR, "VANC line insertion failed\n");
+ goto out;
+ }
+
+ /* For interlaced video, insert into both fields. Switching lines for field 2
+ derived from SMPTE RP 168:2009, Sec 6, Table 2. */
+ switch (ctx->bmd_mode) {
+ case bmdModeNTSC:
+ case bmdModeNTSC2398:
+ f2_line = 273 - 10 + f1_line;
+ break;
+ case bmdModePAL:
+ f2_line = 319 - 6 + f1_line;
+ break;
+ case bmdModeHD1080i50:
+ case bmdModeHD1080i5994:
+ case bmdModeHD1080i6000:
+ f2_line = 569 - 7 + f1_line;
+ break;
+ default:
+ f2_line = 0;
+ break;
+ }
+
+ if (f2_line > 0) {
+ ret = klvanc_line_insert(ctx->vanc_ctx, vanc_lines, afd_words, len, f2_line, 0);
+ if (ret) {
+ av_log(avctx, AV_LOG_ERROR, "VANC line insertion failed\n");
+ goto out;
+ }
+ }
+
+out:
+ if (afd)
+ klvanc_destroy_AFD(afd);
+ if (afd_words)
+ free(afd_words);
+}
+
static int decklink_construct_vanc(AVFormatContext *avctx, struct decklink_ctx *ctx,
- AVPacket *pkt, decklink_frame *frame)
+ AVPacket *pkt, decklink_frame *frame,
+ AVStream *st)
{
struct klvanc_line_set_s vanc_lines = { 0 };
int ret = 0, i;
@@ -422,6 +508,7 @@ static int decklink_construct_vanc(AVFormatContext *avctx, struct decklink_ctx *
return 0;
construct_cc(avctx, ctx, pkt, &vanc_lines);
+ construct_afd(avctx, ctx, pkt, &vanc_lines, st);
IDeckLinkVideoFrameAncillary *vanc;
int result = ctx->dlo->CreateAncillaryData(bmdFormat10BitYUV, &vanc);
@@ -513,7 +600,7 @@ static int decklink_write_video_packet(AVFormatContext *avctx, AVPacket *pkt)
frame = new decklink_frame(ctx, avpacket, st->codecpar->codec_id, ctx->bmd_height, ctx->bmd_width);
#if CONFIG_LIBKLVANC
- if (decklink_construct_vanc(avctx, ctx, pkt, frame))
+ if (decklink_construct_vanc(avctx, ctx, pkt, frame, st))
av_log(avctx, AV_LOG_ERROR, "Failed to construct VANC\n");
#endif
}
--
2.35.1.655.ga68dfadae5
_______________________________________________
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".
next reply other threads:[~2023-03-27 19:58 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-27 19:58 Devin Heitmueller [this message]
2023-04-03 21:43 ` Devin Heitmueller
2023-04-05 22:06 ` Marton Balint
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230327195810.2240-1-dheitmueller@ltnglobal.com \
--to=devin.heitmueller@ltnglobal.com \
--cc=dheitmueller@ltnglobal.com \
--cc=ffmpeg-devel@ffmpeg.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git