[FFmpeg-devel] [PATCH] lavf: JSON captions demuxer.
Clément Bœsch
ubitux at gmail.com
Sat Nov 24 22:28:54 CET 2012
On Wed, Nov 21, 2012 at 01:55:34PM +0100, Nicolas George wrote:
[...]
> + pkt = ff_subtitles_queue_insert(subs, content.str, content.len, 0);
> + if (!pkt)
> + return AVERROR(ENOMEM);
> + pkt->pos = pos;
> + pkt->dts =
> + pkt->pts = start;
You don't need to set dts, it will be set automatically in
ff_subtitles_queue_read_packet()
> + pkt->duration = duration;
> + av_bprint_finalize(&content, NULL);
> +
> + skip_spaces(pb, &cur_byte);
> + if (cur_byte != ',')
> + break;
> + next_byte(pb, &cur_byte);
> + }
> + ret = expect_byte(pb, &cur_byte, ']');
> + if (ret < 0)
> + return ret;
> + ret = expect_byte(pb, &cur_byte, '}');
> + if (ret < 0)
> + return ret;
> + skip_spaces(pb, &cur_byte);
> + if (cur_byte != AVERROR_EOF)
> + return ERR_CODE(cur_byte);
> + return 0;
> +}
> +
[...]
> +static av_cold int tedcaptions_read_probe(AVProbeData *p)
> +{
> + static const char *const tags[] = {
> + "\"captions\"", "\"duration\"", "\"content\"",
> + "\"startOfParagraph\"", "\"startTime\"",
> + };
> + unsigned i, count = 0;
> + const char *t;
> +
> + if (p->buf[strspn(p->buf, " \t\r\n")] != '{')
> + return 0;
> + for (i = 0; i < FF_ARRAY_ELEMS(tags); i++) {
> + if (!(t = strstr(p->buf, tags[i])))
> + continue;
> + t += strlen(tags[i]);
> + t += strspn(t, " \t\r\n");
> + if (*t == ':')
> + count++;
> + }
> + return count == FF_ARRAY_ELEMS(tags) ? AVPROBE_SCORE_MAX :
> + count ? AVPROBE_SCORE_MAX / 2 : 0;
> +}
> +
Nice :)
> +AVInputFormat ff_tedcaptions_demuxer = {
> + .name = "tedcaptions",
> + .long_name = NULL_IF_CONFIG_SMALL("TED Talks captions"),
> + .priv_data_size = sizeof(TEDCaptionsDemuxer),
> + .read_header = tedcaptions_read_header,
> + .read_packet = tedcaptions_read_packet,
> + .read_close = tedcaptions_read_close,
> + .read_probe = tedcaptions_read_probe,
> + .priv_class = &tedcaptions_demuxer_class,
> +};
Thanks, LGTM.
--
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/20121124/cc5276a5/attachment.asc>
More information about the ffmpeg-devel
mailing list