[FFmpeg-devel] [PATCH] Text subtitle decoder
Aurelien Jacobs
aurel
Sat Nov 27 18:16:45 CET 2010
On Sat, Nov 27, 2010 at 09:43:01PM +1100, Peter Ross wrote:
> $subject (Purging my patch queue.)
>
> -- Peter
> (A907 E02F A6E5 0CD2 34CD 20D2 6760 79C5 AC40 DD6B)
> From 58ad4d115131b111100b750228b5afb64829ca18 Mon Sep 17 00:00:00 2001
> From: Peter Ross <pross at xvid.org>
> Date: Sat, 27 Nov 2010 21:28:20 +1100
> Subject: [PATCH] Text subtitle decoder
>
> ---
> Changelog | 1 +
> libavcodec/Makefile | 1 +
> libavcodec/allcodecs.c | 1 +
> libavcodec/text.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++
> 4 files changed, 64 insertions(+), 0 deletions(-)
> create mode 100644 libavcodec/text.c
>
> [...]
>
> diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
> index fbae0f6..3aa28b2 100644
> --- a/libavcodec/allcodecs.c
> +++ b/libavcodec/allcodecs.c
> @@ -346,6 +346,7 @@ void avcodec_register_all(void)
> REGISTER_ENCDEC (DVBSUB, dvbsub);
> REGISTER_ENCDEC (DVDSUB, dvdsub);
> REGISTER_DECODER (PGSSUB, pgssub);
> + REGISTER_ENCDEC (TEXT, text);
ENCDEC ???
> diff --git a/libavcodec/text.c b/libavcodec/text.c
> new file mode 100644
> index 0000000..5876a94
> --- /dev/null
> +++ b/libavcodec/text.c
> @@ -0,0 +1,61 @@
> +/*
> + * Text subtitle decoder
> + * Copyright (c) 2010 Peter Ross <pross at xvid.org>
> + *
> + * This file is part of FFmpeg.
> + *
> + * FFmpeg is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * FFmpeg is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with FFmpeg; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
> + */
> +
> +#include "avcodec.h"
> +#include "get_bits.h"
> +#include "bytestream.h"
> +
> +static int decode_frame(AVCodecContext *avctx, void *data, int *data_size,
> + AVPacket *avpkt)
> +{
> + const uint8_t *buf = avpkt->data;
> + int buf_size = avpkt->size;
> + AVSubtitle *sub = data;
> + int64_t pts = 0;
> +
> + if (avpkt->pts != AV_NOPTS_VALUE)
> + pts = av_rescale_q(avpkt->pts, AV_TIME_BASE_Q, (AVRational){1, 1000});
> +
> + memset(sub, 0, sizeof(*sub));
> + sub->pts = avpkt->pts;
> + sub->start_display_time = pts;
> + sub->end_display_time = pts + 500;
Why pts + 500 ???
More generally, what is this decoder useful for ?
Currently, there are only 3 demuxers which produce CODEC_ID_TEXT streams:
matroska, nut and ogm.
For both matroska and ogm this is plain wrong to use CODEC_ID_TEXT, as
those streams contains in fact SubRip formated text (including some html
like formatting, like <b>, <font size="20">, etc...). I will fix both of
them very soon now, so that they output CODEC_ID_SRT instead.
So this will leave us with nut as the only demuxer producing
CODEC_ID_TEXT. I don't know if this type of track is really used in
actual files, and if it is a good idea to support this kind "codec"
that is used nowhere else, but my gut feeling says that we should just
drop CODEC_ID_TEXT entirely.
Aurel
More information about the ffmpeg-devel
mailing list