master-of-zen / Av1an

Cross-platform command-line AV1 / VP9 / HEVC / H264 encoding framework with per scene quality encoding
GNU General Public License v3.0
1.51k stars 155 forks source link

Can't use ffmpeg filters via CLI flag #698

Closed OParczyk closed 1 year ago

OParczyk commented 1 year ago

Hi! I'd like to use av1an to convert a video file. It is interlaced and I'd like to apply yadif to it.

Without the filter the command seems to work: av1an --temp /media/user/ramdisk/ -i input.mkv -w 8 -x 0 --chunk-method hybrid -e rav1e --target-quality 90 -o output.mkv

yet trying to use -f -vf yadif aswell fails:

error: Found argument 'yadif' which wasn't expected, or isn't valid in this context

As if yadif is interpreted as a whole new argument. -f yadif gets past this check, but then ffmpeg crashes as without the -vf it thinks yadif is supposed to be a output file without specified container format.

I've tried both zsh and bash, and numerous ways of trying to pass it correctly, including -f '-vf yadif',-f '"-vf yadif"', -f '\-vf\ yadif', -f "-vf yadif" – virtually every way of escaping and quoting I could think of and combinations thereof. Using --ffmpeg also doesn't change this behaviour. Edit: Padding spaces inside the quotes were also tried, both escaped, plain,...

ffmpeg and rav1e were both built yesterday and av1an correctly uses these binaries. Both work as intended, as far as I've been able to tell. I've installed/built av1an yesterday with cargo install. I'm on Ubuntu 22.04 otherwise.

Other issue writers here apparently were able to use much more complex filters, so I wonder what is going on here?

OParczyk commented 1 year ago

I've just tried it in Python using submodule.run(): neither subprocess.run(['av1an','--temp', '/media/user/ramdisk', '-i', 'input.mp4', '-w', '8', '-x', '0', '--chunk-method','hybrid','-e','rav1e','--target-quality','93','--vmaf','-f','-vf yadif','-o','output.mkv']) nor subprocess.run(['av1an','--temp', '/media/user/ramdisk', '-i', 'input.mp4', '-w', '8', '-x', '0', '--chunk-method','hybrid','-e','rav1e','--target-quality','93','--vmaf','-f','\'-vf yadif\'','-o','output.mkv']) worked. Both yield the same error as within my shell:

error: Found argument 'yadif'' which wasn't expected, or isn't valid in this context

master-of-zen commented 1 year ago

For example this script works for me:

import subprocess
subprocess.run(['av1an', '-i', 'm.mp4', '-f','-vf scale=1280:720:0:0,yadif','-o','output.mkv'])
OParczyk commented 1 year ago

Thanks for looking into this I've just tried this and weirdly, the same happens: "error: Found argument 'scale=1280:720:0:0,yadif' which wasn't expected, or isn't valid in this context"

OParczyk commented 1 year ago

On that note: have to set env. variables to get both av1an and vspipe working, I've done so by placing the following scripts into home/bin:

#!/bin/bash

LD_LIBRARY_PATH=/usr/local/lib PYTHONPATH=/usr/local/lib/python3.10/site-packages /home/user/.cargo/bin/av1an $@
#!/bin/bash

LD_LIBRARY_PATH=/usr/local/lib PYTHONPATH=/usr/local/lib/python3.10/site-packages /usr/local/bin/vspipe $@

and called them av1an and vspipe respectively to execute as wrappers. I believe it is this, that happens to trigger the following warning everytime I run av1an:

$ av1an sys:1: RuntimeWarning: An environment is getting collected without calling EnvironmentPolicyAPI.destroy_environment(). This skips some lifecycle callbacks (e.g. register_on_destroy). This might cause libraries to misbehave.

It didn't cause a problem before as far as I could tell, but do you think these issues might be related?

OParczyk commented 1 year ago

Interesting. Exporting the env variables explicitly and then running /home/user/.cargo/bin/av1an --temp /media/user/ramdisk/av1antmp -i in.mkv -w 6 --chunk-method hybrid -e rav1e --target-quality 93 --vmaf --concat mkvmerge -f '-vf yadif' -o out.mkv works. Well, the RuntimeWarning persists, but the command executes correctly.

Replacing $@ with "$@" in the scripts fixes the odd behavior, so it's been my fault. Thank you for your time!