georgmartius / vid.stab

Video stabilization library
http://public.hronopik.de/vid.stab/
Other
838 stars 110 forks source link

[Question] Can we know the final zoom before 2-pass encoding? #101

Closed fu-hsi closed 3 years ago

fu-hsi commented 3 years ago

Hi. I want to know Final zoom for all clips after 1-pass encoding. I have trf files and how to know what Final zoom will be applied? Now I must run 2-pass encoding to know this (from console log). I need know this parameter before run 2-pass encoding to set optimal parameters. Regards.

georgmartius commented 3 years ago

Hi, I know you also had another request, but I could not look into this yet. Can you maybe explain why you need to set the zoom parameter manually before pass 2? Georg

georgmartius commented 3 years ago

There are different settings for the zoom see https://ffmpeg.org/ffmpeg-filters.html#vidstabtransform-1

optzoom Set optimal zooming to avoid borders.

Accepted values are: ‘0’ disabled ‘1’ optimal static zoom value is determined (only very strong movements will lead to visible borders) (default) ‘2’ optimal adaptive zoom value is determined (no borders will be visible), see zoomspeed Note that the value given at zoom is added to the one calculated here.

So 1 is the default and creates a fixed zoom with a value, such that 98% of time there is not border visible. What do you want to do?

fu-hsi commented 3 years ago

Because there have been situations in the past where too much zoom has been applied. I prefer to set a fixed zoom on all my clips, it is more natural for me. I calculated the average zoom in OpenCalc and 7x is just right for me for the last movie. I want to speed up this process. Regards.

fu-hsi commented 3 years ago

Accepted values are: ‘0’ disabled ‘1’ optimal static zoom value is determined (only very strong movements will lead to visible borders) (default) ‘2’ optimal adaptive zoom value is determined (no borders will be visible), see zoomspeed Note that the value given at zoom is added to the one calculated here.

I know that, but this is not solution for my problem. I want only calculate/display final zoom before 2-pass encoding.

[vidstabtransform @ 000000f499dfe248] Final zoom: 6.028248

georgmartius commented 3 years ago

So what do you do with this "final zoom value" afterward? Because you can specify zoom in addition which will get added to this value. So "final_zoom: 6" and zoom=-2 would result in a fixed zoom of 4. Does this help? Georg

fu-hsi commented 3 years ago

I don't get you at all, sorry. What I need I wrote above. If I must run encoding only for display "Final zoom" in console, that's insane. Why I can't display this value from trf file? Why I must run 2-pass encoding for that? This value must be known earlier anyway. What I do with this value is not important. You keep trying to lead me to a different path. I know what I am doing, I know the parameters of this library quite well. I can calculate it by my self and make script for this task, just tell my what this values means in my trf file (the last line):

VID.STAB 1 # accuracy = 15 # shakiness = 10 # stepsize = 6 # mincontrast = 0.250000 Frame 1 (List 0 []) > Frame 2 (List 149 [(LM 6 -5 746 647 144 0.353665 0.667294),(LM 1 -1 1390 647 144 0.344630 0.659915)

If that's impossible, we can close this Question. Regards.

georgmartius commented 3 years ago

Okay, sorry I did not mean to piss you off. I just thought it might be good to really understand what is needed. Maybe one could add an option that would do what you want. Honestly, I still don't understand how you want to compute the fixed zoom you need.

The computation is a bit more intricate than you might think. The trf file contains local motions: LM 6 -5 746 647 144 0.353665 0.667294 v.x, v.y, f.x, f.y, f.size, contrast, match This is the vector of motion v, the measurement field position f, the field size, its contrast and how good the match was. Now all these little motion vectors are taken together. A RANSAC style algorithm is removing outliers and then the best fitting global translation and rotation is computed.

In the newest version, since just a few days ago, the trf file will be binary, so you have to load it with the same serialization routines. Why not running the second pass with -t 0:01 then it will only do one frame, but vid.stab will still look at the entire trf file and compute what you need.

georgmartius commented 3 years ago

There is also the debug option, that creates the globalmotions file, which is still an ASCII format. That contains the globally applied transformation. But it is also computed in the second pass.

fu-hsi commented 3 years ago

Why not running the second pass with -t 0:01 then it will only do one frame, but vid.stab will still look at the entire trf file and compute what you need.

If it works, it will actually be enough. I thought about terminating the script, but this solution is brilliant in its simplicity. Thank you.

fu-hsi commented 3 years ago

-frames:v 1 does it better and extract exactly one frame :) It still need initialize 2-pass process that consumes probably more time than encoding one frame :) But that's enough for me.

georgmartius commented 3 years ago

Good point. The time would anyway be needed to compute the value you want. It does the full optimization of the camera path etc. Great that it works for you.

fu-hsi commented 3 years ago

It is one of the best stabilization software available as a plugin what I've tested and use. This speeds up the process a lot because we can only launch our script by one click and stabilize hundreds of video clips on specified directory and we can go to sleep. I tested many video editors and none of it has that stupid simple option like "stabilize selected files". We must stabilize each separately by selecting clip, waiting to end... and then we can select another clip (e.g. DaVinci Resolve). This may take hundreds of hours.