1

I have file.mov video. It has a lot of blank black color fragments that have different durations.

I need to replace black color fragments that show up for more than 5 seconds with transparency. Is that possible to add some alpha channel for that purpose?

Comment to Mulvya's answer:

Amazing solution. With #2 section everything ok.

With #1 section I created this code:

output=$(ffprobe -f lavfi -i "movie=file.mov,blackdetect=d=3.5" -show_entries tags=lavfi.black_start,lavfi.black_end -of compact=p=0 -v 0|awk '!/^$/')
echo $output

using awk '!/^$/' to remove empty lines.

Here is the output I get:

output

tag:lavfi.black_start repeats with same value several times, not having right structure with closing tag:lavfi.black_end

If I change blackdetect=d=3.5 to other value, for exaple d=10, it outputs the same result as d=3.5. How could I solve this issue having right tag:lavfi.black_start,tag:lavfi.black_end synthax with correct grepping d= value?

kostya572
  • 169
  • 2
  • 21

1 Answers1

1

#1 Run blackdetect to identify fragments

ffprobe -f lavfi -i "movie=file.mov,blackdetect=d=3.5" -show_entries tags=lavfi.black_start,lavfi.black_end -of compact=p=0 -v 0

Edit: Due to a quirk in the filter, one has to use ffmpeg to get this data

The command below saves the data to a text file.

ffmpeg -f lavfi -i movie=file.mov,blackdetect=d=3.5,metadata=print:file=- -f null - -hide_banner -v 0 | grep lavfi > times.txt 

This will print a set of timecodes of black segments lasting atleast 3.5 seconds.

#2 Add alpha and change alpha of fragments to 0

ffmpeg -i file.mov -vf format=rgba,colorchannelmixer=aa=0:enable='between(t,12.4,16.1)+between(t,55.1,60.0)+between(t,62.9,69.2)' -c:v libvpx-vp9 -crf 10 -b:v 0 out.mkv

In each between expression is the start time and end time of a black fragment, in seconds.

If you want to save the result to file, you'll need to pick a codec which supports alpha, like the one in the above command. If your file already has alpha, skip the format filter.

Gyan
  • 85,394
  • 9
  • 169
  • 201
  • I've updated question with one issue regarding #1 section. Please reply me. – kostya572 Dec 31 '17 at 17:38
  • Can you share the file? Cut a small portion if it's too large: `ffmpeg -i in.mov -c copy -t 25 sample.mov`? – Gyan Dec 31 '17 at 18:06
  • Here is it: https://toolsq.com/files/imagine.mov I only forgot that on 5th second on right top corner appears application logo, maybe it's issue? Logo is not needed, in other scripts I cropped it with - "[1:v]crop=iw:0.50*ih,setpts=PTS-STARTPTS$DIFF/TB, \" – kostya572 Dec 31 '17 at 18:14
  • 1
    Works with ffmpeg: `ffmpeg -i imagine.mov -vf blackdetect=d=3.5 -f null -`. I'm just testing filter logging. You'll have to apply crop to get correct results. – Gyan Dec 31 '17 at 18:31
  • Thanks, it works correct. If not hard, could you tell me how to save ffmpeg output into text file or grep only lines containing word "blackdetect"? Have a Happy New Year! – kostya572 Dec 31 '17 at 18:44