Write FFMepeg results to use as Conditionals

Questions and answers on how to get the most out of FFAStrans
knk
Posts: 38
Joined: Wed Jun 21, 2017 3:50 pm

Write FFMepeg results to use as Conditionals

Post by knk »

Hi!
I need a specific number of black frames on the beginning and end of videos entering a folder. Made a workflow adding those frames, works perfectly.
Now the problem is some clips already come with those frames so I end up doubling the black frames, so it becomes an issue.
FFMpeg has the blackdetect function that could help me use a Conditional Node to direct the processing to whether it needs/doesn't need to add them.
My question: is it possible to write a txt file, for example, with an FFMpeg process, then have FFASTrans look for if "blackdetect" lines exist in that txt in order to make a decision to redirect the workflow branch?
Thanks in advance!
Sidenote: this is an amazing tool!
momocampo
Posts: 595
Joined: Thu Jun 08, 2017 12:36 pm
Location: France-Paris

Re: Write FFMepeg results to use as Conditionals

Post by momocampo »

Hello knk,
Not sure it is exactly what you want but you can use a command executor node to apply your ffmepg command (blackdectect), use the "SDTOUT field to populate your result to a variable. Then use a conditional with your variable to choose the way that you want.
You can also create a txt file (generate text file node) with what you want inside, use populate variable node to read the string inside ( "$read" function ) and use your variable to do what you want.
Hope it helps.
Cheers.
B.
emcodem
Posts: 1811
Joined: Wed Sep 19, 2018 8:11 am

Re: Write FFMepeg results to use as Conditionals

Post by emcodem »

Hi knk,

sure not a problem at all, here some example how i would do it (time for some regex, yeeey!):
blackdetect.json
(6.95 KiB) Downloaded 373 times
take note at the commandline executor nodes, the first one detects the black at start of file and the second one at end of file.
At start, i limit the duration being parsed by ffmpeg using -t 3 which means only 3 seconds of the file are being checked. Then blackdetect=d=1 says that the black must be minimum 1 second to be detected.

Second commandline proc, for the end, i use -sseof -2 which means we only search the last 2 seconds of the input file and again blackdetect=d=1 says the black must be minumum 1.
When using the workflow as it is, you must set these parameters in a way that only ONE black is detected in the checked video area. If it detects multiple, you only get the duration of the FIRST found blackout.

When there is no black at all, the commandline procs will end in error, as you see i do catch this (in the example WF only for the start portion) error and allow the workflow to go on.

Details depend on your requirements but the wf above might help you as a starting point
emcodem, wrapping since 2009 you got the rhyme?
knk
Posts: 38
Joined: Wed Jun 21, 2017 3:50 pm

Re: Write FFMepeg results to use as Conditionals

Post by knk »

Wow... you guys are amazing! Thank you so much!
This is exactly what I need.
Best regards to you all
knk
Posts: 38
Joined: Wed Jun 21, 2017 3:50 pm

Re: Write FFMepeg results to use as Conditionals

Post by knk »

Hey!
First of all thanks for your precious help.
Workflow for detecting blacks from start = done! Amazing!

Now, from the end of the file Command Executor terminates in error.
I don't think the function "-sseof" is being processed...

Is there any other way to get the information from the end of clips minus 1sec?

Thanks for your help!
emcodem
Posts: 1811
Joined: Wed Sep 19, 2018 8:11 am

Re: Write FFMepeg results to use as Conditionals

Post by emcodem »

Hey again, nice, thanks for letting us know that the first part works :D

uhmmm... so the wf i uploaded worked as it was and it honored the sseof command. Did you try with my exact, unmodified workflow or are you experiencing troubles with your own one? If your own, could you please upload it here?
You should pay attention that sseof must be a negative number and it must be larger than your blackdetect=d setting, e.g. to detect if the last 2 seconds are black, check the last 3 seconds and supply a duration of black minimum 2, e.g.

Code: Select all

-sseof  -3

Code: Select all

blackdetect=d=2
In words: Check if the last 3 seconds of the input video do contain at least 2 seconds black frames in a row.
emcodem, wrapping since 2009 you got the rhyme?
knk
Posts: 38
Joined: Wed Jun 21, 2017 3:50 pm

Re: Write FFMepeg results to use as Conditionals

Post by knk »

Hey!
Thanks for the reply.

So I've came back to this and tried the original workflow "as is", only added a watchfolder at the beginning and text generator at the end to put down all the variables collected along the way.

I can't make it work. Only when I drop the "-sseof" section on the ffmpeg command.
Otherwise always exits with:
Process exited with error code: 1

Thanks again! And stay safe!
emcodem
Posts: 1811
Joined: Wed Sep 19, 2018 8:11 am

Re: Write FFMepeg results to use as Conditionals

Post by emcodem »

Hey @knk,

so good to hear back but i am sorry that it still dont work for you. I guess you meanwhile work with alternatives to -sseof?
Interesting that you added a watchfolder processor for testing the workflow, do you know about the "submit file" feature in context menu of each processor? Also you use a write text file proc to see variable values, was it not enough for you to see the variable values in the job monitor "Result" column?

Anyway, it would be interesting to see if it works for you just as it works for me using the same input file (attached, just rename from .txt to .mp4).

My results are:
%s_black_duration_start% = 3.04
%s_black_duration_end% = 2.92
Attachments
3s_start.mp4.txt
(623.46 KiB) Downloaded 305 times
emcodem, wrapping since 2009 you got the rhyme?
knk
Posts: 38
Joined: Wed Jun 21, 2017 3:50 pm

Re: Write FFMepeg results to use as Conditionals

Post by knk »

Hey!
Thanks again for the reply!

The watchfolders are just a "standard" to me to set multiple processing on the go, because I like to validate dozens of files before considering anything a success :)
Seeing results in the status window, sure, but when I'm getting errors I prefer to set text files along the way to see what is being used as variables, since I'm not even close to an expert on those matters.

So, regarding the original workflow. Yes, it works perfectly with your mp4 file. I get the same values.
Thing is my workflows are currently locked to MXF formats, and with MXF files doesn't work with -sseof command.

Is there a logical reason for this?
emcodem
Posts: 1811
Joined: Wed Sep 19, 2018 8:11 am

Re: Write FFMepeg results to use as Conditionals

Post by emcodem »

Well i guess that depends on the type of mxf that you have. E.g. i tested the workflow above only using XDCAMHD mxf, this works because they carry a useable index.
However, sseof is definitely not guaranteed to work. the ss option should be somewhat more stable but it gets a little more complex this way.
Before we go down that road i'd like to ask you if you could share one short mxf file where sseof didnt work for you?
https://drive.google.com/drive/folders/ ... sp=sharing
emcodem, wrapping since 2009 you got the rhyme?
Post Reply