Ffmpeg-python: Adding Metadata

Created on 19 Aug 2018  路  6Comments  路  Source: kkroening/ffmpeg-python

I am trying to find a way to add metadata to the output. Using ffmpeg from the command line I would use something like -metadata title="Title" . I couldn't find anything relating to this in the ffmpeg-python docs. I tried a few different methods, using global_args and output kwargs and I wasn't able to get it to work, usually getting an error like the following.

Unrecognized option 'metadata title="test title"
Error splitting the argument list: Option not found

Here's an example of a full command using ffmpeg.

ffmpeg -i 1-00.30.mp4 -vcodec copy -acodec copy -scodec copy -metadata title="Sample Title" 1-00.30_copy.mp4

Any help would be appreciated.

Most helpful comment

I Solved it by using the output kwargs and using metadata='title=Example Title'.

title =' Example Title'
out = (
    ffmpeg
    .input(infile)
    .output(outfile, metadata='title=' + title)
)

All 6 comments

I Solved it by using the output kwargs and using metadata='title=Example Title'.

title =' Example Title'
out = (
    ffmpeg
    .input(infile)
    .output(outfile, metadata='title=' + title)
)

While another question arises, how do we add two or more metadata as the following terminal command does:
ffmpeg -i "concat:file1.mp3|file2.mp3" -metadata title="new title" -metadata artist="foo bar" -acodec copy output.mp3

To set multiple metadata arguments you can cheat a little by using metadata specifiers in a kwargs argument ...
**{ 'metadata':'title=My Title', 'metadata:':'artist=Me', 'metadata:g':'album=X', }
A little ugly, but I can set 3 metadata keys using this technique.

To set multiple metadata arguments you can cheat a little by using metadata specifiers in a kwargs argument ...
**{ 'metadata':'title=My Title', 'metadata:':'artist=Me', 'metadata:g':'album=X', }
A little ugly, but I can set 3 metadata keys using this technique.

It works, thanks.

A little cleaner, it seems I can do ...
{ 'metadata:g:0':"title=My Title", 'metadata:g:1':"artist=Me", 'metadata:g:2':"album=X", 'metadata:g:3':"year=2019", }
which hopefully means I can add as many metadata items as I need. The index - 0,1,2,3 - seems to be just ignored my ffmpeg as they are all global metadata items, but at least give us unique key values in the dictionary object that the ffmpeg wrapper uses for building up the ffmpeg arguments.

A little cleaner, it seems I can do ...
{ 'metadata:g:0':"title=My Title", 'metadata:g:1':"artist=Me", 'metadata:g:2':"album=X", 'metadata:g:3':"year=2019", }
which hopefully means I can add as many metadata items as I need. The index - 0,1,2,3 - seems to be just ignored my ffmpeg as they are all global metadata items, but at least give us unique key values in the dictionary object that the ffmpeg wrapper uses for building up the ffmpeg arguments.

Awesome. I'd never find this trick by looking those documents. How did you find this trick? By reading source code?

Was this page helpful?
0 / 5 - 0 ratings