Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic Target File Path #1346

Open
flesnuk opened this issue May 7, 2024 · 4 comments
Open

Dynamic Target File Path #1346

flesnuk opened this issue May 7, 2024 · 4 comments

Comments

@flesnuk
Copy link

flesnuk commented May 7, 2024

Is your feature request related to a problem? Please describe.
I'm trying to "imitate" the feature of handbrake where the target filepath gets automatically updated after you change any encoder option like CRF or preset, etc. For now I managed to use the Event Command but I feel limited for one thing. I can set up the event trigger to be on Before Job Processed or After Source Loaded, but still not quite optimal because:
After Source Loaded: once it loads, the target filepath and project name remains the same as the default Project or Template config. After you change some setting in the encoder, it won't update anymore and remain as is (I mean, the filename changes to x265_crf18.mkv but doesn't update anymore).
Before Job Processed or Before Processing: this address the previous problem, but this only applies when starting the Job.
What I want is being able to schedule multiple Jobs with different CRF or encoder settings and then at the end launch all of them and compare the results afterwards.

So I managed to get the filepath to be how I like it, ending with _av1_crf34_preset8.mkv for example. But I'm failing at trying to update somehow the target filepath "dynamically" in some way, without resorting to powershell scripting.

Describe the solution you'd like
It would be nice to have a new event triggered by VideoEncoder.OnStateChange() for example, so when you close the Encoder Options window, you can trigger an event like EncoderSettingsUpdated and put that into the Event Commands Editor.
The only limitation I find myself is I cannot create multiple jobs with different settings because the filepath remains the same (until the job is finally launched that is) and wouldn't add a new Job when clicking Add Job.

Describe alternatives you've considered
The only alternative I can think to this would be using a Powershell script and launching it manually after I have got all my encoder settings set.
For example

$crf = $activeProject.VideoEncoder.Params.ConstantRateFactor.Value
$activeProject.TargetFile = "PATH\myvideo_crf" + $crf + ".mkv";

Explain why the feature matters to you
I thinks this would be a nice addition for batch encoding the same file with different settings, so you can experiment quickly by letting StaxRip launching all jobs and coming back later and comparing the results. It's tedious to wait for the job to launch/finish and then modify the settings again.

Additional context
Of course, I might missing something with how StaxRip manages the target file or updates, and maybe the solution is simpler than adding anything to the code. I just discovered the Event Command today (I only knew about PS scripting) and seems a much simpler and awesome way to do powerful stuff in StaxRip rather than using powershell.

PS. The target file path expression I come up for the event command in case someone finds this thread while searching:
%target_dir%\%source_name%_%eval:"%encoder%" -replace "SvtAv1EncApp","av1"%_%eval:((Select-String -InputObject "%encoder_settings%" -Pattern "(crf \S+)|(preset \S+)|(film-grain \S+)" -AllMatches | Foreach {$_.Matches.Value}) -join "_") -replace "\s",'' -replace "film-grain","fg" %.%muxer_ext%
The -Pattern option is for specifying what encoder settings I want in the filename.

@Dendraspis
Copy link
Collaborator

Whatever solution I might think of, it will be very complex to implement and hard to use. Every encoder has to be supported, names have to be unique, path length should be less than 260 ... and what if file name exists?

It's tedious to wait for the job to launch/finish and then modify the settings again.

Sure, but why??
You can add a job with a target file for example ABC_CRF23.mkv, you click on Add Job and then you enter the Encoder Options again to modify the CRF value to 24. You click ok, modify the target file to ABC_CRF24.mkv, click Add Job and then you enter the Encoder Options again. This time you adjust the BFrames to 8, click Ok and rename the target file to ABC_CRF24_BF8.mkv before you click on Add Job.
After adding the first job, you can also run a second instance and let it start the first job while you add the others in order to not waste time.

Right now I don't see any advantage that would come with your request, despite the fact, that you would not have to add some characters to the target file name. I do it often, but it never bothered me that much to do so.

@flesnuk
Copy link
Author

flesnuk commented May 7, 2024

I see, for me creating a new type of Event and call it something like EncoderSettingsChanged triggered at the end of the method OnStateChange() from VideoEncoder class would be enough to solve this issue. Since then you can listen for that event in the Event Commands and be able to update the Target Path with SetTargetFile command as I defined above.
But since I don't know the specifics of how everything connects together in the app, then maybe it was wishful thinking, I see there is some method like RaiseAppEvent() which handles many more things, so yeah, adding a new event doesn't seem as I easy as I thought. 😄

Anyway, I think for this task, is more useful to create a Powershell script with for-loops iterating over the encoder settings I want to test (e.g.: iterating over an array of crfs [20,25,30]) and creating a Job for each one. That is if I insist in using StaxRip, because this looks more like job for a shell script at this point 😅

@Dendraspis
Copy link
Collaborator

It might take a while, but I will see if I can properly add an encoder options based event. But in case I'm not missing anything: Even with an event like that, you still have only the whole parameters, no delta. StaxRip itself has no ability to put code inside, so you would end up creating event commands for each encoder parameter, because you can call a PowerShell script, but that script won't be able to set the target file name. 🤔

Indeed. 😅

@flesnuk
Copy link
Author

flesnuk commented May 8, 2024

Also, if it's easier a BeforeAddingJob event would also work.
I'm not sure if I follow along, the only important thing is getting the event to trigger when there is a change, I don't care about the event parameters. That is so the Event Command gets triggered and the target file gets set again.
I will try to explain again with screenshots just in case
I have set this event command
image
So when you load a video you get the target file based on the project's default encoder settings:
image
Just in case, to not get confused by the complex expression for the SetTargetFile, here is a simpler one:
%target_dir%\%source_name%_%encoder_settings%.%muxer_ext%
Which would produce this target file: C:\Users\flesn\Videos\00000-720_crf 18 output-depth 10 colorprim bt709 colormatrix bt709 transfer bt709 range limited.mkv
Hence the complex expression to filter specific parameters. But doesn't matter for the issue.
So, if I now change any encoder param, the target file won't be updated anymore, because the Event trigger is "After Source Loaded"

One way I tried solving this is by changing/duplicating the event command and now listening for the event Before Job Processed.
In this case, everything stays the same, but the resulting output file it's correct.
image
image
So the only issue here is that if I click Add Job, I can't add many jobs at once because the target file stays the same, even though the resulting file would be correct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants