[FFmpeg-devel] [PATCH 2/4] id3v2: merge TYER/TDAT/TIME to date tag
Anton Khirnov
anton
Sat Oct 30 10:51:57 CEST 2010
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.
--
Anton Khirnov
-------------- 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/11302ab1/attachment.pgp>
More information about the ffmpeg-devel
mailing list