[FFmpeg-devel] [PATCH] lavf/id3v2enc: fix cover art display on some software

Matthieu Bouron matthieu.bouron at gmail.com
Wed May 29 20:40:23 CEST 2013


On Wed, May 29, 2013 at 06:13:51PM +0000, Paul B Mahol wrote:
> On 5/29/13, Matthieu Bouron <matthieu.bouron at gmail.com> wrote:
> > Adding an arbitrary amount of padding bytes at the end of the
> > ID3 metadata fixes cover art display for some software (iTunes,
> > Traktor, Serato, Torq).
> >
> > For reference (ID3 metadata):
> >
> > [ Apic frames ]                      -> cover doesn't show up
> > [ Apic frames, Padding ]             -> ok
> > [ Apic frames, ID3 frames ]          -> ok
> > [ ID3 frames, Apic frames ]          -> cover doesn't show up
> > [ ID3 frames, Apic frames, Padding ] -> ok
> > ---
> >  libavformat/id3v2enc.c  | 14 +++++++++++++-
> >  tests/ref/lavf-fate/mp3 |  4 ++--
> >  2 files changed, 15 insertions(+), 3 deletions(-)
> >
> > diff --git a/libavformat/id3v2enc.c b/libavformat/id3v2enc.c
> > index 60ddbaa..d43d48f 100644
> > --- a/libavformat/id3v2enc.c
> > +++ b/libavformat/id3v2enc.c
> > @@ -28,6 +28,8 @@
> >  #include "avio.h"
> >  #include "id3v2.h"
> >
> > +#define PADDING_BYTES 10
> > +
> >  static void id3v2_put_size(AVIOContext *pb, int size)
> >  {
> >      avio_w8(pb, size >> 21 & 0x7f);
> > @@ -319,7 +321,17 @@ int ff_id3v2_write_apic(AVFormatContext *s,
> > ID3v2EncContext *id3, AVPacket *pkt)
> >
> >  void ff_id3v2_finish(ID3v2EncContext *id3, AVIOContext *pb)
> >  {
> > -    int64_t cur_pos = avio_tell(pb);
> > +    int i;
> > +    int64_t cur_pos;
> > +
> > +    /* adding an arbitrary amount of padding bytes at the end of the
> > +     * ID3 metadata fixes cover art display for some software (iTunes,
> > +     * Traktor, Serato, Torq) */
> > +    for (i = 0; i < PADDING_BYTES; i++)
> > +        avio_w8(pb, 0);
> 
> ffio_fill()
> 

Thanks.
Patch updated.
-------------- next part --------------
>From 2c99fa277f4119dd44764206cbeb74bfa9a606ef Mon Sep 17 00:00:00 2001
From: Matthieu Bouron <matthieu.bouron at gmail.com>
Date: Wed, 29 May 2013 12:05:26 +0200
Subject: [PATCH] lavf/id3v2enc: fix cover art display on some software
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Adding an arbitrary amount of padding bytes at the end of the
ID3 metadata fixes cover art display for some software (iTunes,
Traktor, Serato, Torq).

For reference (ID3 metadata):

[ Apic frames ]                      → cover doesn't show up
[ Apic frames, Padding ]             → ok
[ Apic frames, ID3 frames ]          → ok
[ ID3 frames, Apic frames ]          → cover doesn't show up
[ ID3 frames, Apic frames, Padding ] → ok
---
 libavformat/id3v2enc.c  | 13 ++++++++++++-
 tests/ref/lavf-fate/mp3 |  4 ++--
 2 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/libavformat/id3v2enc.c b/libavformat/id3v2enc.c
index 60ddbaa..f7c37eb 100644
--- a/libavformat/id3v2enc.c
+++ b/libavformat/id3v2enc.c
@@ -26,8 +26,11 @@
 #include "libavutil/intreadwrite.h"
 #include "avformat.h"
 #include "avio.h"
+#include "avio_internal.h"
 #include "id3v2.h"
 
+#define PADDING_BYTES 10
+
 static void id3v2_put_size(AVIOContext *pb, int size)
 {
     avio_w8(pb, size >> 21 & 0x7f);
@@ -319,7 +322,15 @@ int ff_id3v2_write_apic(AVFormatContext *s, ID3v2EncContext *id3, AVPacket *pkt)
 
 void ff_id3v2_finish(ID3v2EncContext *id3, AVIOContext *pb)
 {
-    int64_t cur_pos = avio_tell(pb);
+    int64_t cur_pos;
+
+    /* adding an arbitrary amount of padding bytes at the end of the
+     * ID3 metadata fixes cover art display for some software (iTunes,
+     * Traktor, Serato, Torq) */
+    ffio_fill(pb, 0, PADDING_BYTES);
+    id3->len += PADDING_BYTES;
+
+    cur_pos = avio_tell(pb);
     avio_seek(pb, id3->size_pos, SEEK_SET);
     id3v2_put_size(pb, id3->len);
     avio_seek(pb, cur_pos, SEEK_SET);
diff --git a/tests/ref/lavf-fate/mp3 b/tests/ref/lavf-fate/mp3
index 361314b..6f201e0 100644
--- a/tests/ref/lavf-fate/mp3
+++ b/tests/ref/lavf-fate/mp3
@@ -1,3 +1,3 @@
-7fcf80c2059b5c058a6cdd2e2f798b6c *./tests/data/lavf-fate/lavf.mp3
-96366 ./tests/data/lavf-fate/lavf.mp3
+6bdea919dc6856d76ef2553698e2b0d3 *./tests/data/lavf-fate/lavf.mp3
+96376 ./tests/data/lavf-fate/lavf.mp3
 ./tests/data/lavf-fate/lavf.mp3 CRC=0x6c9850fe
-- 
1.8.2.3



More information about the ffmpeg-devel mailing list