global metadata, etc.¶
- doc
https://ffmpeg.org/ffmpeg-formats.html#Metadata-1, https://ffmpeg.org/ffmpeg.html#Advanced-options
Warning
As I mentioned at Text expansion, there is no (straightforward) way to render the global metadata as an image with ffmpeg, so, the act of inserting global metadata into media files is basically for tools other than ffmpeg, isn’t it?
But give up to think “for any tool other than ffmpeg”.
For example, for non-English handling, Windows Explorer and ffmpeg are different. (ffmpeg reads everything as utf-8 and writes with utf-8. But there are probably tools out there that write as mbcs, and Windows Explorer can read it correctly somehow, of cource ffmpeg can’t.)
ffmetadata file¶
To dump metadata and then to load it back, the most easy way is to use a ffmetadata file, this is the same way as shown chapters:
;FFMETADATA1
; title (TIT2)
title=Peel
; track (TRCK)
track=2/14
; album (TALB)
album=Slowly
; genre (TCON)
genre=Rock
; artist (TPE1) -> "Contribution artists"
artist=Niko\; Andy
; album_artist (TPE2) -> "Album Artist"
album_artist=Lou
[me@host: ~]$ ffmpeg -hide_banner -y -i input.mp3 -i ffm1.txt -map_metadata 1 output.mp3
Input #0, mp3, from 'input.mp3':
Metadata:
encoder : Lavf57.71.100
Duration: 00:01:59.69, start: 0.025057, bitrate: 127 kb/s
Stream #0:0: Audio: mp3, 44100 Hz, stereo, s16p, 127 kb/s
Metadata:
encoder : Lavf
Input #1, ffmetadata, from 'ffm1.txt':
Metadata:
title : Peel
track : 2/14
album : Slowly
genre : Rock
artist : Niko; Andy
album_artist : Lou
Duration: N/A, start: 0.000000, bitrate: N/A
Stream mapping:
Stream #0:0 -> #0:0 (mp3 (native) -> mp3 (libmp3lame))
Press [q] to stop, [?] for help
Output #0, mp3, to 'output.mp3':
Metadata:
TIT2 : Peel
TRCK : 2/14
TALB : Slowly
TCON : Rock
TPE1 : Niko; Andy
TPE2 : Lou
TSSE : Lavf57.71.100
Stream #0:0: Audio: mp3 (libmp3lame), 44100 Hz, stereo, s16p
Metadata:
encoder : Lavc57.89.100 libmp3lame
... (snip) ...
[me@host: ~]$ ffmpeg -hide_banner -y -i output.mp3 -f ffmetadata - 2> /dev/null
title=Peel
track=2/14
album=Slowly
genre=Rock
artist=Niko\; Andy
album_artist=Lou
encoder=Lavf57.71.100
[me@host: ~]$ ffmpeg -hide_banner -y -i input.mp3 -i ffm1.txt -map_metadata 1 \
> -id3v2_version 3 \
> output_id3v2_3.mp3
Input #0, mp3, from 'input.mp3':
Metadata:
encoder : Lavf57.71.100
Duration: 00:01:59.69, start: 0.025057, bitrate: 127 kb/s
Stream #0:0: Audio: mp3, 44100 Hz, stereo, s16p, 127 kb/s
Metadata:
encoder : Lavf
Input #1, ffmetadata, from 'ffm1.txt':
Metadata:
title : Peel
track : 2/14
album : Slowly
genre : Rock
artist : Niko; Andy
album_artist : Lou
Duration: N/A, start: 0.000000, bitrate: N/A
Stream mapping:
Stream #0:0 -> #0:0 (mp3 (native) -> mp3 (libmp3lame))
Press [q] to stop, [?] for help
Output #0, mp3, to 'output_id3v2_3.mp3':
Metadata:
TIT2 : Peel
TRCK : 2/14
TALB : Slowly
TCON : Rock
TPE1 : Niko; Andy
TPE2 : Lou
TSSE : Lavf57.71.100
Stream #0:0: Audio: mp3 (libmp3lame), 44100 Hz, stereo, s16p
Metadata:
encoder : Lavc57.89.100 libmp3lame
... (snip) ...
[me@host: ~]$ ffmpeg -hide_banner -y -i output_id3v2_3.mp3 -f ffmetadata - 2> /dev/null
;FFMETADATA1
title=Peel
track=2/14
album=Slowly
genre=Rock
artist=Niko\; Andy
album_artist=Lou
encoder=Lavf57.71.100
- see also
;FFMETADATA1
; TIT2 (title)
TIT2=Peel
; TRCK (track)
TRCK=2/14
; TALB (album)
TALB=Slowly
; TCON (genre)
TCON=Rock
; TPE1 (artist) -> "Contribution artists"
TPE1=Niko\; Andy
; TPE2 (album_artist) -> "Album Artist"
TPE2=Lou
[me@host: ~]$ ffmpeg -hide_banner -y -i input.mp3 -i ffm2.txt -map_metadata 1 output2.mp3
Input #0, mp3, from 'input.mp3':
Metadata:
encoder : Lavf57.71.100
Duration: 00:01:59.69, start: 0.025057, bitrate: 127 kb/s
Stream #0:0: Audio: mp3, 44100 Hz, stereo, s16p, 127 kb/s
Metadata:
encoder : Lavf
Input #1, ffmetadata, from 'ffm2.txt':
Metadata:
TIT2 : Peel
TRCK : 2/14
TALB : Slowly
TCON : Rock
TPE1 : Niko; Andy
TPE2 : Lou
Duration: N/A, start: 0.000000, bitrate: N/A
Stream mapping:
Stream #0:0 -> #0:0 (mp3 (native) -> mp3 (libmp3lame))
Press [q] to stop, [?] for help
Output #0, mp3, to 'output2.mp3':
Metadata:
TIT2 : Peel
TRCK : 2/14
TALB : Slowly
TCON : Rock
TPE1 : Niko; Andy
TPE2 : Lou
TSSE : Lavf57.71.100
Stream #0:0: Audio: mp3 (libmp3lame), 44100 Hz, stereo, s16p
Metadata:
encoder : Lavc57.89.100 libmp3lame
... (snip) ...
[me@host: ~]$ ffmpeg -hide_banner -y -i output2.mp3 -f ffmetadata - 2> /dev/null
;FFMETADATA1
title=Peel
track=2/14
album=Slowly
genre=Rock
artist=Niko\; Andy
album_artist=Lou
encoder=Lavf57.71.100
As mentioned above, “%{metadata}” can not use this information, but because ffmetadata files can be extracted as you see, of course you can:
#! /bin/sh
trap 'rm -f _meta.txt' 0 1 2 3 15
ifn="$1"
# extract ffmetadata
ffmpeg -y -i "${ifn}" -f ffmetadata _meta.txt
# draw the content of _meta.txt
ffplay "${ifn}" -vf "\
drawtext='
font=monospace:
fontsize=40:
fontcolor=white:
shadowcolor=blue:shadowx=2:shadowy=2:
x=30:y=30:
expansion=none:
textfile=_meta.txt'
"
-metadata¶
[me@host: ~]$ ffmpeg -hide_banner -y -i input.mp3 -metadata title="Peel Slowly and See" \
> -c copy output3.mp3
Input #0, mp3, from 'input.mp3':
Metadata:
encoder : Lavf57.71.100
Duration: 00:01:59.69, start: 0.025057, bitrate: 127 kb/s
Stream #0:0: Audio: mp3, 44100 Hz, stereo, s16p, 127 kb/s
Metadata:
encoder : Lavf
Output #0, mp3, to 'output3.mp3':
Metadata:
TIT2 : Peel Slowly and See
TSSE : Lavf57.71.100
Stream #0:0: Audio: mp3, 44100 Hz, stereo, s16p, 127 kb/s
Metadata:
encoder : Lavf
Stream mapping:
Stream #0:0 -> #0:0 (copy)
... (snip) ...
[me@host: ~]$ ffmpeg -hide_banner -y -i output3.mp3 -f ffmetadata - 2>/dev/null
;FFMETADATA1
title=Peel Slowly and See
encoder=Lavf57.71.100
[me@host: ~]$ ffmpeg -hide_banner -y -i input.mp3 -i ffm1.txt -map_metadata 1 \
> -metadata title="Peel Slowly and See" -c copy output4.mp3
Input #0, mp3, from 'input.mp3':
Metadata:
encoder : Lavf57.71.100
Duration: 00:01:59.69, start: 0.025057, bitrate: 127 kb/s
Stream #0:0: Audio: mp3, 44100 Hz, stereo, s16p, 127 kb/s
Metadata:
encoder : Lavf
Input #1, ffmetadata, from 'ffm1.txt':
Metadata:
title : Peel
track : 2/14
album : Slowly
genre : Rock
artist : Niko; Andy
album_artist : Lou
Duration: N/A, start: 0.000000, bitrate: N/A
Output #0, mp3, to 'output4.mp3':
Metadata:
TPE2 : Lou
TRCK : 2/14
TALB : Slowly
TCON : Rock
TPE1 : Niko; Andy
TIT2 : Peel Slowly and See
TSSE : Lavf57.71.100
Stream #0:0: Audio: mp3, 44100 Hz, stereo, s16p, 127 kb/s
Metadata:
encoder : Lavf
Stream mapping:
Stream #0:0 -> #0:0 (copy)
... (snip) ...
[me@host: ~]$ ffmpeg -hide_banner -y -i output4.mp3 -f ffmetadata - 2>/dev/null
;FFMETADATA1
album_artist=Lou
track=2/14
album=Slowly
genre=Rock
artist=Niko\; Andy
title=Peel Slowly and See
encoder=Lavf57.71.100