[FFmpeg-devel] LRC (music lyrics) muxer and demuxer

Aurelien Jacobs aurel
Wed Dec 29 21:17:09 CET 2010


On Wed, Dec 29, 2010 at 04:07:15PM +1100, Peter Ross wrote:
> On Sun, Dec 26, 2010 at 10:00:59PM +0100, Aurelien Jacobs wrote:
> > On Sun, Dec 26, 2010 at 11:45:50PM +1100, Peter Ross wrote:
> > > Typical sample: http://lrc.awardspace.us/lrc/Evanescence-Missing.lrc
> > 
> > First some general comments.
> > 
> > [...]
> > 
> > Also, I wonder how we will generate AVSubtitle.end_display_time in the
> > decoder ? In LRC, the start time of the next frame is the end time of
> > current frame. The decoder could wait for the next frame before
> > returning current frame, adding a 1 frame delay, but with subtitles, the
> > time between two frames can be really long and the video would continue
> > to decode while the subtitle is waiting for next frame to appear to know
> > the end time of the frame which is supposed to be displayed now. So I
> > guess this wouldn't really work.
> > Any idea about how we could handle this ?
> 
> If the demuxer parses the entire file at file_open() time, then it can
> calculate the duration and pass that onto the decoder via AVPacket->duration.

AVPacket->duration is generally not appropriate for subtitles, because
it don't represent the time during which a subtitle must be displayed.
It represent the time difference between the pts of one packet and the
next one.
But in this specific case where we have no end time in the file and that
every subtitle is supposed to be displayed until the start of the next
one, AVPacket->duration seems perfectly appropriate (as long as we don't
drop packets with "blank" lyric).
So the LRC demuxer should indeed set AVPacket->duration and it should
output blank lyric the same way that it output any other lyric.

> > Now about the code itself.
> > 
> > > [...]
> > > +static int read_header(AVFormatContext *s, AVFormatParameters *ap)
> > > +{
> > > +    AVStream *st = av_new_stream(s, 0);
> > > +    if (!st)
> > > +        return -1;
> > > +    st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE;
> > > +    st->codec->codec_id   = CODEC_ID_TEXT;
> > > +    st->start_time        = 0;
> > > +    av_set_pts_info(st, 64, 1, 100);
> > 
> > > +    ff_metadata_conv_ctx(s, ff_lrc_metadata_conv, NULL);
> > 
> > What is this ff_metadata_conv_ctx() good for ?
> 
> That tells ffmpeg to automatically translate betwen the LRC metadata keys
> and the generic ffmpeg keys. e.g. 'ti' == 'title'. Somebody feel free
> to correct me on this.

Well, yes, I know what's the purpose of this function. But here, you
call it in read_header(), before any single bit for the input bitstream
is read. So I doubt there will ever be any metadata to convert in the
context at this point...

> > > [...]
> > > +AVInputFormat lrc_demuxer = {
> > > +    .name           = "lrc",
> > 
> > > +    .long_name      = NULL_IF_CONFIG_SMALL("LRC"),
> > 
> > Not a very descriptive long name...
> 
> 'LRC lyrics'? Suggestions welcome.

Yes, that's better. Probably good enough if nobody has a better
suggestion.

Aurel



More information about the ffmpeg-devel mailing list