0

I'm looking around but I just don't understand / don't work for me. I would like a system that writes on a txt the number of black frames (total) at the beginning of the video (any type of video, x264 x265 etc. Mainly .MP4 _ AVC / .MKV _ x264 - x265).

Basically, with Aegisub if you open a video, you can scroll by frame and see the exact number of black frames (which are inserted by whoever made the release) ... The problem is to do it for 100 and pass episodes and above all you have to wait for Aegisub initialize the video (sometimes for some BD x265 it can be 2 minutes).

So the process is:

  1. 2 Videos, 1 where I get the subtitles, usually the Web / TV track (which may not have the usual 24 black frames) and 1 which will be used as a new video track (which can have 24/42 black frames at the beginning of the video ).

  2. I open the videos on Aegisub (waiting from 30s to 2 minutes);

  3. I check the end of the black frames and write the results on a TXT.

TXT Ex:

        Cleo  / Snow-Raws / lovely / The Aster       [24+ = 1001ms]

Ep01: 24+ / 24+ / 0    / 24+
Ep02: 24+ / 0   / 24+  / 0
Ep03: 24+ / 0   / 24+  / 0
Ep04: 24+ / 24+ / 24+  / 24+
Ep05: 24+ / 0   / 24+  / 0
Ep06: 24+ / 0   / 24+  / 0
Ep07: 24+ / 24+ / 24+  / 24+
Ep08: 24+ / 0   / 24+  / 0
Ep09: 24+ / 0   / 24+  / 0
Ep10: 24+ / 24+ / 24+  / 24+
Ep11: 24+ / 0   / 24+  / 0
Ep12: 24+ / 0   / 24+  / 0

0 indicates that the video starts immediately with a frame that is not black (the episode image).

Looking around I found a script for AviSynth, obviously it doesn't work for me (for me, things never go to the first).

This is the script:

#Script to find blank frames
#The script outputs the frame number of the first frame that falls below
#the threshold luma value. 

Loadplugin("C:\Program Files (x86)\AviSynth+\plugins\ffms2-2.40-msvc\x64\ffms2.dll")

#Specify the name and location of the output file
filename = "D:\blank_frames.txt"

#Specify the blank threshold. Set to zero for pure black.
global blankthreshold=0

#Specify the name and location of your video file
FFmpegSource2("\\WS2019\Storage5\Anime2\DanMachi\Stagione 02\DanMachi - s02e02 - Cleo + LovelyHestia [TV] - .mkv").killaudio()


#Optional: For analog captures, get rid of the borders.
#          Analog video can have border garbage that affects averageluma
Crop(16,16,-16,-16)

# Use the following to reduce the number of fields by 50% in order to speed processing
separatefields.selectodd

i=last
j=trim(i,1,0) #Previous frame [edit] Actually, it is the NEXT frame

# Temporarily un-comment next line to display the average luma value on screen to help determine threshold value
#ScriptClip(i,"Subtitle(String(AverageLuma(i) ))" )

#This line below will output EVERY frame that is below threshold, which results in LOTS of frames
#Normally you don't do this, but it is included for those who want this capability.
#WriteFileIf(last, filename,  "(AverageLuma(i)<blankthreshold)", "current_frame+1", append = false)

#This is the line that actually writes the frame number of the FIRST frame that falls below the threshold
WriteFileIf(last, filename,  "(AverageLuma(i)<blankthreshold)&&AverageLuma(j)>blankthreshold", "current_frame+1")

#The line below finds the LAST blank frame. 
#WriteFileIf(last, filename,  "(AverageLuma(i)>blankthreshold)&&AverageLuma(j)<blankthreshold", "current_frame+1", append = false)

Basically the script "starts" (I still don't understand how AviSynth works) but the "blank_frames.txt" file is empty, 0kb. I use "AviSynth +" for Windows with AvsPmod and MPC-HC / MPC-BE. I also have AviMeter but it doesn't do anything either.

Finally, I also found the "guides" if you use FFmpeg but from what I see, from a command line output and I don't know how to automate the process so that with a .bat throwing the video on it, it automatically starts the command which will then save the number of black frames at the beginning of the video in a TXT.

Links: https://stackoverflow.com/questions/58971875/is-there-a-way-to-detect-black-on-ffmpeg-video-files

https://stackoverflow.com/questions/18722747/can-you-put-the-result-of-a-blackdetect-filter-in-a-textfile-using-ffmpeg/18726326

https://www.ffmpeg.org/ffmpeg-filters.html#blackframe

So I would like to understand if there is an .exe or a .bat created by someone to do this thing or how:

  1. run this Script or ffmpeg command line on windows with batch (for now I have ffmpeg for audacity);
  2. "automate" the process (if possible) so that it is enough to release the video or videos on the .bat or .avs (avisynth script) and this saves the black frames found on a txt (not necessarily txt but something simple goes well, ex: csv, excel etc.).

For automation, I just need to know if it can be done. I know 2 3 commands for "Batch" but I'm not sure if they work when used on AviSynth / FFmpeg which I don't know about.

It sounds silly but I noticed that this AviSynth script starts the whole video (as if I were watching normally), I would not want it to ... not write the TXT until it finishes watching. What it needs to do is check how many black frames there are from frame 0 to the first non-black frame (usually no more than 6000ms of video).

Thanks in advance and I hope I have not done something wrong.

5
  • A lot of text here to parse... Do you need help with 1) The ffmpeg command? 2) Making the batch-file? 3) Everything?
    – llogan
    Commented Nov 17, 2020 at 19:32
  • The result is a TXT with written how many black frames (or ms) are seen in the first 6 seconds of any video (mkv, mp4 / x264, x265). Looking around I found:AviSynth script (that doesn't work for me, leave the txt empty); The command to use on FFmpeg but I don't know how to simplify the process to get a txt with frames of black frames. Furthermore, only the black frames of the first 6 seconds of video are enough for me (otherwise it takes at least 4 minutes to analyze the black frames of the whole video. I hope I was clear.
    – Geass
    Commented Nov 17, 2020 at 21:45
  • See Can you put the result of a blackdetect filter in a textfile using ffmpeg?. See both answers as one might be better for you than the other.
    – llogan
    Commented Nov 17, 2020 at 23:30
  • Ok, it works. I automated with: for %%1 in ("*.mkv") do ffmpeg -i "%%1" -t 6 -vf "blackdetect=d=0.1:pix_th=0.00" -an -f null - 2>&1 | findstr black_duration >> TMS.txt. Thanks for the "-t 6". I'm looking at how to make sure that you answered / close the question.
    – Geass
    Commented Nov 18, 2020 at 0:54
  • You can just make your comment the answer.
    – llogan
    Commented Nov 18, 2020 at 1:02

1 Answer 1

1

Thanks to llogan, who passed me "-t 6" the solution is:

for %%1 in ("*.mkv") do ffmpeg -i "%%1" -t 6 -vf "blackdetect=d=0.1:pix_th=0.00" -an -f null - 2>&1 | findstr black_duration >> TMS.txt

for .bat drag and drop; automatically creates a TMS.txt with the duration written in black for the first 6 seconds of each "* .mkv" in the same directory as the drag and drop file.

ffmpeg -i %1 -t 6 -vf "blackdetect=d=0.1:pix_th=0.00" -an -f null - 2>&1 | findstr black_duration >> "%~n1".txt

This instead creates a .txt with the same name as the input file and works only for single file.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .