MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / avcodec_decode_subtitle2

Function avcodec_decode_subtitle2

libavcodec/decode.c:916–985  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

914}
915
916int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub,
917 int *got_sub_ptr, const AVPacket *avpkt)
918{
919 int ret = 0;
920
921 if (!avpkt->data && avpkt->size) {
922 av_log(avctx, AV_LOG_ERROR, "invalid packet: NULL data, size != 0\n");
923 return AVERROR(EINVAL);
924 }
925 if (!avctx->codec)
926 return AVERROR(EINVAL);
927 if (ffcodec(avctx->codec)->cb_type != FF_CODEC_CB_TYPE_DECODE_SUB) {
928 av_log(avctx, AV_LOG_ERROR, "Codec not subtitle decoder\n");
929 return AVERROR(EINVAL);
930 }
931
932 *got_sub_ptr = 0;
933 get_subtitle_defaults(sub);
934
935 if ((avctx->codec->capabilities & AV_CODEC_CAP_DELAY) || avpkt->size) {
936 AVCodecInternal *avci = avctx->internal;
937 const AVPacket *pkt;
938
939 ret = recode_subtitle(avctx, &pkt, avpkt, avci->buffer_pkt);
940 if (ret < 0)
941 return ret;
942
943 if (avctx->pkt_timebase.num && avpkt->pts != AV_NOPTS_VALUE)
944 sub->pts = av_rescale_q(avpkt->pts,
945 avctx->pkt_timebase, AV_TIME_BASE_Q);
946 ret = ffcodec(avctx->codec)->cb.decode_sub(avctx, sub, got_sub_ptr, pkt);
947 if (pkt == avci->buffer_pkt) // did we recode?
948 av_packet_unref(avci->buffer_pkt);
949 if (ret < 0) {
950 *got_sub_ptr = 0;
951 avsubtitle_free(sub);
952 return ret;
953 }
954 av_assert1(!sub->num_rects || *got_sub_ptr);
955
956 if (sub->num_rects && !sub->end_display_time && avpkt->duration &&
957 avctx->pkt_timebase.num) {
958 AVRational ms = { 1, 1000 };
959 sub->end_display_time = av_rescale_q(avpkt->duration,
960 avctx->pkt_timebase, ms);
961 }
962
963 if (avctx->codec_descriptor->props & AV_CODEC_PROP_BITMAP_SUB)
964 sub->format = 0;
965 else if (avctx->codec_descriptor->props & AV_CODEC_PROP_TEXT_SUB)
966 sub->format = 1;
967
968 for (unsigned i = 0; i < sub->num_rects; i++) {
969 if (avctx->sub_charenc_mode != FF_SUB_CHARENC_MODE_IGNORE &&
970 sub->rects[i]->ass && !utf8_check(sub->rects[i]->ass)) {
971 av_log(avctx, AV_LOG_ERROR,
972 "Invalid UTF-8 in decoded subtitles text; "
973 "maybe missing -sub_charenc option\n");

Callers 6

subtitle_handlerFunction · 0.85
try_decode_frameFunction · 0.85
decoder_decode_frameFunction · 0.85
transcode_subtitlesFunction · 0.85
process_frameFunction · 0.85
init_subtitlesFunction · 0.85

Calls 8

av_logFunction · 0.85
ffcodecFunction · 0.85
get_subtitle_defaultsFunction · 0.85
recode_subtitleFunction · 0.85
av_rescale_qFunction · 0.85
av_packet_unrefFunction · 0.85
avsubtitle_freeFunction · 0.85
utf8_checkFunction · 0.85

Tested by

no test coverage detected