diff --git a/src/media_object.cpp b/src/media_object.cpp index 0878e48..93dbbff 100644 --- a/src/media_object.cpp +++ b/src/media_object.cpp @@ -752,14 +752,18 @@ void media_object::open(const std::string &url) msg::dbg(_url + " stream " + str::from(i) + " is subtitle stream " + str::from(j) + "."); _ffmpeg->subtitle_codec_ctxs.push_back(_ffmpeg->format_ctx->streams[i]->codec); _ffmpeg->subtitle_codecs.push_back(avcodec_find_decoder(_ffmpeg->subtitle_codec_ctxs[j]->codec_id)); - if (!_ffmpeg->subtitle_codecs[j]) + // CODEC_ID_TEXT does not have any decoder + if (_ffmpeg->subtitle_codecs[j] || _ffmpeg->subtitle_codec_ctxs[j]->codec_id != CODEC_ID_TEXT) { - throw exc(_url + " stream " + str::from(i) + ": Unsupported subtitle codec."); - } - if ((e = avcodec_open(_ffmpeg->subtitle_codec_ctxs[j], _ffmpeg->subtitle_codecs[j])) < 0) - { - _ffmpeg->subtitle_codecs[j] = NULL; - throw exc(_url + " stream " + str::from(i) + ": Cannot open subtitle codec: " + my_av_strerror(e)); + if (!_ffmpeg->subtitle_codecs[j]) + { + throw exc(_url + " stream " + str::from(i) + ": Unsupported subtitle codec."); + } + if ((e = avcodec_open(_ffmpeg->subtitle_codec_ctxs[j], _ffmpeg->subtitle_codecs[j])) < 0) + { + _ffmpeg->subtitle_codecs[j] = NULL; + throw exc(_url + " stream " + str::from(i) + ": Cannot open subtitle codec: " + my_av_strerror(e)); + } } _ffmpeg->subtitle_box_templates.push_back(subtitle_box()); set_subtitle_box_template(j); @@ -1453,6 +1457,27 @@ void subtitle_decode_thread::run() AVSubtitle subtitle; int got_subtitle; tmppacket = packet; + + // XXX CODEC_ID_TEXT does not have any decoder. Just use raw UTF-8 data from packet + if(_ffmpeg->subtitle_codec_ctxs[_subtitle_stream]->codec_id == CODEC_ID_TEXT) + { + int64_t duration = packet.convergence_duration * 1000000 + * _ffmpeg->format_ctx->streams[_ffmpeg->subtitle_streams[_subtitle_stream]]->time_base.num + / _ffmpeg->format_ctx->streams[_ffmpeg->subtitle_streams[_subtitle_stream]]->time_base.den; + + // Put it in the subtitle buffer + subtitle_box box = _ffmpeg->subtitle_box_templates[_subtitle_stream]; + box.presentation_start_time = timestamp; + box.presentation_stop_time = timestamp + duration; + + box.format = subtitle_box::text; + box.str += reinterpret_cast(packet.data); + + _ffmpeg->subtitle_box_buffers[_subtitle_stream].push_back(box); + + tmppacket.size = 0; + } + while (tmppacket.size > 0) { int len = avcodec_decode_subtitle2(_ffmpeg->subtitle_codec_ctxs[_subtitle_stream],