[FFmpeg-devel] [PATCH] id3v2enc: chapter support

Michael Niedermayer michaelni at gmx.at
Fri May 10 19:54:11 CEST 2013


On Thu, May 09, 2013 at 04:26:49PM +0000, Paul B Mahol wrote:
> Signed-off-by: Paul B Mahol <onemda at gmail.com>
> ---
>  libavformat/id3v2enc.c | 84 ++++++++++++++++++++++++++++++++++++++++++--------
>  1 file changed, 71 insertions(+), 13 deletions(-)
> 
> diff --git a/libavformat/id3v2enc.c b/libavformat/id3v2enc.c
> index a10d679..1b77b07 100644
> --- a/libavformat/id3v2enc.c
> +++ b/libavformat/id3v2enc.c
> @@ -162,33 +162,31 @@ void ff_id3v2_start(ID3v2EncContext *id3, AVIOContext *pb, int id3v2_version,
>      avio_wb32(pb, 0);
>  }
>  
> -int ff_id3v2_write_metadata(AVFormatContext *s, ID3v2EncContext *id3)
> +static int write_metadata(AVIOContext *pb, AVDictionary **metadata,
> +                          ID3v2EncContext *id3, int enc)
>  {
>      AVDictionaryEntry *t = NULL;
> -    int enc = id3->version == 3 ? ID3v2_ENCODING_UTF16BOM :
> -                                  ID3v2_ENCODING_UTF8;
> +    int ret;
>  
> -    ff_metadata_conv(&s->metadata, ff_id3v2_34_metadata_conv, NULL);
> +    ff_metadata_conv(metadata, ff_id3v2_34_metadata_conv, NULL);
>      if (id3->version == 3)
> -        id3v2_3_metadata_split_date(&s->metadata);
> +        id3v2_3_metadata_split_date(metadata);
>      else if (id3->version == 4)
> -        ff_metadata_conv(&s->metadata, ff_id3v2_4_metadata_conv, NULL);
> -
> -    while ((t = av_dict_get(s->metadata, "", t, AV_DICT_IGNORE_SUFFIX))) {
> -        int ret;
> +        ff_metadata_conv(metadata, ff_id3v2_4_metadata_conv, NULL);
>  
> -        if ((ret = id3v2_check_write_tag(id3, s->pb, t, ff_id3v2_tags, enc)) > 0) {
> +    while ((t = av_dict_get(*metadata, "", t, AV_DICT_IGNORE_SUFFIX))) {
> +        if ((ret = id3v2_check_write_tag(id3, pb, t, ff_id3v2_tags, enc)) > 0) {
>              id3->len += ret;
>              continue;
>          }
> -        if ((ret = id3v2_check_write_tag(id3, s->pb, t, id3->version == 3 ?
> -                                               ff_id3v2_3_tags : ff_id3v2_4_tags, enc)) > 0) {
> +        if ((ret = id3v2_check_write_tag(id3, pb, t, id3->version == 3 ?
> +                                         ff_id3v2_3_tags : ff_id3v2_4_tags, enc)) > 0) {
>              id3->len += ret;
>              continue;
>          }
>  
>          /* unknown tag, write as TXXX frame */
> -        if ((ret = id3v2_put_ttag(id3, s->pb, t->key, t->value, MKBETAG('T', 'X', 'X', 'X'), enc)) < 0)
> +        if ((ret = id3v2_put_ttag(id3, pb, t->key, t->value, MKBETAG('T', 'X', 'X', 'X'), enc)) < 0)
>              return ret;
>          id3->len += ret;
>      }
> @@ -196,6 +194,66 @@ int ff_id3v2_write_metadata(AVFormatContext *s, ID3v2EncContext *id3)
>      return 0;
>  }
>  
> +static int write_chapter(AVFormatContext *s, ID3v2EncContext *id3, int id, int enc)
> +{
> +    const AVRational time_base = {1, 1000};
> +    AVChapter *ch = s->chapters[id];
> +    uint8_t *dyn_buf = NULL;
> +    AVIOContext *dyn_bc;
> +    char *name;
> +    int len, start, end, ret;
> +
> +    if (avio_open_dyn_buf(&dyn_bc) < 0)
> +        return AVERROR(ENOMEM);
> +    name = av_asprintf("ch%d", id);
> +    if (!name) {
> +        av_free(dyn_buf);
> +        return AVERROR(ENOMEM);
> +    }
> +

char name[123] would be simpler, not needing the error check and free

rest LGTM if its tested with some software that supports reading
this

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

I know you won't believe me, but the highest form of Human Excellence is
to question oneself and others. -- Socrates
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20130510/fa5c651a/attachment.asc>


More information about the ffmpeg-devel mailing list