Unified · Split
| @@ -3539,6 +3539,7 @@ h264_redundant_pps_bsf_select="cbs_h264" · 3538 unmodified lines | |||
| 3539 | hevc_metadata_bsf_select="cbs_h265" | 3539 | hevc_metadata_bsf_select="cbs_h265" |
| 3540 | mjpeg2jpeg_bsf_select="jpegtables" | 3540 | mjpeg2jpeg_bsf_select="jpegtables" |
| 3541 | mpeg2_metadata_bsf_select="cbs_mpeg2" | 3541 | mpeg2_metadata_bsf_select="cbs_mpeg2" |
| 3542 | smpte436m_to_eia608_bsf_select="smpte_436m" | ||
| 3542 | trace_headers_bsf_select="cbs cbs_vp8" | 3543 | trace_headers_bsf_select="cbs cbs_vp8" |
| 3543 | vp9_metadata_bsf_select="cbs_vp9" | 3544 | vp9_metadata_bsf_select="cbs_vp9" |
| 3544 | vvc_metadata_bsf_select="cbs_h266" | 3545 | vvc_metadata_bsf_select="cbs_h266" |
| @@ -948,6 +948,11 @@ ffmpeg -i INPUT -c:a copy -bsf:a setts=pts=DTS out.mkv · 947 unmodified lines | |||
| 948 | Log basic packet information. Mainly useful for testing, debugging, | 948 | Log basic packet information. Mainly useful for testing, debugging, |
| 949 | and development. | 949 | and development. |
| 950 | 950 | ||
| 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 | |||
| 951 | @anchor{text2movsub} | 956 | @anchor{text2movsub} |
| 952 | @section text2movsub | 957 | @section text2movsub |
| 953 | 958 | ||
| @@ -61,6 +61,7 @@ extern const FFBitStreamFilter ff_prores_metadata_bsf; · 60 unmodified lines | |||
| 61 | extern const FFBitStreamFilter ff_remove_extradata_bsf; | 61 | extern const FFBitStreamFilter ff_remove_extradata_bsf; |
| 62 | extern const FFBitStreamFilter ff_setts_bsf; | 62 | extern const FFBitStreamFilter ff_setts_bsf; |
| 63 | extern const FFBitStreamFilter ff_showinfo_bsf; | 63 | extern const FFBitStreamFilter ff_showinfo_bsf; |
| 64 | extern const FFBitStreamFilter ff_smpte436m_to_eia608_bsf; | ||
| 64 | extern const FFBitStreamFilter ff_text2movsub_bsf; | 65 | extern const FFBitStreamFilter ff_text2movsub_bsf; |
| 65 | extern const FFBitStreamFilter ff_trace_headers_bsf; | 66 | extern const FFBitStreamFilter ff_trace_headers_bsf; |
| 66 | extern const FFBitStreamFilter ff_truehd_core_bsf; | 67 | extern const FFBitStreamFilter ff_truehd_core_bsf; |
| @@ -38,6 +38,7 @@ OBJS-$(CONFIG_PRORES_METADATA_BSF) += bsf/prores_metadata.o · 37 unmodified lines | |||
| 38 | OBJS-$(CONFIG_REMOVE_EXTRADATA_BSF) += bsf/remove_extradata.o | 38 | OBJS-$(CONFIG_REMOVE_EXTRADATA_BSF) += bsf/remove_extradata.o |
| 39 | OBJS-$(CONFIG_SETTS_BSF) += bsf/setts.o | 39 | OBJS-$(CONFIG_SETTS_BSF) += bsf/setts.o |
| 40 | OBJS-$(CONFIG_SHOWINFO_BSF) += bsf/showinfo.o | 40 | OBJS-$(CONFIG_SHOWINFO_BSF) += bsf/showinfo.o |
| 41 | OBJS-$(CONFIG_SMPTE436M_TO_EIA608_BSF) += bsf/smpte436m_to_eia608.o | ||
| 41 | OBJS-$(CONFIG_TEXT2MOVSUB_BSF) += bsf/movsub.o | 42 | OBJS-$(CONFIG_TEXT2MOVSUB_BSF) += bsf/movsub.o |
| 42 | OBJS-$(CONFIG_TRACE_HEADERS_BSF) += bsf/trace_headers.o | 43 | OBJS-$(CONFIG_TRACE_HEADERS_BSF) += bsf/trace_headers.o |
| 43 | OBJS-$(CONFIG_TRUEHD_CORE_BSF) += bsf/truehd_core.o | 44 | OBJS-$(CONFIG_TRUEHD_CORE_BSF) += bsf/truehd_core.o |
| @@ -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 | }; | ||