[FFmpeg-devel] [PATCH 2/3] movenc: Handle need for extra packets to express subtitle duration.

Clément Bœsch ubitux at gmail.com
Sun Jul 29 12:01:39 CEST 2012


On Thu, Jul 26, 2012 at 08:37:52PM -0700, Philip Langdale wrote:
> As packet duration is not stored inherently in MPEG4 containers,
> subtitles have their duration expressed by storing an additional
> empty packet with a pts matching the desired end time of the real
> subtitle. Additionally, it is generally expected that all streams
> start at time = 0, so an empty packet needs to be inserted at the
> beginning of the stream, before the first real subtitle.
> 
> Unfortunately, ffmpeg lacks a proper way to express that a subtitle
> might map to multiple packets, so the muxer is the only place we
> can handle this.
> 
> Signed-off-by: Philip Langdale <philipl at overt.org>
> ---
>  libavformat/movenc.c |   88 ++++++++++++++++++++++++++++++++++++++++++++++----
>  libavformat/movenc.h |    1 +
>  2 files changed, 83 insertions(+), 6 deletions(-)
> 
[...]
> +static int mov_write_packet(AVFormatContext *s, AVPacket *pkt)
> +{
> +    if (!pkt) {
> +        mov_flush_fragment(s);
> +        return 1;
> +    } else {
> +        MOVMuxContext *mov = s->priv_data;
> +
> +        if (!pkt->size) return 0; /* Discard 0 sized packets */
> +
> +        /*
> +         * Subtitles require special handling.
> +         *
> +         * 1) For full complaince, every track must have a sample at

compliance

> +         * dts == 0, which is rarely true for subtitles. So, as soon

I'm not sure that's rarely true; I have 5 SRT at 00:00:00.000 in my
collection. Of course the text is not part of the movie (various credits,
disclaimer etc). Will they be remuxed?

> +         * as we see any packet with dts > 0, write an empty subtitle
> +         * at dts == 0 for any subtitle track with no samples in it.
> +         *
> +         * 2) For each subtitle track, check if the current packet's
> +         * dts is past the duration of the last subtitle sample. If
> +         * so, we now need to write an end sample for that subtitle.
> +         *
> +         * This must be done conditionally to allow for subtitles that
> +         * immediately replace each other, in which case an end sample
> +         * is not needed, and is, in fact, actively harmful.
> +         *
> +         * 3) See mov_write_trailer for how the final end sample is
> +         * handled.
> +         */
> +        for (int i = 0; i < mov->nb_streams; i++) {

Please move the int outside the for; it seems we are still undecided about
that syntax so better keep it consistent with the rest of the code.

[...]

-- 
Clément B.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 490 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20120729/16de9832/attachment.asc>


More information about the ffmpeg-devel mailing list