[FFmpeg-devel] [PATCH 2/4] id3v2: merge TYER/TDAT/TIME to date tag
Michael Niedermayer
michaelni
Sat Oct 30 15:25:33 CEST 2010
On Sat, Oct 30, 2010 at 10:51:57AM +0200, Anton Khirnov wrote:
> On Sun, Oct 17, 2010 at 10:37:20AM +0200, Michael Niedermayer wrote:
> > On Fri, Oct 15, 2010 at 09:20:59PM +0200, Anton Khirnov wrote:
> > > ---
> > > libavformat/id3v2.c | 37 +++++++++++++++++++++++++++++++++++++
> > > 1 files changed, 37 insertions(+), 0 deletions(-)
> > >
> > > diff --git a/libavformat/id3v2.c b/libavformat/id3v2.c
> > > index fbcb8f8..d66509f 100644
> > > --- a/libavformat/id3v2.c
> > > +++ b/libavformat/id3v2.c
> > > @@ -162,6 +162,42 @@ static void read_ttag(AVFormatContext *s, ByteIOContext *pb, int taglen, const c
> > > av_metadata_set2(&s->metadata, key, val, 0);
> > > }
> > >
> > > +static int is_number(const char *p)
> > > +{
> > > + while (*p)
> > > + if (!isdigit(*p++))
> > > + return 0;
> > > + return 1;
> > > +}
> > > +
> > > +static void merge_date(AVMetadata **m)
> > > +{
> > > + AVMetadataTag *t;
> > > + char date[17] = {0}; // YYYY-MM-DD hh:mm
> > > +
> > > + if (!(t = av_metadata_get(*m, "TYER", NULL, AV_METADATA_MATCH_CASE)) ||
> > > + strlen(t->value) != 4 || !is_number(t->value))
> > > + return;
> > > + snprintf(date, sizeof(date), "%04d", atoi(t->value));
> > > + av_metadata_set2(m, "TYER", NULL, 0);
> > > +
> > > + if (!(t = av_metadata_get(*m, "TDAT", NULL, AV_METADATA_MATCH_CASE)) ||
> > > + strlen(t->value) != 4 || !is_number(t->value))
> > > + goto finish;
> > > + snprintf(date + 4, sizeof(date) - 4, "-%.2s-%.2s", t->value + 2, t->value);
> > > + av_metadata_set2(m, "TDAT", NULL, 0);
> > > +
> > > + if (!(t = av_metadata_get(*m, "TIME", NULL, AV_METADATA_MATCH_CASE)) ||
> > > + strlen(t->value) != 4 || !is_number(t->value))
> > > + goto finish;
> > > + snprintf(date + 10, sizeof(date) - 10, " %.2s:%.2s", t->value, t->value + 2);
> > > + av_metadata_set2(m, "TIME", NULL, 0);
> >
> > why 3 snprintf instead of 1?
> sorry, i don't see how you want to do this with one snprintf without
> overcomplicating it.
your code is already unreadable, can it really be worse?
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
Incandescent light bulbs waste a lot of energy as heat so the EU forbids them.
Their replacement, compact fluorescent lamps, much more expensive, dont fit in
many old lamps, flicker, contain toxic mercury, produce a fraction of the light
that is claimed and in a unnatural spectrum rendering colors different than
in natural light. Ah and we now need to turn the heaters up more in winter to
compensate the lower wasted heat. Who wins? Not the environment, thats for sure
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20101030/dd971fdb/attachment.pgp>
More information about the ffmpeg-devel
mailing list