Index: external/FFmpeg/ffmpeg.c =================================================================== --- external/FFmpeg/ffmpeg.c (revision 27125) +++ external/FFmpeg/ffmpeg.c (working copy) @@ -2331,6 +2331,7 @@ ost = ost_table[i]; if (ost->encoding_needed) { AVCodec *codec = output_codecs[i]; + AVCodecContext *dec = ist_table[ost->source_index]->st->codec; if (!codec) codec = avcodec_find_encoder(ost->st->codec->codec_id); if (!codec) { @@ -2339,6 +2340,15 @@ ret = AVERROR(EINVAL); goto dump_format; } + if (dec->subtitle_header) { + ost->st->codec->subtitle_header = av_malloc(dec->subtitle_header_size); + if (!ost->st->codec->subtitle_header) { + ret = AVERROR(ENOMEM); + goto dump_format; + } + memcpy(ost->st->codec->subtitle_header, dec->subtitle_header, dec->subtitle_header_size); + ost->st->codec->subtitle_header_size = dec->subtitle_header_size; + } if (avcodec_open(ost->st->codec, codec) < 0) { snprintf(error, sizeof(error), "Error while opening encoder for output stream #%d.%d - maybe incorrect parameters such as bit_rate, rate, width or height", ost->file_index, ost->index); @@ -2693,6 +2703,7 @@ } av_fifo_free(ost->fifo); /* works even if fifo is not initialized but set to zero */ + av_freep(&ost->st->codec->subtitle_header); av_free(ost->pict_tmp.data[0]); if (ost->video_resample) sws_freeContext(ost->img_resample_ctx); Index: external/FFmpeg/libavcodec/avcodec.h =================================================================== --- external/FFmpeg/libavcodec/avcodec.h (revision 27125) +++ external/FFmpeg/libavcodec/avcodec.h (working copy) @@ -2742,6 +2742,17 @@ * - decoding: set by decoder */ int xvmc_vld_hwslice; + + /** + * Header containing style information for text subtitles. + * For SUBTITLE_ASS subtitle type, it should contain the whole ASS + * [Script Info] and [V4+ Styles] section, plus the [Events] line and + * the Format line following. It shouldn't include any Dialogue line. + * - encoding: Set/allocated/freed by user (before avcodec_open()) + * - decoding: Set/allocated/freed by libavcodec (by avcodec_open()) + */ + uint8_t *subtitle_header; + int subtitle_header_size; } AVCodecContext; /** Index: external/FFmpeg/libavformat/utils.c =================================================================== --- external/FFmpeg/libavformat/utils.c (revision 27125) +++ external/FFmpeg/libavformat/utils.c (working copy) @@ -2271,12 +2271,20 @@ st->parser->flags |= PARSER_FLAG_COMPLETE_FRAMES; } } + assert(!st->codec->codec); + //try to just open decoders, in case this is enough to get parameters if(!has_codec_parameters(st->codec)){ AVCodec *codec = avcodec_find_decoder(st->codec->codec_id); - if (codec) + + /* Ensure that subtitle_header is properly set. */ + if (st->codec->codec_type == AVMEDIA_TYPE_SUBTITLE + && codec && !st->codec->codec) avcodec_open(st->codec, codec); + + if (codec && !st->codec->codec) + avcodec_open(st->codec, codec); } } @@ -2547,6 +2554,7 @@ av_metadata_free(&st->metadata); av_free(st->index_entries); av_free(st->codec->extradata); + av_free(st->codec->subtitle_header); av_free(st->codec); #if FF_API_OLD_METADATA av_free(st->filename);