[FFmpeg-devel] [PATCH] AVFormat: LRC demuxer and muxer

Michael Niedermayer michaelni at gmx.at
Sat Jul 12 20:09:06 CEST 2014


On Thu, Jul 10, 2014 at 09:31:57PM +0800, Star Brilliant wrote:
> Some improvements in lrc_probe.
> 
> Updated patch is attached.
> 
> Thanks.

>  Changelog                |    1 
>  doc/general.texi         |    1 
>  libavformat/Makefile     |    2 
>  libavformat/allformats.c |    1 
>  libavformat/lrc.c        |   34 ++++++
>  libavformat/lrc.h        |   29 +++++
>  libavformat/lrcdec.c     |  247 +++++++++++++++++++++++++++++++++++++++++++++++
>  libavformat/lrcenc.c     |  142 +++++++++++++++++++++++++++
>  8 files changed, 457 insertions(+)
> b89208d82122540e5d3c4c5ae4dc7f935ba29e29  0001-AVFormat-LRC-demuxer-and-muxer.patch
> From 6ad46495be298fc7254676b141378295c2238e69 Mon Sep 17 00:00:00 2001
> From: Star Brilliant <m13253 at hotmail.com>
> Date: Wed, 9 Jul 2014 14:24:05 +0800
> Subject: [PATCH] AVFormat: LRC demuxer and muxer
> 
> ---
>  Changelog                |   1 +
>  doc/general.texi         |   1 +
>  libavformat/Makefile     |   2 +
>  libavformat/allformats.c |   1 +
>  libavformat/lrc.c        |  34 +++++++
>  libavformat/lrc.h        |  29 ++++++
>  libavformat/lrcdec.c     | 247 +++++++++++++++++++++++++++++++++++++++++++++++
>  libavformat/lrcenc.c     | 142 +++++++++++++++++++++++++++
>  8 files changed, 457 insertions(+)
>  create mode 100644 libavformat/lrc.c
>  create mode 100644 libavformat/lrc.h
>  create mode 100644 libavformat/lrcdec.c
>  create mode 100644 libavformat/lrcenc.c
> 
> diff --git a/Changelog b/Changelog
> index fa443dc..75bde5b 100644
> --- a/Changelog
> +++ b/Changelog
> @@ -29,6 +29,7 @@ version <next>:
>  - showcqt multimedia filter
>  - zoompan filter
>  - signalstats filter
> +- LRC demuxer and muxer
>  
>  
>  version 2.2:
> diff --git a/doc/general.texi b/doc/general.texi
> index 86569a2..c008261 100644
> --- a/doc/general.texi
> +++ b/doc/general.texi
> @@ -310,6 +310,7 @@ library:
>      @tab Used by Linux Media Labs MPEG-4 PCI boards
>  @item LOAS                      @tab   @tab X
>      @tab contains LATM multiplexed AAC audio
> + at item LRC                       @tab X @tab X
>  @item LVF                       @tab   @tab X
>  @item LXF                       @tab   @tab X
>      @tab VR native stream format, used by Leitch/Harris' video servers.
> diff --git a/libavformat/Makefile b/libavformat/Makefile
> index ecae4d0..3218c4c 100644
> --- a/libavformat/Makefile
> +++ b/libavformat/Makefile
> @@ -202,6 +202,8 @@ OBJS-$(CONFIG_LATM_DEMUXER)              += rawdec.o
>  OBJS-$(CONFIG_LATM_MUXER)                += latmenc.o rawenc.o
>  OBJS-$(CONFIG_LMLM4_DEMUXER)             += lmlm4.o
>  OBJS-$(CONFIG_LOAS_DEMUXER)              += loasdec.o rawdec.o
> +OBJS-$(CONFIG_LRC_DEMUXER)               += lrcdec.o lrc.o subtitles.o
> +OBJS-$(CONFIG_LRC_MUXER)                 += lrcenc.o lrc.o
>  OBJS-$(CONFIG_LVF_DEMUXER)               += lvfdec.o
>  OBJS-$(CONFIG_LXF_DEMUXER)               += lxfdec.o
>  OBJS-$(CONFIG_M4V_DEMUXER)               += m4vdec.o rawdec.o
> diff --git a/libavformat/allformats.c b/libavformat/allformats.c
> index dc5557c..fff05ee 100644
> --- a/libavformat/allformats.c
> +++ b/libavformat/allformats.c
> @@ -163,6 +163,7 @@ void av_register_all(void)
>      REGISTER_MUXDEMUX(LATM,             latm);
>      REGISTER_DEMUXER (LMLM4,            lmlm4);
>      REGISTER_DEMUXER (LOAS,             loas);
> +    REGISTER_MUXDEMUX(LRC,              lrc);
>      REGISTER_DEMUXER (LVF,              lvf);
>      REGISTER_DEMUXER (LXF,              lxf);
>      REGISTER_MUXDEMUX(M4V,              m4v);
> diff --git a/libavformat/lrc.c b/libavformat/lrc.c
> new file mode 100644
> index 0000000..67eeede
> --- /dev/null
> +++ b/libavformat/lrc.c
> @@ -0,0 +1,34 @@
> +/*
> + * LRC lyrics file format decoder
> + * Copyright (c) 2014 StarBrilliant <m13253 at hotmail.com>
> + *
> + * 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 "metadata.h"
> +#include "lrc.h"
> +
> +const AVMetadataConv ffpriv_lrc_metadata_conv[] = {
> +    {"ti", "title"},
> +    {"al", "album"},
> +    {"ar", "artist"},
> +    {"au", "author"},
> +    {"by", "creator"},
> +    {"re", "encoder"},
> +    {"ve", "encoder_version"},
> +    {0, 0}
> +};
> diff --git a/libavformat/lrc.h b/libavformat/lrc.h
> new file mode 100644
> index 0000000..93274d5
> --- /dev/null
> +++ b/libavformat/lrc.h
> @@ -0,0 +1,29 @@
> +/*
> + * LRC lyrics file format decoder
> + * Copyright (c) 2014 StarBrilliant <m13253 at hotmail.com>
> + *
> + * 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
> + */
> +
> +#ifndef AVFORMAT_LRC_H
> +#define AVFORMAT_LRC_H
> +
> +#include "metadata.h"
> +

