damianociarla / node-ffmpeg

ffmpeg module for nodejs
MIT License
604 stars 140 forks source link

Multiple metadata options #47

Open ivanm376 opened 6 years ago

ivanm376 commented 6 years ago

Trying to set metadata as described in https://multimedia.cx/eggs/supplying-ffmpeg-with-metadata/

file.addCommand('-metadata', `title="TestTitle"`)
file.addCommand('-metadata', `artist="TestArtist"`)

And getting this error:

Potentially unhandled rejection [1] {"code":112,"msg":"The command \"-metadata\" already exists"} (WARNING: non-Error used)

Shouldn't multiple -metadata options be allowed ?

shketov commented 2 years ago

acutally. has anyone found a solution?

SourceCodeNinja commented 1 year ago

I had to rewrite the addCommand function to check if given command equals -metadata then it will not check if it exists in commands array.

this.addCommand = function (command, argument) {
    if (command == "-metadata") {
        commands.push(command);
        if (argument != undefined)
        commands.push(argument);
    } else if (utils.in_array(command, commands) === false) { 
        // Add the new command
        commands.push(command);
        // Add the argument to new command
        if (argument != undefined)
            commands.push(argument);
    } else 
        throw errors.renderError('command_already_exists', command);
}

Alternatively you can do the following...

var metadata = [];
for (const prop in meta) {
    metadata.push(`${prop}="${meta[prop]}"`);
}

stream.addCommand(`-metadata`, metadata.join(` -metadata `));