[FFmpeg-devel] [PATCH v4 04/18] avcodec/avcodec: Add av_get_subtitle_format_from_codecdesc function
Soft Works
softworkz at hotmail.com
Sat Sep 11 11:16:33 EEST 2021
Introduce a single place for deriving an AVSubtitleType
from AV_CODEC_PROP_xxx
Signed-off-by: softworkz <softworkz at hotmail.com>
---
libavcodec/avcodec.h | 8 ++++++++
libavcodec/decode.c | 5 +----
libavcodec/utils.c | 11 +++++++++++
3 files changed, 20 insertions(+), 4 deletions(-)
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index b459c23ac7..0f71b42d61 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -3059,6 +3059,14 @@ void avcodec_flush_buffers(AVCodecContext *avctx);
*/
int av_get_audio_frame_duration(AVCodecContext *avctx, int frame_bytes);
+/**
+ * Return subtitle format from a codec descriptor
+ *
+ * @param codec_descriptor codec descriptor
+ * @return the subtitle type (e.g. bitmap, text)
+ */
+enum AVSubtitleType av_get_subtitle_format_from_codecdesc(const AVCodecDescriptor *codec_descriptor);
+
/* memory */
/**
diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index 643f9d6a30..dfec9711ed 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -841,10 +841,7 @@ int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub,
avctx->pkt_timebase, ms);
}
- if (avctx->codec_descriptor->props & AV_CODEC_PROP_BITMAP_SUB)
- sub->format = 0;
- else if (avctx->codec_descriptor->props & AV_CODEC_PROP_TEXT_SUB)
- sub->format = 1;
+ sub->format = av_get_subtitle_format_from_codecdesc(avctx->codec_descriptor);
for (unsigned i = 0; i < sub->num_rects; i++) {
if (avctx->sub_charenc_mode != FF_SUB_CHARENC_MODE_IGNORE &&
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index cfc07cbcb8..767dfabd1e 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -818,6 +818,17 @@ int av_get_audio_frame_duration(AVCodecContext *avctx, int frame_bytes)
return FFMAX(0, duration);
}
+enum AVSubtitleType av_get_subtitle_format_from_codecdesc(const AVCodecDescriptor *codec_descriptor)
+{
+ if(codec_descriptor->props & AV_CODEC_PROP_BITMAP_SUB)
+ return AV_SUBTITLE_FMT_BITMAP;
+
+ if(codec_descriptor->props & AV_CODEC_PROP_TEXT_SUB)
+ return AV_SUBTITLE_FMT_ASS;
+
+ return AV_SUBTITLE_FMT_UNKNOWN;
+}
+
int av_get_audio_frame_duration2(AVCodecParameters *par, int frame_bytes)
{
int duration = get_audio_frame_duration(par->codec_id, par->sample_rate,
--
2.30.2.windows.1
More information about the ffmpeg-devel
mailing list