[FFmpeg-user] Help with metadata writing (mp4)... what'spossible?

yUGz afterLife yugz.afterlife.888 at gmail.com
Thu Dec 6 21:18:25 EET 2018


Here iz an exemple in php
Ull see correct metadatatagz sample to get infoz
The script should be human readable

< ?php
        if (is_file($imgsrc)) unlink($imgsrc);
        exec("$ffmpegbin -i \"$fullfile\" \"$imgsrc\" 2>&1");
        if (!is_file($imgsrc)) if (is_file($imgfile)) copy($imgfile,$imgsrc);

        if (is_file($tagzfile)) unlink($tagzfile);
        exec("$ffprobebin -i \"$fullfile\" -v quiet -print_format json -show_format -show_streams > \"$tagzfile\"");

        $infoz = array();
        foreach (array('artist','subartist','album','track','title','label','ref','genre','bpm','bitrate','frequency','version','layer','desc','country','url','secs') as $plop) {
                $infoz[$plop] = '';
        }
        $infoz['date'] = '????/??/??';

        $str = file_get_contents($tagzfile);
        $json = json_decode($str, true);

        //print_r($json);

        if (!empty($json['format']['tags']['artist'])) $infoz['artist'] = $json['format']['tags']['artist'];
        else if (!empty($json['format']['tags']['ARTIST'])) $infoz['artist'] = $json['format']['tags']['ARTIST'];
        if (!empty($json['format']['tags']['album_artist'])) $infoz['subartist'] = $json['format']['tags']['album_artist'];
        else if (!empty($json['format']['tags']['ALBUM_ARTIST'])) $infoz['subartist'] = $json['format']['tags']['ALBUM_ARTIST'];
        if (!empty($json['format']['tags']['album'])) $infoz['album'] = $json['format']['tags']['album'];
        else if (!empty($json['format']['tags']['ALBUM'])) $infoz['album'] = $json['format']['tags']['ALBUM'];
        if (!empty($json['format']['track_number'])) $infoz['track'] = $json['format']['track_number'];
        else if (!empty($json['format']['TRACK_NUMBER'])) $infoz['track'] = $json['format']['TRACK_NUMBER'];
        else if (!empty($json['format']['track'])) $infoz['track'] = $json['format']['track'];
        if (!empty($json['format']['tags']['title'])) $infoz['title'] = $json['format']['tags']['title'];
        else if (!empty($json['format']['tags']['TITLE'])) $infoz['title'] = $json['format']['tags']['TITLE'];
        if (!empty($json['format']['tags']['publisher'])) $infoz['label'] = $json['format']['tags']['publisher'];
        if (!empty($json['format']['tags']['Catalog Number'])) $infoz['ref'] = $json['format']['tags']['Catalog Number'];
        if (!empty($json['format']['tags']['genre'])) $infoz['genre'] = $json['format']['tags']['genre'];
        else if (!empty($json['format']['tags']['GENRE'])) $infoz['genre'] = $json['format']['tags']['GENRE'];
        if (!empty($json['format']['tags']['bpm'])) $infoz['bpm'] = $json['format']['tags']['bpm'];
        else if (!empty($json['format']['tags']['TBPM'])) $infoz['bpm'] = $json['format']['tags']['TBPM'];
        if (!empty($json['format']['bit_rate'])) $infoz['bitrate'] = $json['format']['bit_rate'];
        if (!empty(preg_split('/\//',$json['streams'][0]['codec_time_base'])[1])) $infoz['frequency'] = preg_split('/\//',$json['streams'][0]['codec_time_base'])[1];
        if (!empty($json['format']['tags']['date'])) $infoz['date'] = preg_replace('/(\d{4})[-|\/]*(\d{2})[-|\/]*(\d{2}).*/',"$1/$2/$3",$json['format']['tags']['date']);
        else if (!empty($json['format']['tags']['DATE'])) $infoz['date'] = preg_replace('/(\d{4})[-|\/]*(\d{2})[-|\/]*(\d{2}).*/',"$1/$2/$3",$json['format']['tags']['DATE']);
        if (!empty($json['format']['tags']['comment'])) $infoz['desc'] = $json['format']['tags']['comment'];
        if (!empty($json['format']['tags']['country'])) $infoz['country'] = $json['format']['tags']['country'];
        if (!empty($json['format']['tags']['url'])) $infoz['url'] = $json['format']['tags']['url'];
        if (!empty($json['streams'][0]['duration'])) $infoz['secs'] = floor($json['streams'][0]['duration']);
