Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
FFmpeg
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
libremedia
Tethys
FFmpeg
Commits
b182eeb0
Commit
b182eeb0
authored
16 years ago
by
Aurelien Jacobs
Browse files
Options
Downloads
Patches
Plain Diff
use new metadata API in the mp3 muxer
Originally committed as revision 16954 to
svn://svn.ffmpeg.org/ffmpeg/trunk
parent
9d98535c
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
libavformat/mp3.c
+50
-40
50 additions, 40 deletions
libavformat/mp3.c
with
50 additions
and
40 deletions
libavformat/mp3.c
+
50
−
40
View file @
b182eeb0
...
@@ -526,35 +526,44 @@ static int mp3_read_packet(AVFormatContext *s, AVPacket *pkt)
...
@@ -526,35 +526,44 @@ static int mp3_read_packet(AVFormatContext *s, AVPacket *pkt)
}
}
#if CONFIG_MP2_MUXER || CONFIG_MP3_MUXER
#if CONFIG_MP2_MUXER || CONFIG_MP3_MUXER
static
void
id3v1_create_tag
(
AVFormatContext
*
s
,
uint8_t
*
buf
)
static
int
id3v1_set_string
(
AVFormatContext
*
s
,
const
char
*
key
,
uint8_t
*
buf
,
int
buf_size
)
{
{
int
v
,
i
;
AVMetadataTag
*
tag
;
if
((
tag
=
av_metadata_get
(
s
->
metadata
,
key
,
NULL
,
0
)))
strncpy
(
buf
,
tag
->
value
,
buf_size
);
return
!!
tag
;
}
static
int
id3v1_create_tag
(
AVFormatContext
*
s
,
uint8_t
*
buf
)
{
AVMetadataTag
*
tag
;
int
i
,
count
=
0
;
memset
(
buf
,
0
,
ID3v1_TAG_SIZE
);
/* fail safe */
memset
(
buf
,
0
,
ID3v1_TAG_SIZE
);
/* fail safe */
buf
[
0
]
=
'T'
;
buf
[
0
]
=
'T'
;
buf
[
1
]
=
'A'
;
buf
[
1
]
=
'A'
;
buf
[
2
]
=
'G'
;
buf
[
2
]
=
'G'
;
strncpy
(
buf
+
3
,
s
->
title
,
30
);
count
+=
id3v1_set_string
(
s
,
"title"
,
buf
+
3
,
30
);
strncpy
(
buf
+
33
,
s
->
author
,
30
);
count
+=
id3v1_set_string
(
s
,
"author"
,
buf
+
33
,
30
);
strncpy
(
buf
+
63
,
s
->
album
,
30
);
count
+=
id3v1_set_string
(
s
,
"album"
,
buf
+
63
,
30
);
v
=
s
->
year
;
count
+=
id3v1_set_string
(
s
,
"year"
,
buf
+
93
,
4
);
if
(
v
>
0
)
{
count
+=
id3v1_set_string
(
s
,
"comment"
,
buf
+
97
,
30
);
for
(
i
=
0
;
i
<
4
;
i
++
)
{
if
((
tag
=
av_metadata_get
(
s
->
metadata
,
"track"
,
NULL
,
0
)))
{
buf
[
96
-
i
]
=
'0'
+
(
v
%
10
);
v
=
v
/
10
;
}
}
strncpy
(
buf
+
97
,
s
->
comment
,
30
);
if
(
s
->
track
!=
0
)
{
buf
[
125
]
=
0
;
buf
[
125
]
=
0
;
buf
[
126
]
=
s
->
track
;
buf
[
126
]
=
atoi
(
tag
->
value
);
count
++
;
}
}
if
((
tag
=
av_metadata_get
(
s
->
metadata
,
"genre"
,
NULL
,
0
)))
{
for
(
i
=
0
;
i
<=
ID3v1_GENRE_MAX
;
i
++
)
{
for
(
i
=
0
;
i
<=
ID3v1_GENRE_MAX
;
i
++
)
{
if
(
!
strcasecmp
(
s
->
genr
e
,
id3v1_genre_str
[
i
]))
{
if
(
!
strcasecmp
(
tag
->
valu
e
,
id3v1_genre_str
[
i
]))
{
buf
[
127
]
=
i
;
buf
[
127
]
=
i
;
count
++
;
break
;
break
;
}
}
}
}
}
return
count
;
}
}
/* simple formats */
/* simple formats */
...
@@ -584,22 +593,24 @@ static void id3v2_put_ttag(AVFormatContext *s, const char *string, uint32_t tag)
...
@@ -584,22 +593,24 @@ static void id3v2_put_ttag(AVFormatContext *s, const char *string, uint32_t tag)
static
int
mp3_write_header
(
struct
AVFormatContext
*
s
)
static
int
mp3_write_header
(
struct
AVFormatContext
*
s
)
{
{
AVMetadataTag
*
title
,
*
author
,
*
album
,
*
genre
,
*
copyright
,
*
track
,
*
year
;
int
totlen
=
0
;
int
totlen
=
0
;
char
tracktxt
[
10
];
char
yeartxt
[
10
];
title
=
av_metadata_get
(
s
->
metadata
,
"title"
,
NULL
,
0
);
author
=
av_metadata_get
(
s
->
metadata
,
"author"
,
NULL
,
0
);
if
(
s
->
track
)
album
=
av_metadata_get
(
s
->
metadata
,
"album"
,
NULL
,
0
);
snprintf
(
tracktxt
,
sizeof
(
tracktxt
),
"%d"
,
s
->
track
);
genre
=
av_metadata_get
(
s
->
metadata
,
"genre"
,
NULL
,
0
);
if
(
s
->
year
)
copyright
=
av_metadata_get
(
s
->
metadata
,
"copyright"
,
NULL
,
0
);
snprintf
(
yeartxt
,
sizeof
(
yeartxt
)
,
"%d"
,
s
->
year
);
track
=
av_metadata_get
(
s
->
metadata
,
"track"
,
NULL
,
0
);
year
=
av_metadata_get
(
s
->
metadata
,
"year"
,
NULL
,
0
);
if
(
s
->
title
[
0
])
totlen
+=
11
+
strlen
(
s
->
title
);
if
(
s
->
author
[
0
])
totlen
+=
11
+
strlen
(
s
->
author
);
if
(
title
)
totlen
+=
11
+
strlen
(
title
->
value
);
if
(
s
->
album
[
0
])
totlen
+=
11
+
strlen
(
s
->
album
);
if
(
author
)
totlen
+=
11
+
strlen
(
author
->
value
);
if
(
s
->
genre
[
0
])
totlen
+=
11
+
strlen
(
s
->
genre
);
if
(
album
)
totlen
+=
11
+
strlen
(
album
->
value
);
if
(
s
->
copyright
[
0
])
totlen
+=
11
+
strlen
(
s
->
copyright
);
if
(
genre
)
totlen
+=
11
+
strlen
(
genre
->
value
);
if
(
s
->
track
)
totlen
+=
11
+
strlen
(
tracktxt
);
if
(
copyright
)
totlen
+=
11
+
strlen
(
copyright
->
value
);
if
(
s
->
year
)
totlen
+=
11
+
strlen
(
yeartxt
);
if
(
track
)
totlen
+=
11
+
strlen
(
track
->
value
);
if
(
year
)
totlen
+=
11
+
strlen
(
year
->
value
);
if
(
!
(
s
->
streams
[
0
]
->
codec
->
flags
&
CODEC_FLAG_BITEXACT
))
if
(
!
(
s
->
streams
[
0
]
->
codec
->
flags
&
CODEC_FLAG_BITEXACT
))
totlen
+=
strlen
(
LIBAVFORMAT_IDENT
)
+
11
;
totlen
+=
strlen
(
LIBAVFORMAT_IDENT
)
+
11
;
...
@@ -612,13 +623,13 @@ static int mp3_write_header(struct AVFormatContext *s)
...
@@ -612,13 +623,13 @@ static int mp3_write_header(struct AVFormatContext *s)
id3v2_put_size
(
s
,
totlen
);
id3v2_put_size
(
s
,
totlen
);
if
(
s
->
title
[
0
]
)
id3v2_put_ttag
(
s
,
s
->
title
,
MKBETAG
(
'T'
,
'I'
,
'T'
,
'2'
));
if
(
title
)
id3v2_put_ttag
(
s
,
title
->
value
,
MKBETAG
(
'T'
,
'I'
,
'T'
,
'2'
));
if
(
s
->
author
[
0
]
)
id3v2_put_ttag
(
s
,
s
->
author
,
MKBETAG
(
'T'
,
'P'
,
'E'
,
'1'
));
if
(
author
)
id3v2_put_ttag
(
s
,
author
->
value
,
MKBETAG
(
'T'
,
'P'
,
'E'
,
'1'
));
if
(
s
->
album
[
0
]
)
id3v2_put_ttag
(
s
,
s
->
album
,
MKBETAG
(
'T'
,
'A'
,
'L'
,
'B'
));
if
(
album
)
id3v2_put_ttag
(
s
,
album
->
value
,
MKBETAG
(
'T'
,
'A'
,
'L'
,
'B'
));
if
(
s
->
genre
[
0
]
)
id3v2_put_ttag
(
s
,
s
->
genre
,
MKBETAG
(
'T'
,
'C'
,
'O'
,
'N'
));
if
(
genre
)
id3v2_put_ttag
(
s
,
genre
->
value
,
MKBETAG
(
'T'
,
'C'
,
'O'
,
'N'
));
if
(
s
->
copyright
[
0
]
)
id3v2_put_ttag
(
s
,
s
->
copyright
,
MKBETAG
(
'T'
,
'C'
,
'O'
,
'P'
));
if
(
copyright
)
id3v2_put_ttag
(
s
,
copyright
->
value
,
MKBETAG
(
'T'
,
'C'
,
'O'
,
'P'
));
if
(
s
->
track
)
id3v2_put_ttag
(
s
,
track
txt
,
MKBETAG
(
'T'
,
'R'
,
'C'
,
'K'
));
if
(
track
)
id3v2_put_ttag
(
s
,
track
->
value
,
MKBETAG
(
'T'
,
'R'
,
'C'
,
'K'
));
if
(
s
->
year
)
id3v2_put_ttag
(
s
,
year
txt
,
MKBETAG
(
'T'
,
'Y'
,
'E'
,
'R'
));
if
(
year
)
id3v2_put_ttag
(
s
,
year
->
value
,
MKBETAG
(
'T'
,
'Y'
,
'E'
,
'R'
));
if
(
!
(
s
->
streams
[
0
]
->
codec
->
flags
&
CODEC_FLAG_BITEXACT
))
if
(
!
(
s
->
streams
[
0
]
->
codec
->
flags
&
CODEC_FLAG_BITEXACT
))
id3v2_put_ttag
(
s
,
LIBAVFORMAT_IDENT
,
MKBETAG
(
'T'
,
'E'
,
'N'
,
'C'
));
id3v2_put_ttag
(
s
,
LIBAVFORMAT_IDENT
,
MKBETAG
(
'T'
,
'E'
,
'N'
,
'C'
));
return
0
;
return
0
;
...
@@ -636,8 +647,7 @@ static int mp3_write_trailer(struct AVFormatContext *s)
...
@@ -636,8 +647,7 @@ static int mp3_write_trailer(struct AVFormatContext *s)
uint8_t
buf
[
ID3v1_TAG_SIZE
];
uint8_t
buf
[
ID3v1_TAG_SIZE
];
/* write the id3v1 tag */
/* write the id3v1 tag */
if
(
s
->
title
[
0
]
!=
'\0'
)
{
if
(
id3v1_create_tag
(
s
,
buf
)
>
0
)
{
id3v1_create_tag
(
s
,
buf
);
put_buffer
(
s
->
pb
,
buf
,
ID3v1_TAG_SIZE
);
put_buffer
(
s
->
pb
,
buf
,
ID3v1_TAG_SIZE
);
put_flush_packet
(
s
->
pb
);
put_flush_packet
(
s
->
pb
);
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment