1

I want to use a filter in an ffmpeg version compiled for Javascript (ffmpeg.js). But the parser doesn't seem to handle quotes, so I need to write the full command without quotes.

How can I write the following command without quotes?

ffmpeg -i video.mp4 -i image.jpg -filter_complex "[1][0]scale2ref[i][v];[v][i]overlay=10:10:enable=\'between(t,1,2)\'" -c:a copy output.mp4

In javascript I specify the command as follows:

worker.postMessage({
 type: 'command',
 arguments: "-i video.mp4 -i image.jpg -filter_complex '[1][0]scale2ref[i][v];[v][i]overlay=10:10' -c:a copy output.mp4".split(' '),
files: [
{
    data: new Uint8Array(videofile),
    name: 'video.mp4'
},
{
    data: new Uint8Array(imagefile),
    name: 'image.jpg'
},

] });

Which however results in:

[AVFilterGraph @ 0xdf4c30] No such filter: '[1][0]scale2ref[i][v];[v][i]overlay=10:10'

I checked and the overlay filter works in simpler version without quotes, for example this command works:

arguments: "-i video.mp4 -i image.jpg -filter_complex overlay=10:10 -c:a copy output.mp4".split(' '),
user2212461
  • 3,105
  • 8
  • 49
  • 87
  • I guess you need to remove the single quotes from the string inside `arguments`. Otherwise ffmpeg will receive the single quote as-is, which doesn't make sense. But it'd make more sense if you passed the shell command as an *array* of arguments which are then handled by a proper executable calling function (e.g., https://nodejs.org/docs/v8.1.4/api/child_process.html#child_process_child_process_execfile_file_args_options_callback), so you don't have to worry about quoting. – slhck Apr 10 '19 at 08:36

1 Answers1

0

I think the problem is that the ' will still be around after the split which makes ffmpeg confused. If this was a real shell the argument parser would split and parse the quotes properly.

Try to remove the ' in the original string like this:

arguments: "-i video.mp4 -i image.jpg -filter_complex [1][0]scale2ref[i][v];[v][i]overlay=10:10 -c:a copy output.mp4".split(' ')

Or maybe even skip doing split and pass a list of arguments directly instead:

arguments: ["-i", "video.mp4", "-i", "image.jpg", "-filter_complex", "[1][0]scale2ref[i][v];[v][i]overlay=10:10", "-c:a", "copy", "output.mp4"]
Mattias Wadman
  • 11,172
  • 2
  • 42
  • 57