?>
…
< ?php
        $metaz = '';
        if (is_file($imgsrc)) $metaz .= ' -i "'.$imgsrc.'" -map 0:0 -map 1:0 -id3v2_version 3 -metadata:s:v title="album COVER" -metadata:s:v comment="COVER (front)"';
        if (!empty($artist)) $metaz .= ' -metadata artist="'.$chandle->real_escape_string($artist).'"';
        if (!empty($subartist)) $metaz .= ' -metadata album_artist="'.$chandle->real_escape_string($subartist).'"';
        if (!empty($title)) $metaz .= ' -metadata title="'.$chandle->real_escape_string($title).'"';
        if (!empty($album)) $metaz .= ' -metadata album="'.$chandle->real_escape_string($album).'"';
        if (!empty($track)) $metaz .= ' -metadata track="'.$chandle->real_escape_string($track).'"';
        if (!empty($genre)) $metaz .= ' -metadata genre="'.$chandle->real_escape_string($genre).'"';
        if (!empty($label)) $metaz .= ' -metadata publisher="'.$chandle->real_escape_string($label).'"';
        if (!empty($ref)) $metaz .= ' -metadata catalog_number="'.$chandle->real_escape_string($ref).'"';
        if (!empty($bpm)) $metaz .= ' -metadata bpm="'.$chandle->real_escape_string($bpm).'"';
        if (!empty($date)) $metaz .= ' -metadata date="'.$chandle->real_escape_string(str_replace('/','/',$date)).'"';

        $fileParts = pathinfo(basename($fullfile));
        $ext = $fileParts['extension'];
        $temppfile = $fullfile.'.tmp.'.$ext;

        if (!empty($metaz)) {
                exec("$ffmpegbin -i \"$fullfile\"$metaz -vn -sn -codec:a copy \"$temppfile\" 2>&1");
        }
        if (is_file($temppfile)) {
                unlink($fullfile);
                rename($temppfile,$fullfile);
        }
?>

-metadata artist
-metadata album_artist
-metadata album
-metadata title
-metadata genre
-metadata publisher
-metadata bpm
-metadata date

By the way iam trying to write CATALOG NUMBER tag (TXXX :CATALOGNUMBER)
-metadata catalog_number
-metadata TXXX :CATALOGNUMBER
Both dont work

If u have any tip, thx



Hugo

De : Gyan Doshi
Envoyé le :jeudi 6 décembre 2018 19:56
À : ffmpeg-user at ffmpeg.org
Objet :Re: [FFmpeg-user] Help with metadata writing (mp4)... what'spossible?

On 07-12-2018 12:10 AM, Karen Norton wrote:

> 
> My questions are about finding the full scope of keys that can be written
> with ffmpeg because the sites I reference give varying sets of keys. I
> would like to find a comprehensive list of keys for all files in general
> (video and audio) but for mp4 in particular. I would also like to know
> about writing custom tags/keys. Is this possible for mp4 in general but
> more importantly mp4 with ffmpeg. :-D

The MP4 file format itself does not provide any restrictions on metadata 
keys. The list in my SU answer lists all the iTunes tags that our muxer 
currently supports. Custom global tags are possible if

    -movflags use_metadata_tags

is added to the command.

Then -metadata somekey=somevalue can be stored. I should update my 
answer to reflect this. I can't test this but it's possible that Apple 
applications may not read these or any other tags if this method is used.

Thanks,
Gyan
_______________________________________________
ffmpeg-user mailing list
ffmpeg-user at ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
ffmpeg-user-request at ffmpeg.org with subject "unsubscribe".



More information about the ffmpeg-user mailing list