History

allow passing subtitles header between decoder and encoder

Originally committed as revision 25745 to svn://svn.ffmpeg.org/ffmpeg/trunk

Aurelien Jacobs committed 16 years ago

Commit cb2c9711 parent 2722dd63 files · +29 −1Browse files

Unified · Split

3 files
  1. ffmpeg.c +11 −0
  2. libavcodec/avcodec.h +11 −0
  3. libavformat/utils.c +7 −1
ffmpeg.c+11−0
@@ -2284,6 +2284,7 @@ static int transcode(AVFormatContext **output_files, · 2283 unmodified lines
22842284 ost = ost_table[i];
22852285 if (ost->encoding_needed) {
22862286 AVCodec *codec = i < nb_output_codecs ? output_codecs[i] : NULL;
2287+ AVCodecContext *dec = ist_table[ost->source_index]->st->codec;
22872288 if (!codec)
22882289 codec = avcodec_find_encoder(ost->st->codec->codec_id);
22892290 if (!codec) {
@@ -2292,6 +2293,15 @@ static int transcode(AVFormatContext **output_files, · 2 unmodified lines
22922293 ret = AVERROR(EINVAL);
22932294 goto dump_format;
22942295 }
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+ }
22952305 if (avcodec_open(ost->st->codec, codec) < 0) {
22962306 snprintf(error, sizeof(error), "Error while opening encoder for output stream #%d.%d - maybe incorrect parameters such as bit_rate, rate, width or height",
22972307 ost->file_index, ost->index);
@@ -2690,6 +2700,7 @@ static int transcode(AVFormatContext **output_files, · 392 unmodified lines
26902700 }
26912701 av_fifo_free(ost->fifo); /* works even if fifo is not
26922702 initialized but set to zero */
2703+ av_freep(&ost->st->codec->subtitle_header);
26932704 av_free(ost->pict_tmp.data[0]);
26942705 av_free(ost->forced_kf_pts);
26952706 if (ost->video_resample)
libavcodec/avcodec.h+11−0
@@ -2757,6 +2757,17 @@ typedef struct AVCodecContext { · 2756 unmodified lines
27572757 * - decoding: unused
27582758 */
27592759 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;
27602771 } AVCodecContext;
27612772
27622773 /**
libavformat/utils.c+7−1
@@ -2206,9 +2206,14 @@ int av_find_stream_info(AVFormatContext *ic) · 2205 unmodified lines
22062206 if (codec && codec->capabilities & CODEC_CAP_CHANNEL_CONF)
22072207 st->codec->channels = 0;
22082208
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+
22092214 //try to just open decoders, in case this is enough to get parameters
22102215 if(!has_codec_parameters(st->codec)){
2211− if (codec)
2216+ if (codec && !st->codec->codec)
22122217 avcodec_open(st->codec, codec);
22132218 }
22142219 }
@@ -2471,6 +2476,7 @@ void av_close_input_stream(AVFormatContext *s) · 256 unmodified lines
24712476 av_metadata_free(&st->metadata);
24722477 av_free(st->index_entries);
24732478 av_free(st->codec->extradata);
2479+ av_free(st->codec->subtitle_header);
24742480 av_free(st->codec);
24752481 #if FF_API_OLD_METADATA
24762482 av_free(st->filename);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t