Detect 1 sec black at the end of files

Questions and answers on how to get the most out of FFAStrans
Post Reply
Ian_Grey
Posts: 6
Joined: Fri Dec 02, 2016 8:19 pm

Detect 1 sec black at the end of files

Post by Ian_Grey »

Hi,

I am using FFAStrans to check master files against various broadcaster tech specs and it is working remarkable well.

One broadcaster needs to have 1 sec of black at the end of a file that operators sometimes miss. Is there a way to detect if a file has black for the last 25frames of the file?
emcodem
Posts: 1646
Joined: Wed Sep 19, 2018 8:11 am

Re: Detect 1 sec black at the end of files

Post by emcodem »

Hey Mr Grey,

lucky you just yesterday i did the same but 1 frame at start. I did alter it for you:
emcodem_blackdetect_at_end.json
(3.98 KiB) Downloaded 67 times
Please try out this one. Check out the commandline processor parameters,

Code: Select all

-sseof -1
Tells ffmpeg to seek -1 second from end.

Code: Select all

blackdetect=d=0.9
Tells ffmpeg to alert if 0.9 seconds were black.

Just edit the values until it detects exactly what you like.
Take care, you cannot seek to -1 seconds and seek for 1 second black because the blackdetect would only report if black is longer than 1 second, so it would never detect because you only check exactly 1 second.
Also, if you seek -2 seconds and detect 1 second black, you would be notified that there is 1 second black WITHIN the last 2 seconds, not at the very end where you are looking for it to be.

Also, if there is too much black detected, you might want to add a thresshold, e.g.
blackdetect=d=2:pix_th=0.00
https://ffmpeg.org/ffmpeg-filters.html#blackdetect
emcodem, wrapping since 2009 you got the rhyme?
emcodem
Posts: 1646
Joined: Wed Sep 19, 2018 8:11 am

Re: Detect 1 sec black at the end of files

Post by emcodem »

and @Ian_Grey please don't forget to report if it worked or if you maybe did it totally different in the end. It is always helpful for forum readers to know if the proposed stuff worked or not :D
emcodem, wrapping since 2009 you got the rhyme?
movalex
Posts: 31
Joined: Thu Feb 06, 2020 2:23 pm

Re: Detect 1 sec black at the end of files

Post by movalex »

I think the -sseof -1 option does not work for the blacks detect.

Code: Select all

ffmpeg -i "D:\RENDER\test_black.avi" -sseof -1 -vf "blackframe=thresh=32:amount=50" -an -f null - 2>&1 | findstr "Parsed_blackframe" >> "blacks.txt"
At least for me it does not return anything despite there's some blacks frames present at the end.
However if I manually run blackframe check over the whole file, I receive a list of black frames relatively quickly:

Code: Select all

ffmpeg -i "D:\RENDER\test_black.avi" -vf "blackframe=thresh=32:amount=50" -an -f null - 2>&1 | findstr "Parsed_blackframe" >> "blacks.txt"
[Parsed_blackframe_0 @ 00000238859ba1c0] frame:0 pblack:100 pts:0 t:0.000000 type:I last_keyframe:0
[Parsed_blackframe_0 @ 00000238859ba1c0] frame:1 pblack:100 pts:1 t:0.040000 type:I last_keyframe:1
[Parsed_blackframe_0 @ 00000238859ba1c0] frame:2 pblack:99 pts:2 t:0.080000 type:I last_keyframe:2
[Parsed_blackframe_0 @ 00000238859ba1c0] frame:3 pblack:57 pts:3 t:0.120000 type:I last_keyframe:3
[Parsed_blackframe_0 @ 00000238859ba1c0] frame:42 pblack:93 pts:42 t:1.680000 type:I last_keyframe:42
[Parsed_blackframe_0 @ 00000238859ba1c0] frame:43 pblack:100 pts:43 t:1.720000 type:I last_keyframe:43
[Parsed_blackframe_0 @ 00000238859ba1c0] frame:44 pblack:100 pts:44 t:1.760000 type:I last_keyframe:44
[Parsed_blackframe_0 @ 00000238859ba1c0] frame:45 pblack:100 pts:45 t:1.800000 type:I last_keyframe:45
[Parsed_blackframe_0 @ 00000238859ba1c0] frame:46 pblack:100 pts:46 t:1.840000 type:I last_keyframe:46
Basically I need to check if the first and last frame of the file are black. Is it possible to get and parse this list with FFAStrans?

UPD:
Ok, it actually works, I should have put the -sseof -1 BEFORE the -i option... Sorry, false alarm:

Code: Select all

ffmpeg -sseof -1 -i "D:\RENDER\test_black.avi"  -vf "blackframe=thresh=32:amount=50" -an -f null - 2>&1 | findstr "Parsed_blackframe" >> "blacks.txt"
Works beautifully, thanks!
emcodem
Posts: 1646
Joined: Wed Sep 19, 2018 8:11 am

Re: Detect 1 sec black at the end of files

Post by emcodem »

movalex wrote: Thu Feb 09, 2023 6:39 pm
Ok, it actually works, I should have put the -sseof -1 BEFORE the -i option...
Yeey, congrats on getting it working :D And thanks for the response!
It is possible that it don't work exactly with -sseof (before -i) but in that case ffmepg is not able to seek in the container. But i guess such file formats are not subject to be sources for this kind of professional operations and they should be normalized to professional formats anyways.
emcodem, wrapping since 2009 you got the rhyme?
Conniver
Posts: 36
Joined: Thu Jan 12, 2023 8:32 am

Re: Detect 1 sec black at the end of files

Post by Conniver »

Is there any example workflows or resources where I can find info about checking tech specs with the tools available to FFastrans?
I've managed to create a decent proxy generating workflow (thanks emcodem), and next on the list is a QC / tech spec workflow.
emcodem
Posts: 1646
Joined: Wed Sep 19, 2018 8:11 am

Re: Detect 1 sec black at the end of files

Post by emcodem »

@Conniver that's definitely worth another thread :D
It's like no, we don't have anything in general and there is much possibilities. It depends on what you plan to do. E.g. Simple basic values checking like width, height, bitrate, audio layout... well we got inbuilt variables, functions and a conditional processor for that :D
Also, for very specialized XDCAM compliance error i had this example: viewtopic.php?f=5&t=1270&p=6881&hilit=silicon#p6881
emcodem, wrapping since 2009 you got the rhyme?
Post Reply