mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2024-12-23 12:43:46 +02:00
allow passing subtitles header between decoder and encoder
Originally committed as revision 25745 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
parent
2722dd6ebf
commit
cb2c971d91
11
ffmpeg.c
11
ffmpeg.c
@ -2284,6 +2284,7 @@ static int transcode(AVFormatContext **output_files,
|
|||||||
ost = ost_table[i];
|
ost = ost_table[i];
|
||||||
if (ost->encoding_needed) {
|
if (ost->encoding_needed) {
|
||||||
AVCodec *codec = i < nb_output_codecs ? output_codecs[i] : NULL;
|
AVCodec *codec = i < nb_output_codecs ? output_codecs[i] : NULL;
|
||||||
|
AVCodecContext *dec = ist_table[ost->source_index]->st->codec;
|
||||||
if (!codec)
|
if (!codec)
|
||||||
codec = avcodec_find_encoder(ost->st->codec->codec_id);
|
codec = avcodec_find_encoder(ost->st->codec->codec_id);
|
||||||
if (!codec) {
|
if (!codec) {
|
||||||
@ -2292,6 +2293,15 @@ static int transcode(AVFormatContext **output_files,
|
|||||||
ret = AVERROR(EINVAL);
|
ret = AVERROR(EINVAL);
|
||||||
goto dump_format;
|
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) {
|
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",
|
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);
|
ost->file_index, ost->index);
|
||||||
@ -2690,6 +2700,7 @@ static int transcode(AVFormatContext **output_files,
|
|||||||
}
|
}
|
||||||
av_fifo_free(ost->fifo); /* works even if fifo is not
|
av_fifo_free(ost->fifo); /* works even if fifo is not
|
||||||
initialized but set to zero */
|
initialized but set to zero */
|
||||||
|
av_freep(&ost->st->codec->subtitle_header);
|
||||||
av_free(ost->pict_tmp.data[0]);
|
av_free(ost->pict_tmp.data[0]);
|
||||||
av_free(ost->forced_kf_pts);
|
av_free(ost->forced_kf_pts);
|
||||||
if (ost->video_resample)
|
if (ost->video_resample)
|
||||||
|
@ -2757,6 +2757,17 @@ typedef struct AVCodecContext {
|
|||||||
* - decoding: unused
|
* - decoding: unused
|
||||||
*/
|
*/
|
||||||
int slices;
|
int slices;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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;
|
} AVCodecContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -2206,9 +2206,14 @@ int av_find_stream_info(AVFormatContext *ic)
|
|||||||
if (codec && codec->capabilities & CODEC_CAP_CHANNEL_CONF)
|
if (codec && codec->capabilities & CODEC_CAP_CHANNEL_CONF)
|
||||||
st->codec->channels = 0;
|
st->codec->channels = 0;
|
||||||
|
|
||||||
|
/* Ensure that subtitle_header is properly set. */
|
||||||
|
if (st->codec->codec_type == AVMEDIA_TYPE_SUBTITLE
|
||||||
|
&& codec && !st->codec->codec)
|
||||||
|
avcodec_open(st->codec, codec);
|
||||||
|
|
||||||
//try to just open decoders, in case this is enough to get parameters
|
//try to just open decoders, in case this is enough to get parameters
|
||||||
if(!has_codec_parameters(st->codec)){
|
if(!has_codec_parameters(st->codec)){
|
||||||
if (codec)
|
if (codec && !st->codec->codec)
|
||||||
avcodec_open(st->codec, codec);
|
avcodec_open(st->codec, codec);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2471,6 +2476,7 @@ void av_close_input_stream(AVFormatContext *s)
|
|||||||
av_metadata_free(&st->metadata);
|
av_metadata_free(&st->metadata);
|
||||||
av_free(st->index_entries);
|
av_free(st->index_entries);
|
||||||
av_free(st->codec->extradata);
|
av_free(st->codec->extradata);
|
||||||
|
av_free(st->codec->subtitle_header);
|
||||||
av_free(st->codec);
|
av_free(st->codec);
|
||||||
#if FF_API_OLD_METADATA
|
#if FF_API_OLD_METADATA
|
||||||
av_free(st->filename);
|
av_free(st->filename);
|
||||||
|
Loading…
Reference in New Issue
Block a user