> +extern const AVMetadataConv ffpriv_lrc_metadata_conv[];

normally we just use ff_
though ffpriv shouldnt do any harm either


> +
> +#endif
> diff --git a/libavformat/lrcdec.c b/libavformat/lrcdec.c
> new file mode 100644
> index 0000000..917fb43
> --- /dev/null
> +++ b/libavformat/lrcdec.c
> @@ -0,0 +1,247 @@
> +/*
> + * LRC lyrics file format decoder
> + * Copyright (c) 2014 StarBrilliant <m13253 at hotmail.com>
> + *
> + * 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 <inttypes.h>
> +#include <stdint.h>
> +#include <string.h>
> +
> +#include "avformat.h"
> +#include "internal.h"
> +#include "lrc.h"
> +#include "metadata.h"
> +#include "subtitles.h"
> +#include "libavutil/bprint.h"
> +#include "libavutil/dict.h"
> +
> +typedef struct LRCContext {
> +    FFDemuxSubtitlesQueue q;
> +    int64_t ts_offset; // offset metadata item
> +} LRCContext;
> +
> +static int64_t find_header(const char *p)
> +{
> +    int64_t offset = 0;
> +    while(p[offset] &&
> +          p[offset] == ' ' || p[offset] == '\t') {

"p[offset] &&" is redundant


> +        offset++;
> +    }
> +    if(p[offset] && p[offset] == '[' &&

same here


> +       p[offset + 1] >= 'a' && p[offset + 1] <= 'z') {
> +        return offset;
> +    } else {
> +        return -1;
> +    }
> +}
> +
> +static int64_t count_ts(const char *p)
> +{
> +    int64_t offset = 0;
> +    int in_brackets = 0;
> +

> +    while(p[offset]) {
> +        if(p[offset] == ' ' || p[offset] == '\t') {
> +            offset++;
> +        } else if(p[offset] == '[') {
> +            offset++;
> +            in_brackets++;
> +        } else if (p[offset] == ']' && in_brackets) {
> +            offset++;
> +            in_brackets--;
> +        } else if(in_brackets &&
> +                 (p[offset] == ':' || p[offset] == '.' || p[offset] == '-' ||
> +                 (p[offset] >= '0' && p[offset] <= '9'))) {
> +            offset++;
> +        } else {
> +            break;
> +        }
> +    }

while(1) {
    ...

could be used here, the 0 case ends at "break" already



[...]

> +static int lrc_write_header(AVFormatContext *s)
> +{
> +    const AVDictionaryEntry *metadata_item;
> +
> +    if(s->nb_streams != 1 ||
> +       s->streams[0]->codec->codec_type != AVMEDIA_TYPE_SUBTITLE) {
> +        av_log(s, AV_LOG_ERROR,
> +               "LRC supports only a single subtitle stream.\n");
> +        return AVERROR(EINVAL);
> +    }
> +    if(s->streams[0]->codec->codec_id != AV_CODEC_ID_SUBRIP &&
> +       s->streams[0]->codec->codec_id != AV_CODEC_ID_TEXT) {
> +        av_log(s, AV_LOG_ERROR, "Unsupported subtitle codec: %s\n",
> +               avcodec_get_name(s->streams[0]->codec->codec_id));
> +        return AVERROR(EINVAL);
> +    }
> +    avpriv_set_pts_info(s->streams[0], 64, 1, 100);
> +
> +    ff_metadata_conv_ctx(s, ffpriv_lrc_metadata_conv, NULL);

> +    av_dict_set(&s->metadata, "ve", AV_STRINGIFY(LIBAVFORMAT_VERSION), 0);

the LIBAVFORMAT_IDENT set by mux.c isnt enough ?

if so, this needs a  AVFMT_FLAG_BITEXACT check or it would break
future regression tests


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

While the State exists there can be no freedom; when there is freedom there
will be no State. -- Vladimir Lenin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 181 bytes
Desc: Digital signature
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20140712/6c577f4d/attachment.asc>


More information about the ffmpeg-devel mailing list