madebyhiro / codem-transcode

Offline video transcoder written in node.js
Other
153 stars 68 forks source link

Encoder options with double quotes don't work #24

Closed tieleman closed 9 years ago

tieleman commented 10 years ago

NodeJS butchers arguments that you pass using child_process.spawn. For example, the following job fails when going into the transcoder:

$ curl -XPOST -d '{
    "source_file": "/tmp/sinterklaas.mov",
    "destination_file":"/tmp/sinterklaas_out.mov",
    "encoder_options": "-acodec copy -vcodec libx264 -vf \"scale=60:60\""
}' http://localhost:8080/jobs

With error:

"ffmpeg finished with an error: '[AVFilterGraph @ 0x7faa18e0b900] No such filter: '"scale'Error opening filters!
' (1)."

While executing it directly from the command line works:

$ ffmpeg -i /tmp/sinterklaas.mov -acodec copy -vcodec libx264 -vf "scale=60:60" /tmp/sinterklaas2.mov
tieleman commented 10 years ago

Workaround: due to the way Node passes arguments to ffmpeg it should never be required to double-quote your arguments. So in the aforementioned case, this works:

$ curl -XPOST -d '{
    "source_file": "/tmp/sinterklaas.mov",
    "destination_file":"/tmp/sinterklaas_out.mov",
    "encoder_options": "-acodec copy -vcodec libx264 -vf scale=60:60"
}' http://localhost:8080/jobs
eiktyrner commented 9 years ago

I'm having some issues with double quotes so I figured I would post in this issue even if it's old. This doesn't work

$ curl -XPOST -d '{
"source_file":"/tmp/input.mov",
"destination_file":"/tmp/output.mov",
"encoder_options":"-filter_complex [0:0][0:1] amerge=input=2 -c:a aac -c:v libx264 -preset fast -crf 22 -pix_fmt yuv420p -g 5 -strict -2"
}' http://192.168.16.44:8080/jobs

Gives error

[AVFilterGraph @ 0x1e2d0c0] No such filter: ''
Error configuring filters.
' (1)."

While this works

$ ffmpeg -i input.mov -filter_complex "[0:0][0:1] amerge=inputs=2" -c:a aac -c:v libx264 -preset fast -crf 22 -pix_fmt yuv420p -g 5 -strict -2 Output.mov

Any ideas?

deedos commented 9 years ago

Hi Jacob.

Did you tey to use single quotes ? For me, it worked cheers

2015-07-22 5:33 GMT-03:00 Jacob Alenius notifications@github.com:

I'm having some issues with double quotes so I figured I would post in this issue even if it's old. This doesn't work

$ curl -XPOST -d '{ "source_file":"/tmp/input.mov", "destination_file":"/tmp/output.mov", "encoder_options":"-filter_complex [0:0][0:1] amerge=input=2 -c:a aac -c:v libx264 -preset fast -crf 22 -pix_fmt yuv420p -g 5 -strict -2" }' http://192.168.16.44:8080/jobs

Gives error

[AVFilterGraph @ 0x1e2d0c0] No such filter: '' Error configuring filters. ' (1)."

While this works

$ ffmpeg -i input.mov -filter_complex "[0:0][0:1] amerge=inputs=2" -c:a aac -c:v libx264 Output.mov

Any ideas?

— Reply to this email directly or view it on GitHub https://github.com/madebyhiro/codem-transcode/issues/24#issuecomment-123616274 .

Daniel Roviriego (21) 35920701 (21) 99561654

eiktyrner commented 9 years ago

Do you mean like this? That would mess with the single quotes that are encapsulating the data. Could you post the whole command you used that worked?

$ curl -XPOST -d '{
"source_file":"/tmp/input.mov",
"destination_file":"/tmp/output.mov",
"encoder_options":"-filter_complex '[0:0][0:1] amerge=input=2' -c:a aac -c:v libx264 -preset fast -crf 22 -pix_fmt yuv420p -g 5 -strict -2"
}' http://192.168.16.44:8080/jobs
tieleman commented 9 years ago

@eiktyrner, I've just pushed a commit that should enable you to use complex filters. The issue was that the encoder_options string is simply being split on whitespace to create an array for the arguments. Obviously this does not work if your filter has whitespace in it.

Can you check out the code and try again (it's not in the released version yet, so you need to check out the code with git)? Instead of a string you should supply an array with arguments for the encoder_options. Your command should be something like:

$ curl -XPOST -d '{
"source_file":"/tmp/input.mov",
"destination_file":"/tmp/output.mov",
"encoder_options":["-filter_complex", "[0:0][0:1] amerge=input=2", "-c:a", "aac", "-c:v", "libx264", "-preset", "fast", "-crf", "22", "-pix_fmt", "yuv420p", "-g", "5", "-strict", "-2"]
}' http://192.168.16.44:8080/jobs

Note that the arguments shouldn't need any additional quotes around them.

deedos commented 9 years ago

Hi @eiktyrner https://github.com/eiktyrner, good that @tieleman had gone for a definite solution. I did give you a bad answer. What worked to me was using no quotes at all, but within the codem-scheduler preset parameter, just like these for overlaying a watermark:

-i /path-to-my-watermark.png -filter_complex [0:v]overlay=0:0[outv];[outv]yadif=1[deint] -map [deint] -map 0:a -acodec libfdk_aac -ab 256k -vcodec libx264 -vb 4700k

my ffmpeg line for testing had single quote for the filter-complex:

-filter_complex '[0:v]overlay=0:0[outv];[outv]yadif=1[deint]'

Anyway, good luck

2015-07-28 11:26 GMT-03:00 Sjoerd Tieleman notifications@github.com:

@eiktyrner https://github.com/eiktyrner, I've just pushed a commit that should enable you to use complex filters. The issue was that the encoder_options string is simply being split on whitespace to create an array for the arguments. Obviously this does not work if your filter has whitespace in it.

Can you check out the code and try again? Instead of a string you should supply an array with arguments for the encoder_options. Your command should be something like:

$ curl -XPOST -d '{ "source_file":"/tmp/input.mov", "destination_file":"/tmp/output.mov", "encoder_options":["-filter_complex", "[0:0][0:1] amerge=input=2", "-c:a", "aac", "-c:v", "libx264", "-preset", "fast", "-crf", "22", "-pix_fmt", "yuv420p", "-g", "5", "-strict", "-2"] }' http://192.168.16.44:8080/jobs

Note that the arguments shouldn't need any additional quotes around them.

— Reply to this email directly or view it on GitHub https://github.com/madebyhiro/codem-transcode/issues/24#issuecomment-125626735 .

Daniel Roviriego (21) 35920701 (21) 99561654

eiktyrner commented 9 years ago

@tieleman Yeah that works, I also managed to get it to work without that space in "[0:0][0:1]amerge=inputs=2", seems it wasn't needed at all. But this should hopefully be a bit more fool proof. Cheers!

tieleman commented 9 years ago

Yeah, I don't know what took me so long to provide a proper fix for this. 😬 Seeing as there's now a definitive way to provide "complex" arguments, I'm going to close this issue, seeing as this is just the way Node.js handles arguments.