Created working script. Use 3 input files, 2 picture and 1 matte to generate an output video
This commit is contained in:
commit
f653f88680
|
@ -0,0 +1,18 @@
|
|||
# bipack
|
||||
|
||||
Script for simulating traveling mattes with ffmpeg.
|
||||
|
||||
## Requirements
|
||||
|
||||
Uses `ffmpeg` to generate matte files, apply mattes as alpha masks and render final video.
|
||||
|
||||
Installation instructions for ffmpeg here: https://github.com/adaptlearning/adapt_authoring/wiki/Installing-FFmpeg
|
||||
|
||||
## Usage
|
||||
|
||||
|
||||
|
||||
`sh bipack.sh A.mp4 B.mp4 matte.mp4 output.mov`
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
#!/bin/bash
|
||||
|
||||
#IMAGE1
|
||||
A=${1}
|
||||
#IMAGE2
|
||||
B=${2}
|
||||
#MATTE
|
||||
MATTE=${3}
|
||||
#OUTPUT FILE
|
||||
OUTPUT_FILE=${4}
|
||||
|
||||
CONTRAST=100
|
||||
SIZE="1280x720"
|
||||
RATE=30
|
||||
|
||||
time ffmpeg -y -i $A -i $B -i $MATTE \
|
||||
-filter_complex "
|
||||
color=0x000000:size=$SIZE, format=rgb24[bla];
|
||||
[0] format=rgb24 [a];
|
||||
[1] format=rgb24 [b];
|
||||
[2] format=gray, smartblur=1, eq=contrast=$CONTRAST, format=rgb24 [maska];
|
||||
[2] format=gray, smartblur=1, eq=contrast=$CONTRAST, negate, format=rgb24 [maskb];
|
||||
[bla][a][maska] maskedmerge, format=rgb24 [pass1];
|
||||
[pass1][b][maskb] maskedmerge, format=rgb24
|
||||
" \
|
||||
-r $RATE \
|
||||
-c:v prores_ks \
|
||||
-profile:v 3 \
|
||||
$OUTPUT_FILE
|
|
@ -0,0 +1,10 @@
|
|||
# Sources
|
||||
|
||||
[alphaextract, alphamerge tutorial](https://hhsprings.bitbucket.io/docs/programming/examples/ffmpeg/manipulating_video_colors/alphamerge_alphaextract.html)
|
||||
|
||||
[alphaextract, alphamerge tutorial 2](https://hhsprings.bitbucket.io/docs/programming/examples/ffmpeg/manipulating_video_colors/alphamerge_alphaextract_more_.html)
|
||||
|
||||
[maskedmerge tutorial](https://hhsprings.bitbucket.io/docs/programming/examples/ffmpeg/manipulating_video_colors/maskedmerge.html)
|
||||
|
||||
[maskedmerge turorial 2](http://oioiiooixiii.blogspot.com/2016/09/ffmpeg-extract-foreground-moving.html)
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
#!/bin/bash
|
||||
|
||||
#IMAGE1
|
||||
A=${1}
|
||||
#IMAGE2
|
||||
B=${2}
|
||||
#MATTE
|
||||
MATTE=${3}
|
||||
#OUTPUT FILE
|
||||
OUTPUT_FILE=${4}
|
||||
|
||||
|
||||
MATTE1=$(mktemp -u).mov
|
||||
MATTE2=$(mktemp -u).mov
|
||||
PASS1=$(mktemp -u).mov
|
||||
PASS2=$(mktemp -u).mov
|
||||
|
||||
# use rawvideo for intermediary tmp files
|
||||
# -f rawvideo -pixel_format rgb24
|
||||
|
||||
echo "Generating mattes from $MATTE..."
|
||||
|
||||
time ffmpeg -y -i $MATTE -t 10 -vf eq=saturation=0:contrast=100 -c:v prores_ks -profile:v 4 $MATTE1
|
||||
time ffmpeg -y -i $MATTE1 -t 10 -vf negate -c:v prores_ks -profile:v 4 $MATTE2
|
||||
|
||||
echo "Applying matte to $A..."
|
||||
|
||||
time ffmpeg -y -i $A -i $MATTE1 \
|
||||
-t 10 \
|
||||
-filter_complex '[1]split[m][a];[a][1]alphamerge[keyed];[0][keyed]overlay=eof_action=endall' \
|
||||
-c:v prores_ks \
|
||||
-profile:v 4 \
|
||||
$PASS1
|
||||
|
||||
echo "Applying matte to $B..."
|
||||
|
||||
time ffmpeg -y -i $B -i $MATTE2 \
|
||||
-t 10 \
|
||||
-filter_complex '[1]split[m][a];[a][1]alphamerge[keyed];[0][keyed]overlay=eof_action=endall' \
|
||||
-c:v prores_ks \
|
||||
-profile:v 4 \
|
||||
$PASS2
|
||||
|
||||
echo "Cleaning up tmp matte files..."
|
||||
#echo $MATTE1
|
||||
rm $MATTE1
|
||||
rm $MATTE2
|
||||
|
||||
echo "Combining matted layers together into $OUTPUT_FILE..."
|
||||
|
||||
time ffmpeg -y -i $PASS1 -i $PASS2 \
|
||||
-t 10 \
|
||||
-filter_complex "[0][1]blend=all_mode='darken'" \
|
||||
-c:v prores_ks \
|
||||
-profile:v 3 \
|
||||
$OUTPUT_FILE
|
||||
|
||||
echo "Cleaning up temp files..."
|
||||
|
||||
rm $PASS1
|
||||
rm $PASS2
|
|
@ -0,0 +1,11 @@
|
|||
#!/bin/bash
|
||||
|
||||
|
||||
#IMAGE1
|
||||
A=${1}
|
||||
#IMAGE2
|
||||
B=${2}
|
||||
OUTPUT_FILE=${3}
|
||||
|
||||
#this combines video with the mattes applied
|
||||
ffmpeg -y -i $A -i $B -filter_complex "[0][1]blend=all_mode='overlay'" -c:v prores_ks -profile:v 3 $OUTPUT_FILE
|
|
@ -0,0 +1,7 @@
|
|||
#!/bin/bash
|
||||
|
||||
INPUT_FILE=${1}
|
||||
OUTPUT_FILE=${2}
|
||||
|
||||
#maximum contrast on video
|
||||
ffmpeg -y -i $INPUT_FILE -vf eq=saturation=0:contrast=100 $OUTPUT_FILE
|
|
@ -0,0 +1,6 @@
|
|||
#!/bin/bash
|
||||
|
||||
INPUT_FILE=${1}
|
||||
OUTPUT_FILE=${2}
|
||||
|
||||
ffmpeg -y -i $INPUT_FILE -vf negate $OUTPUT_FILE
|
|
@ -0,0 +1,30 @@
|
|||
#!/bin/bash
|
||||
|
||||
#ffmpeg -ss 00:00:18.300 -i music.mp3 -loop 1 -i bg.mp4 -i ac%d.png -i dust.mp4 -filter_complex "[1:0]scale=1600:ih*1200/iw, crop=1600:900[a];[a][2:0] overlay=0:0[b]; [3:0] scale=1600:ih*1600/iw, crop=1600:900,setsar=1[c]; [b][c] blend=all_mode='overlay':all_opacity=0.2" -shortest -y output.mp4
|
||||
#-filter_complex "[0][1]blend=all_mode='overlay'"
|
||||
#ffmpeg -i video -vf "movie='image',alphaextract[a];[in][a]alphamerge" -c:v qtrle output.mov
|
||||
|
||||
#-filter_complex "[1:v]alphaextract[alf];[0:v][alf]alphamerge"
|
||||
#-filter_complex "[0][1]alphamerge,format=yuva420p"
|
||||
|
||||
#-filter_complex '[0]split[m][a];[m][a]alphamerge[keyed];[1][keyed]overlay=eof_action=endall'
|
||||
#The alphamerge filter adds a grayscale version of its 2nd input as the alpha channel to the 1st.
|
||||
#The overlay filter does alpha blending of its inputs.
|
||||
# -> CLOSE!!!!
|
||||
# was extracting the wrong value!!!
|
||||
|
||||
|
||||
#overlay fills in black areas with color, but darkens them
|
||||
#subtract inverts colors
|
||||
#multiply128 does opposite of what I want
|
||||
#darken so close, but it desaturates image layer where white is
|
||||
|
||||
|
||||
#IMAGE
|
||||
A=${1}
|
||||
#MATTE LAYER
|
||||
B=${2}
|
||||
OUTPUT_FILE=${3}
|
||||
|
||||
#swap [0]split with [1]split and [m][a]alphamerge with [a][m]alphamerge
|
||||
ffmpeg -y -i $A -i $B -filter_complex '[1]split[m][a];[a][m]alphamerge[keyed];[0][keyed]overlay=eof_action=endall' $OUTPUT_FILE
|
Loading…
Reference in New Issue