Can you put the result of a blackdetect filter in a textfile using ffmpeg?

If using ffprobe is acceptable there is now a simpler way to do it with metadata injection:

ffprobe -f lavfi -i "movie=input.mp4,blackdetect[out0]" -show_entries tags=lavfi.black_start,lavfi.black_end -of default=nw=1 -v quiet

The command outputs only the lavfi tags black_start and black_end.

The advantage is you can also get frame information etc, or multiple tags in a format which is easier to parse.

ffprobe can also output JSON or XML but I can't find a way to skip the frames with no tags which produce empty nodes. This should be easy to patch though.


See aergistal's answer for a newer, simpler method that was not available at the time this answer was made

Is there a way to only take the blackdetect filter output and put it in a .txt file?

By default ffmpeg logs to stderr. You can output to stdout and then use grep to isolate the blackdetect lines:

$ ffmpeg -i video1.mp4 -vf "blackdetect=d=2:pix_th=0.00" -an -f null - 2>&1 | grep blackdetect > output.txt

Resulting in:

$ cat output.txt 
[blackdetect @ 0x1d2b980] black_start:5.16 black_end:10.24 black_duration:5.08 

If you want to append to output.txt instead of overwriting for each instance then use >> instead of >, as in: blackdetect >> output.txt.


Is there a way to do this in a statement with multiple video inputs?

You can use blackdetect with the concat demuxer as shown in your question, but be aware that the black_start and black_end times will be cumulative, and not independent to each input, because you are concatenating all inputs.

Alternatively you can use a bash "for loop" if you want each input to be independently run through blackdetect:

for f in *.mp4; do ffmpeg -i "$f" -vf "blackdetect=d=2:pix_th=0.00" -an -f null - 2>&1 | grep blackdetect > "$f".txt; done

This may create empty txt files.

Tags:

Ffmpeg