[FFmpeg-devel] [PATCH 1/2] allow passing subtitles header between decoder and encoder
Michael Niedermayer
michaelni
Sat Oct 23 21:57:26 CEST 2010
On Tue, Oct 19, 2010 at 09:55:47PM +0200, Aurelien Jacobs wrote:
> On Tue, Oct 19, 2010 at 03:43:52PM +0200, Michael Niedermayer wrote:
> > On Sat, Oct 16, 2010 at 05:31:26PM +0200, Aurelien Jacobs wrote:
> > > ---
> > > ffmpeg.c | 11 +++++++++++
> > > libavcodec/avcodec.h | 8 ++++++++
> > > libavcodec/utils.c | 2 ++
> > > libavformat/utils.c | 4 ++++
> > > 4 files changed, 25 insertions(+), 0 deletions(-)
> > >
> > > diff --git a/ffmpeg.c b/ffmpeg.c
> > > index 4f59b2e..7622ccc 100644
> > > --- a/ffmpeg.c
> > > +++ b/ffmpeg.c
> > > @@ -2365,6 +2365,7 @@ static int transcode(AVFormatContext **output_files,
> > > ost = ost_table[i];
> > > if (ost->encoding_needed) {
> > > AVCodec *codec = i < nb_output_codecs ? output_codecs[i] : NULL;
> > > + AVCodecContext *dec = ist_table[ost->source_index]->st->codec;
> > > if (!codec)
> > > codec = avcodec_find_encoder(ost->st->codec->codec_id);
> > > if (!codec) {
> > > @@ -2373,6 +2374,15 @@ static int transcode(AVFormatContext **output_files,
> > > 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);
> > > @@ -2728,6 +2738,7 @@ static int transcode(AVFormatContext **output_files,
> > > }
> > > 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);
> > > diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
> > > index 4bddbaa..ab3cbd9 100644
> > > --- a/libavcodec/avcodec.h
> > > +++ b/libavcodec/avcodec.h
> > > @@ -2744,6 +2744,14 @@ typedef struct AVCodecContext {
> > > * - decoding: unused
> > > */
> > > int lpc_passes;
> > > +
> > > + /**
> > > + * Header containing style information for text subtitles.
> > > + * - 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;
> > >
> > > /**
> >
> > The description should be enough to implement a decoder and a user app and
> > a subtitle renderer based on it. (some common sense and guessing not excluded)
> > but this seems too terse for that
>
> OK. Updated patch.
> I think it should now be enough to implement anything related to this
> field, with a little bit of common sense and the ASS spec around.
>
> > also are you sure every subtitle decoder will be able to set this by
> > avcodec_open() ?
>
> Yes, sure. It wouldn't be very useful anyway to set it later on.
> I've already (started to) implement several decoders (SubRip,
> MicroDVD, Movtext...), and they fits well within this model.
>
> Aurel
> ffmpeg.c | 11 +++++++++++
> libavcodec/avcodec.h | 11 +++++++++++
> libavcodec/utils.c | 2 ++
> libavformat/utils.c | 4 ++++
> 4 files changed, 28 insertions(+)
> b9b8f826f2f0a1ed1472d2c2c9a7159e1e52761c subtitle_header.diff
> commit e8603fddcd3cc99a26168b7a10c653e7d67e215c
> Author: Aurelien Jacobs <aurel at gnuage.org>
> Date: Thu Aug 5 22:12:37 2010 +0200
>
> allow passing subtitles header between decoder and encoder
>
> diff --git a/ffmpeg.c b/ffmpeg.c
> index 4f59b2e..7622ccc 100644
> --- a/ffmpeg.c
> +++ b/ffmpeg.c
> @@ -2365,6 +2365,7 @@ static int transcode(AVFormatContext **output_files,
> ost = ost_table[i];
> if (ost->encoding_needed) {
> AVCodec *codec = i < nb_output_codecs ? output_codecs[i] : NULL;
> + AVCodecContext *dec = ist_table[ost->source_index]->st->codec;
> if (!codec)
> codec = avcodec_find_encoder(ost->st->codec->codec_id);
> if (!codec) {
> @@ -2373,6 +2374,15 @@ static int transcode(AVFormatContext **output_files,
> 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);
> @@ -2728,6 +2738,7 @@ static int transcode(AVFormatContext **output_files,
> }
> 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);
> diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
> index 4bddbaa..99bc7ad 100644
> --- a/libavcodec/avcodec.h
> +++ b/libavcodec/avcodec.h
> @@ -2744,6 +2744,17 @@ typedef struct AVCodecContext {
> * - decoding: unused
> */
> int lpc_passes;
> +
> + /**
> + * 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())
[...]
> @@ -742,6 +742,8 @@ av_cold int avcodec_close(AVCodecContext *avctx)
> av_freep(&avctx->priv_data);
> if(avctx->codec && avctx->codec->encode)
> av_freep(&avctx->extradata);
> + if (avctx->codec && avctx->codec->encode)
> + av_freep(&avctx->subtitle_header);
> avctx->codec = NULL;
> entangled_thread_counter--;
doesnt match
>
> diff --git a/libavformat/utils.c b/libavformat/utils.c
> index 8a08557..a137e69 100644
> --- a/libavformat/utils.c
> +++ b/libavformat/utils.c
> @@ -2022,6 +2022,9 @@ static int has_codec_parameters(AVCodecContext *enc)
> case AVMEDIA_TYPE_VIDEO:
> val = enc->width && enc->pix_fmt != PIX_FMT_NONE;
> break;
> + case AVMEDIA_TYPE_SUBTITLE:
> + val = !!enc->subtitle_header;
> + break;
> default:
> val = 1;
> break;
This will slow every sub title decoder down that never sets this
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
The real ebay dictionary, page 1
"Used only once" - "Some unspecified defect prevented a second use"
"In good condition" - "Can be repaird by experienced expert"
"As is" - "You wouldnt want it even if you were payed for it, if you knew ..."
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20101023/8220ced8/attachment.pgp>
More information about the ffmpeg-devel
mailing list