API: How to use user_variables to name the output file

Questions and answers on how to get the most out of FFAStrans
Post Reply
gdpodesta
Posts: 38
Joined: Tue Mar 26, 2019 6:11 pm

API: How to use user_variables to name the output file

Post by gdpodesta » Thu Dec 12, 2019 11:20 pm

Guess this REALLY sounds like a newbie question, but I am submitting a new job with the API quite successfully, and including a uservariable to specify the name of the output filename I would like

Code: Select all

$body = array( 
	'wf_id' => $wf_id, 
	'inputfile' => $input_file, 
	's_myfilename' => $broadcast_filename
);
I submit the job, and it proceeds and completes as expected. However, I'm am completely missing the boat on how to USE the variable 's_myfilename' in FFasTrans. I can see a number of places to select them, but mine is not on the list anywhere. How do I get them there to begin with, so that I can select them in building the output filename in the FFmpeg output node?
The installation is almost vanilla. A single Workflow that the API submits to, with single output folder.
UPDATE
: I added the variables to an .ini file, and they're now visible.
I've since found a newer post that submitted the variables like this, but still no luck. All I can get is an output file named "%s_myfilename%.mp4"
"variables":[{"name":"s_myfilename","content":"myfilename"}]
12-12-2019 4-53-15 PM.jpg
12-12-2019 4-53-15 PM.jpg (75.61 KiB) Viewed 707 times
Further Update
Having tried a "Populate Variables" node, it will work if values are added there, so it must be how I'm submitting them with the API.
I've now tried submitting them in all ways that I know, all at once, hoping one would be right - no luck, so I'm at a loss as to how to get them into the workflow.
Posted with http://localhost:65445/api/json/v1/jobs

Code: Select all

array = 
  wf_id: string = 20190326155521
  inputfile: string = C:\TVNI-S8E47.original.mp4
  s_transcoded_filename: string = TVNI-S8E47-20191212_broadcast
  transcoded_filename: string = TVNI-S8E47-20191212_broadcast
  variables: string = [
     {"name":"s_transcoded_filename","content":"TVNI-S8E47-20191212_broadcast"},
     {"name":"transcoded_filename","content":"TVNI-S8E47-20191212_broadcast"}
  ]
In all variations of tinkering, the final output is "TVNI-S8E47.original%s_transcoded_filename%.mp4"

emcodem
Posts: 509
Joined: Wed Sep 19, 2018 8:11 am

Re: API: How to use user_variables to name the output file

Post by emcodem » Fri Dec 13, 2019 8:14 am

Hey gdpodesta,
i recognize you actually have not been welcomed here, so: thanks for using FFAStrans and welcome to the forum!
Were you able to solve your "prepend video" question from the last time? :-)

Basically i recommend to check out the webinterface, you can submit jobs there with variables and check out the POST Body using your browser debug (F12) interface.

However, to make your life easy, i just submitted a job with variable through the webinterface and copied the post body for you:

POST to: http://localhost:3002/proxy/api/json/v1/jobs/

Code: Select all

 {"wf_id":"20191213090328","start_proc":"other_textfile 20191213-090402-864-869eca762fe5","inputfile":"D:\\neu\\SL_01_Wien\\AVI\\Laursen_vs_Chapman.mov","variables":[{"name":"s_test","content":"test"}]}
You will notice that the variable name "s_test" is exactly the same than ffastrans would show when used in a processor but without the percent signs.
In this case, i created and and used a variable named %s_test% in my workflow. The workflow itself only had a Generate text file processor (really not more than that), which writes %s_test% to a file.


Also check in your specific case using error_log or similar, the exact string that your array function will end up in. You need to build a json object, not a json array. Also you have to put your variables into the first level child "variables", which is an array of all variable name->value pairs.

Also, here is another example you can use for investigating:
viewtopic.php?f=5&t=849&p=4486&hilit=beginners#p3586

gdpodesta
Posts: 38
Joined: Tue Mar 26, 2019 6:11 pm

Re: API: How to use user_variables to name the output file

Post by gdpodesta » Fri Dec 13, 2019 5:21 pm

Firstly, thank you for the welcome. My previous question wound up using other methods as the number of variables was becoming too complicated with my limited understanding of FFAStrans at the time (more about that later). For this question however, it looks like I might have been json encoding part of the body twice before posting (extra escaping was there) :oops: . What the Web Interface produced for me was exactly what I thought I was doing, but a fresh start with the code produced it perfectly.

:idea: To clarify what I learned, and be sure I'm on the correct path, let me summarize:
  1. User Variables are introduced to FFAStrans by manually adding them to the [user_variables] section of ffastrans.ini
  2. To implement a User Variable in a workflow, one must first add a "Populate Nodes" to the workflow, then later disable/delete it
  3. User Variables must begin with s_ and are evaluated by wrapping them with % signs
:?: Subsequent Questions:
  1. What is "start_proc" that is being posted?
    I initially included it in my test, but later removed it to see what would happen, and it had no impact.
  2. Can a User Variable be used in a custom FFmpeg node?
    I took a quick stab at it to force a maximum duration by adding -t '%s_max_duration%" to Options, but it resolved to -t '0'
    I quit while I was ahead, and will look at that later if it's possible.
And finally, with more exposure to FFAStrans, I'm impressed beyond words. I've spent 40 years building tools/interfaces like this, and absolutely love what you've done.

emcodem
Posts: 509
Joined: Wed Sep 19, 2018 8:11 am

Re: API: How to use user_variables to name the output file

Post by emcodem » Sat Dec 14, 2019 6:23 pm

Hey, thats great questions!
First of all, fortunately the time of manually ediding file is over since some time in FFAStrans. I strongly encourage you to use the User interface instead of manually editing ini files, especially the workflow ini. To create new user_variables, you just open the variable selector (Bold > symbol near to any input text field in most processors), on the top you select user_variables and there you create/delete user_vars.

Most of your questions should be solved here.
viewtopic.php?f=5&t=849&p=4486&hilit=beginners#p4486

I'd like to recommend you to play with the workflows there as you seem to have lots of basic questions to clear which are explained in detail in this example thread.

Most important, you have to understand the scope of variables: once a user variable is created, you can use it in all text boxes of all processors in all workflows. But the value of a user variable (in difference to STATIC vars) only counts for the currently running branch, so you should have a close look into how branching works as well in the learning thread above. So there is also no need to "reset" a variable.

What is "start_proc" that is being posted?
The "start_proc" is optional in the API, it is basically the processor that you want the workflow to start with, if you omit it in the API call, it will be selected automatically (fun when there are more than 1 workflows in the canvas). You can start the workflow at every processor, just as you can righclick-submit file on the gui canvas.

Can a User Variable be used in a custom FFmpeg node?
as said, user_vars can be used in every textbox. Especially the custom_ffmpeg command just builds a string, so if it resolved to "0" for you, then you clearly did set the value "0" to your variable in a (populate vars) processor before.


And by the way, my reaction was just the same as yours when i discovered ffastrans the first time. @admin is the one to thank for this all!

Post Reply