fifonik / FFMetrics

Visualizes Video Quality Metrics (PSNR, SSIM & VMAF) calculated by ffmpeg.exe
570 stars 22 forks source link

Auto detect characters that should be used for escaping in ffmpeg command line options #85

Closed fifonik closed 2 years ago

ls-milkyway commented 2 years ago

Do you have any ideas how I can try to guess based on "configuration" ffmpeg returned how the executable was buid? So, if I detect that it was build on windows, I can escape colon in filespec with triple back slashes, while when it was build on *nix -- single backslash. Just curious, how gyan is building it? It shows "Build by MSYS2 project" as for your build.

I guess that you need to run ffmpeg -version or ffmpeg -buildconf and grab the output....here is an example explaining details of a version switch.

But, to simplify things ...& make ffmetrics more robust & efficient ...it would better (as I stated earlier) to find a working ffmpeg command using inbuilt model...valid for all types of releases: btbn, gyan, or custom... as it is the default & future proof update..& eliminates the need for model files in vmaf-models folder.

Yep, I am aware that gyan is also using gcc with MSYS2 .....but the difference is: I am using latest ffmpeg master git with last commit and other gits with latest patches.....plus he is using --enable-version3 switch ....I am still trying to find out differences ....and getting close to using his parameters without compromising on latest git versions/patches....till now the only feasible reason : my builds are using msys2's bash environment ....thereby forcing me to use \\\ & he is somehow using other environment ...may be powershell or cmd......I need some time to dig out the real reason.

TIP: If ffmpeg -buildconf shows --enable-vmaf then indeed it is compiled with vmaf....hence the only thing you need is to find a valid path ...if & only if you are not executing command to use an inbuilt model.

fifonik commented 2 years ago

If you turn on writing ffmpeg commands to log you will notice that ffmpeg called multiple times on FFMetrics startup already:

  1. ffmpeg.exe -nostdin -filters -- to check is libvmaf available.
  2. ffmpeg.exe -f lavfi -i color=c=black:s=320x240:d=1 -lavfi [0:v][0:v]libvmaf=model_path=path/to/model.json' -f null - -- to check if json model supported [only called if libvmaf is available + at least one json model found in vmaf-models folder]
  3. ffmpeg.exe -f lavfi -i color=c=black:s=320x240:d=1 -lavfi [0:v][0:v]libvmaf=model_path=path/to/model.pkl' -f null - -- to check if pkl model supported [only called if libvmaf is available + checking for json model failed + at least one pkl model found in vmaf-models folder]

Then ffmpeg called twice for ref:

  1. ffmpeg.exe -t 00:00:02 -i path\to\ref.mp4 -frames:v 30 -filter:v idet -f null - -- to get media info
  2. ffmpeg.exe -ss 1 -i path\to\ref.mp4 -frames:v 1 -f image2 -vf settb=AVTB,setpts=PTS-STARTPTS,scale=-1:200 path\to\Temp\e67e8282-7c47-4232-a311-63348fec99a3.bmp -- to extract thumbnail

Finally, ffmpeg called once per distorted file:

  1. ffmpeg.exe -t 00:00:02 -i path\to\distorted.mp4 -frames:v 30 -filter:v idet -f null - -- to get media info

So ffmpeg is already called too many times on startup and it is quite big and heavy (this is the reason I recomment shared build, it is way faster, especially on low end PCs). This is the reason that FFMetric startup time is a bit high and so I do not want to call ffmpeg more and more for feature detection purposes. However, looks like build-in vmaf model is a way to go, so I'm going to add additional calls that will check if they available.

Right now you can try to use built-in models (I implemented it partically, but have not checket it as I do not have own compiled ffmpeg.exe with built-in models and do not know if any gyan/BtBN's build have them).

To do so you will need:

  1. Rename vmaf-folder so FFMetric will not find external models;
  2. Edit FFMetrics.conf and add "built-in": true in models' sections (you should see "built-in": false in for "vmaf_v0.6.1neg" as an example);
  3. Edit FFMetrics.conf and put libvmaf params in new format in "Filter", something like this: "Filter": "libvmaf=eof_action=endall:n_threads={{n_threads}}:pool={{pool}}:log_fmt={{log_fmt}}:log_path='{{log_path}}':model=version={{model_version}}|enable_transform={{enable_transform}}"

I hope it will work %-)

ls-milkyway commented 2 years ago

So ffmpeg is already called too many times on startup and it is quite big and heavy (this is the reason I recommend shared build, it is way faster, especially on low end PCs). This is the reason that FFMetric startup time is a bit high and so I do not want to call ffmpeg more and more for feature detection purposes.

I can understand.....not much into coding...but I guess with some parallelization (an old pc suffers...but i guess ..dual core are the least now-a-days) and efficient/smart logic you can reduce some loading delays.....the logic for vmaf I guess should be:

If (detect vmaf) AND (detect built-in model OR path c:\:/ OR path c\\:/ OR path C\\\:/) = TRUE then enable vmaf ELSE print "Vmaf not detected ...please use latest ffmpeg with vmaf (put a link to BtbN) " I mean: 1) You just need to check if vmaf is compiled or not. 2) Check 4 possibilities: .path built-in OR path <drive>\:/ OR path <drive>\\:/ OR path <drive>\\\:/ before throwing vmaf not detected error. 3) Forget about calling ffmpeg for pkl model or detecting json or not ....because json model is now a de facto ....sooner built in json models will be the de facto as some old builts are updated (a user by chance may be using an old non inbuilt vmaf model version of ffmpeg).

Lastly, when you are absolutely sure about the use of most efficient/quick logical flow of starting the ffmetrics ...then you can put a progress bar on the UI ...stating "Loading FFmetrics.............." "Gathering mediainfo........." "Detecting psnr & ssim." Detecting....vmaf".......this way it engages the user ...instead of putting a sort of doubt that the app may be hung.

Right now you can try to use built-in models (I implemented it partically, but have not checket it as I do not have own compiled ffmpeg.exe with built-in models and do not know if any gyan/BtBN's build have them).

Both BtbN & Gyan have built-in models .....you don't have compiled version???....even my ffmpeg which I sent to you ....have built-in models .....all that we have to do is to find a proper command that is universal to all 3 or BtbN & Gyan atleast.

OR Publish the source code so that others can join and contribute.

ls-milkyway commented 2 years ago

Check 4 possibilities: .path built-in OR path \:/ OR path \:/ OR path \\:/ before throwing vmaf not detected error.

Not needed as it was missing package VIM (xxd.exe) causing path error...default code used in FFmetrics 1.0.0 is working fine.You can close it.

fifonik commented 2 years ago

Thank you very much for this info! So looks like we do not need the "Escape" option I've just added.