Originally committed as revision 25745 to svn://svn.ffmpeg.org/ffmpeg/trunk
Unified · Split
| @@ -2284,6 +2284,7 @@ static int transcode(AVFormatContext **output_files, · 2283 unmodified lines | ||
| 2284 | 2284 | ost = ost_table[i]; |
| 2285 | 2285 | if (ost->encoding_needed) { |
| 2286 | 2286 | AVCodec *codec = i < nb_output_codecs ? output_codecs[i] : NULL; |
| 2287 | + AVCodecContext *dec = ist_table[ost->source_index]->st->codec; | |
| 2287 | 2288 | if (!codec) |
| 2288 | 2289 | codec = avcodec_find_encoder(ost->st->codec->codec_id); |
| 2289 | 2290 | if (!codec) { |
| @@ -2292,6 +2293,15 @@ static int transcode(AVFormatContext **output_files, · 2 unmodified lines | ||
| 2292 | 2293 | ret = AVERROR(EINVAL); |
| 2293 | 2294 | goto dump_format; |
| 2294 | 2295 | } |
| 2296 | + if (dec->subtitle_header) { | |
| 2297 | + ost->st->codec->subtitle_header = av_malloc(dec->subtitle_header_size); | |
| 2298 | + if (!ost->st->codec->subtitle_header) { | |
| 2299 | + ret = AVERROR(ENOMEM); | |
| 2300 | + goto dump_format; | |
| 2301 | + } | |
| 2302 | + memcpy(ost->st->codec->subtitle_header, dec->subtitle_header, dec->subtitle_header_size); | |
| 2303 | + ost->st->codec->subtitle_header_size = dec->subtitle_header_size; | |
| 2304 | + } | |
| 2295 | 2305 | if (avcodec_open(ost->st->codec, codec) < 0) { |
| 2296 | 2306 | snprintf(error, sizeof(error), "Error while opening encoder for output stream #%d.%d - maybe incorrect parameters such as bit_rate, rate, width or height", |
| 2297 | 2307 | ost->file_index, ost->index); |
| @@ -2690,6 +2700,7 @@ static int transcode(AVFormatContext **output_files, · 392 unmodified lines | ||
| 2690 | 2700 | } |
| 2691 | 2701 | av_fifo_free(ost->fifo); /* works even if fifo is not |
| 2692 | 2702 | initialized but set to zero */ |
| 2703 | + av_freep(&ost->st->codec->subtitle_header); | |
| 2693 | 2704 | av_free(ost->pict_tmp.data[0]); |
| 2694 | 2705 | av_free(ost->forced_kf_pts); |
| 2695 | 2706 | if (ost->video_resample) |
| @@ -2757,6 +2757,17 @@ typedef struct AVCodecContext { · 2756 unmodified lines | ||
| 2757 | 2757 | * - decoding: unused |
| 2758 | 2758 | */ |
| 2759 | 2759 | int slices; |
| 2760 | + | |
| 2761 | + /** | |
| 2762 | + * Header containing style information for text subtitles. | |
| 2763 | + * For SUBTITLE_ASS subtitle type, it should contain the whole ASS | |
| 2764 | + * [Script Info] and [V4+ Styles] section, plus the [Events] line and | |
| 2765 | + * the Format line following. It shouldn't include any Dialogue line. | |
| 2766 | + * - encoding: Set/allocated/freed by user (before avcodec_open()) | |
| 2767 | + * - decoding: Set/allocated/freed by libavcodec (by avcodec_open()) | |
| 2768 | + */ | |
| 2769 | + uint8_t *subtitle_header; | |
| 2770 | + int subtitle_header_size; | |
| 2760 | 2771 | } AVCodecContext; |
| 2761 | 2772 | |
| 2762 | 2773 | /** |
| @@ -2206,9 +2206,14 @@ int av_find_stream_info(AVFormatContext *ic) · 2205 unmodified lines | ||
| 2206 | 2206 | if (codec && codec->capabilities & CODEC_CAP_CHANNEL_CONF) |
| 2207 | 2207 | st->codec->channels = 0; |
| 2208 | 2208 | |
| 2209 | + /* Ensure that subtitle_header is properly set. */ | |
| 2210 | + if (st->codec->codec_type == AVMEDIA_TYPE_SUBTITLE | |
| 2211 | + && codec && !st->codec->codec) | |
| 2212 | + avcodec_open(st->codec, codec); | |
| 2213 | + | |
| 2209 | 2214 | //try to just open decoders, in case this is enough to get parameters |
| 2210 | 2215 | if(!has_codec_parameters(st->codec)){ |
| 2211 | − if (codec) | |
| 2216 | + if (codec && !st->codec->codec) | |
| 2212 | 2217 | avcodec_open(st->codec, codec); |
| 2213 | 2218 | } |
| 2214 | 2219 | } |
| @@ -2471,6 +2476,7 @@ void av_close_input_stream(AVFormatContext *s) · 256 unmodified lines | ||
| 2471 | 2476 | av_metadata_free(&st->metadata); |
| 2472 | 2477 | av_free(st->index_entries); |
| 2473 | 2478 | av_free(st->codec->extradata); |
| 2479 | + av_free(st->codec->subtitle_header); | |
| 2474 | 2480 | av_free(st->codec); |
| 2475 | 2481 | #if FF_API_OLD_METADATA |
| 2476 | 2482 | av_free(st->filename); |