Closed welpo closed 1 month ago
I did it!
After a million attempts, Claude came up with the idea to use the metadata:g:n
format for passing global metadata options. Here's the working code:
def add_metadata_to_mp3():
input_file = os.path.expanduser("~/Desktop/test.mp3")
output_file = os.path.expanduser("~/Desktop/test_metadata.mp3")
metadata = {
"metadata:g:0": "title=Test Title",
"metadata:g:1": "artist=Test Artist",
"metadata:g:2": "album=Test Album",
"metadata:g:3": "year=2024"
}
ffmpeg = (
FFmpeg()
.option("y")
.input(input_file)
.output(output_file, c="copy", **metadata)
)
try:
ffmpeg.execute()
print(f"Metadata added successfully. Output file: {output_file}")
except FFmpegError as e:
print(f"An FFmpeg error occurred: {e.message}")
print(f"FFmpeg arguments: {e.arguments}")
This defines the metadata as a list of tuples, where each tuple contains the metadata:g:n
key and the full key=value
string for each metadata item.
I searched around and found this comment, which may have been in the training data.
Hello!
First off: thanks for this binding!
I'm trying to add multiple metadata fields to an MP3 file. My goal is to recreate the following FFmpeg command:
However, I've encountered several issues while attempting to achieve this using the wrapper.
Code
Attempts and results
Single metadata string:
Result: All metadata fields were concatenated into the "Title" field.
Separate metadata options:
Result: Error - "Error opening input files: Invalid argument" FFmpeg arguments were ordered incorrectly, with metadata before input file:
Output options dictionary:
Result: Error - "Error opening output files: Invalid argument" FFmpeg arguments had incorrect metadata syntax:
Metadata as separate options:
Result: Error - "Error opening input files: Invalid argument" FFmpeg arguments still ordered incorrectly, with metadata before input file:
Is there a correct way to add multiple metadata fields to an output file using the wrapper? If so, could you provide an example of how to achieve this?
Thanks!
Additional information