[FFmpeg-devel] [PATCH] Decoding of raw UTF-8 text from Ogg streams

Michael Niedermayer michaelni
Mon Aug 3 23:44:07 CEST 2009


On Wed, Jul 29, 2009 at 05:55:10PM +0100, ogg.k.ogg.k at googlemail.com wrote:
> And with a temporary copy of the packet so we can add a
> terminating zero to avoid sscanf potentially going off allocated
> memory.
[...]
> +static void find_timing(const AVPacket *avpkt, const AVRational *time_base,
> +                        uint32_t *start, uint32_t *end)
> +{
> +    int hour0, min0, sec0, hsec0;
> +    int hour1, min1, sec1, hsec1;
> +    uint32_t start_ms, end_ms, pts_ms;
> +    char *copy;
> +
> +    *start = 0;
> +    *end   = 0;
> +
> +    copy = av_malloc(avpkt->size+1);
> +    if (!copy)
> +      return;
> +    memcpy(copy, avpkt->data, avpkt->size);
> +    copy[avpkt->size] = 0;
> +
> +    if (sscanf(copy, "%*[^,],%d:%d:%d%*c%d,%d:%d:%d%*c%d",
> +        &hour0, &min0, &sec0, &hsec0, &hour1, &min1, &sec1, &hsec1) != 8) {
> +        goto end;
> +    }
> +
> +#define CHK(val, mx) if ((val) < 0 || (val) >= (mx)) goto end;
> +    CHK(hour0, INT_MAX);
> +    CHK(hour1, INT_MAX);
> +    CHK(min0,  60);
> +    CHK(min1,  60);
> +    CHK(sec0,  60);
> +    CHK(sec1,  60);
> +    CHK(hsec0, 100);
> +    CHK(hsec1, 100);
> +#undef CHK
> +
> +    /* 1197 hours or so */
> +    start_ms = hour0 * 60*60*1000 + min0 * 60*1000 + sec0 * 1000 + hsec0 * 10;
> +    end_ms   = hour1 * 60*60*1000 + min1 * 60*1000 + sec1 * 1000 + hsec1 * 10;
> +    pts_ms   = 1000 * avpkt->pts * time_base->num / time_base->den;
> +
> +    if (start_ms < pts_ms || end_ms < start_ms)
> +        goto end;
> +
> +    *start = start_ms - pts_ms;
> +    *end   = end_ms - pts_ms;

i would have expected

*start = 0
*end = end_ms - start_ms

is your code causing things to be displayed at the correct times?

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Complexity theory is the science of finding the exact solution to an
approximation. Benchmarking OTOH is finding an approximation of the exact
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20090803/c72ca2c4/attachment.pgp>



More information about the ffmpeg-devel mailing list