History

lavc: add smpte436m_to_eia608 bitstream filter

Jacob Lifshay committed 1 year ago

Commit aa5b9db1 parent 1c85a385 files · +97 −0Browse files

Unified · Split

5 files
  1. configure +1 −0
  2. doc/bitstream_filters.texi +5 −0
  3. libavcodec/bitstream_filters.c +1 −0
  4. libavcodec/bsf/Makefile +1 −0
  5. libavcodec/bsf/smpte436m_to_eia608.c +89 −0
configure+1−0
@@ -3539,6 +3539,7 @@ h264_redundant_pps_bsf_select="cbs_h264" · 3538 unmodified lines
35393539 hevc_metadata_bsf_select="cbs_h265"
35403540 mjpeg2jpeg_bsf_select="jpegtables"
35413541 mpeg2_metadata_bsf_select="cbs_mpeg2"
3542+smpte436m_to_eia608_bsf_select="smpte_436m"
35423543 trace_headers_bsf_select="cbs cbs_vp8"
35433544 vp9_metadata_bsf_select="cbs_vp9"
35443545 vvc_metadata_bsf_select="cbs_h266"
doc/bitstream_filters.texi+5−0
@@ -948,6 +948,11 @@ ffmpeg -i INPUT -c:a copy -bsf:a setts=pts=DTS out.mkv · 947 unmodified lines
948948 Log basic packet information. Mainly useful for testing, debugging,
949949 and development.
950950
951+@section smpte436m_to_eia608
952+
953+Convert from a @code{SMPTE_436M_ANC} data stream to a @code{EIA_608} stream,
954+extracting the closed captions from CTA-708 CDP VANC packets, and ignoring all other data.
955+
951956 @anchor{text2movsub}
952957 @section text2movsub
953958
libavcodec/bitstream_filters.c+1−0
@@ -61,6 +61,7 @@ extern const FFBitStreamFilter ff_prores_metadata_bsf; · 60 unmodified lines
6161 extern const FFBitStreamFilter ff_remove_extradata_bsf;
6262 extern const FFBitStreamFilter ff_setts_bsf;
6363 extern const FFBitStreamFilter ff_showinfo_bsf;
64+extern const FFBitStreamFilter ff_smpte436m_to_eia608_bsf;
6465 extern const FFBitStreamFilter ff_text2movsub_bsf;
6566 extern const FFBitStreamFilter ff_trace_headers_bsf;
6667 extern const FFBitStreamFilter ff_truehd_core_bsf;
libavcodec/bsf/Makefile+1−0
@@ -38,6 +38,7 @@ OBJS-$(CONFIG_PRORES_METADATA_BSF) += bsf/prores_metadata.o · 37 unmodified lines
3838 OBJS-$(CONFIG_REMOVE_EXTRADATA_BSF) += bsf/remove_extradata.o
3939 OBJS-$(CONFIG_SETTS_BSF) += bsf/setts.o
4040 OBJS-$(CONFIG_SHOWINFO_BSF) += bsf/showinfo.o
41+OBJS-$(CONFIG_SMPTE436M_TO_EIA608_BSF) += bsf/smpte436m_to_eia608.o
4142 OBJS-$(CONFIG_TEXT2MOVSUB_BSF) += bsf/movsub.o
4243 OBJS-$(CONFIG_TRACE_HEADERS_BSF) += bsf/trace_headers.o
4344 OBJS-$(CONFIG_TRUEHD_CORE_BSF) += bsf/truehd_core.o
libavcodec/bsf/smpte436m_to_eia608.c+89−0
@@ -0,0 +1,89 @@
1+/*
2+ * MXF SMPTE-436M ANC to EIA-608 bitstream filter
3+ * Copyright (c) 2025 Jacob Lifshay
4+ *
5+ * This file is part of FFmpeg.
6+ *
7+ * FFmpeg is free software; you can redistribute it and/or
8+ * modify it under the terms of the GNU Lesser General Public
9+ * License as published by the Free Software Foundation; either
10+ * version 2.1 of the License, or (at your option) any later version.
11+ *
12+ * FFmpeg is distributed in the hope that it will be useful,
13+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
14+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+ * Lesser General Public License for more details.
16+ *
17+ * You should have received a copy of the GNU Lesser General Public
18+ * License along with FFmpeg; if not, write to the Free Software
19+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20+ */
21+
22+#include "bsf.h"
23+#include "bsf_internal.h"
24+#include "codec_id.h"
25+#include "libavcodec/smpte_436m.h"
26+#include "libavutil/error.h"
27+
28+static av_cold int ff_smpte436m_to_eia608_init(AVBSFContext *ctx)
29+{
30+ ctx->par_out->codec_type = AVMEDIA_TYPE_SUBTITLE;
31+ ctx->par_out->codec_id = AV_CODEC_ID_EIA_608;
32+ return 0;
33+}
34+
35+static int ff_smpte436m_to_eia608_filter(AVBSFContext *ctx, AVPacket *out)
36+{
37+ AVPacket *in;
38+ int ret = ff_bsf_get_packet(ctx, &in);
39+ if (ret < 0)
40+ return ret;
41+
42+ AVSmpte436mAncIterator iter;
43+ ret = av_smpte_436m_anc_iter_init(&iter, in->data, in->size);
44+ if (ret < 0)
45+ goto fail;
46+ AVSmpte436mCodedAnc coded_anc;
47+ while ((ret = av_smpte_436m_anc_iter_next(&iter, &coded_anc)) >= 0) {
48+ AVSmpte291mAnc8bit anc;
49+ ret = av_smpte_291m_anc_8bit_decode(
50+ &anc, coded_anc.payload_sample_coding, coded_anc.payload_sample_count, coded_anc.payload, ctx);
51+ if (ret < 0)
52+ goto fail;
53+ ret = av_smpte_291m_anc_8bit_extract_cta_708(&anc, NULL, ctx);
54+ if (ret == AVERROR(EAGAIN))
55+ continue;
56+ if (ret < 0)
57+ goto fail;
58+ int cc_count = ret;
59+
60+ ret = av_new_packet(out, 3 * cc_count);
61+ if (ret < 0)
62+ goto fail;
63+
64+ ret = av_packet_copy_props(out, in);
65+ if (ret < 0)
66+ goto fail;
67+
68+ // verified it won't fail by running it above
69+ av_smpte_291m_anc_8bit_extract_cta_708(&anc, out->data, ctx);
70+
71+ return 0;
72+ }
73+ if (ret != AVERROR_EOF)
74+ return ret;
75+ ret = AVERROR(EAGAIN);
76+
77+fail:
78+ if (ret < 0)
79+ av_packet_unref(out);
80+ av_packet_free(&in);
81+ return ret;
82+}
83+
84+const FFBitStreamFilter ff_smpte436m_to_eia608_bsf = {
85+ .p.name = "smpte436m_to_eia608",
86+ .p.codec_ids = (const enum AVCodecID[]){ AV_CODEC_ID_SMPTE_436M_ANC, AV_CODEC_ID_NONE },
87+ .init = ff_smpte436m_to_eia608_init,
88+ .filter = ff_smpte436m_to_eia608_filter,
89+};

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t