Skip to content

Instantly share code, notes, and snippets.

@ibaaj
Last active May 10, 2016 05:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ibaaj/6f189ab8744adf7934249ae752ed1cad to your computer and use it in GitHub Desktop.
Save ibaaj/6f189ab8744adf7934249ae752ed1cad to your computer and use it in GitHub Desktop.
fix-scoping.sh
#!/bin/zsh
mkdir -p {frames,final};
ffmpeg -i 03.mp4 -r 25 -qscale:v 2 frames/%05d.jpg ;
framesNumber=$(ls ./frames/*.jpg |wc -l|tr -d ' ');
W=720
H=1280
P_W=160
P_H=128
PSHIFT=5
GAP=15
MODE=0
for startId in {1..${framesNumber}..$((PSHIFT + GAP ))}
do
for id in {${startId}..$((startId + PSHIFT + GAP -1 ))}
do
nb=$(printf %05d ${id});
target=$(printf %05d $((startId + PSHIFT - 1 )));
lim=$((startId + PSHIFT - 1 ));
echo "id: $id - nb: $nb - target: $target - startId: $startId - lim: $lim";
if [[ "$id" -gt "$lim" ]] ; then
cp ./frames/$nb.jpg ./final/$nb.jpg;
continue;
fi
x="convert ./frames/$nb.jpg "
for i in {0..$((H / P_H - 1 ))}
do
for j in {0..$(( W / P_W - 1))}
do
if [[ `expr $MODE % 2` -eq 0 ]]; then
if [ `expr $i % 2` -eq `expr $j % 2` ]; then
x="$x \( ./frames/${target}.jpg -crop ${P_W}x${P_H}+$((j*P_W))+$((i*P_H)) -contrast -contrast -geometry +$((j*P_W))+$((i*P_H)) \) -composite "
fi
else
if [ `expr $i % 2` -ne `expr $j % 2` ]; then
x="$x \( ./frames/${target}.jpg -crop ${P_W}x${P_H}+$((j*P_W))+$((i*P_H)) -contrast -contrast -geometry +$((j*P_W))+$((i*P_H)) \) -composite "
fi
fi
done
done
x="$x final/${nb}.jpg ";
#echo $x;
eval $x;
x=""
done
MODE=$((MODE + 1))
done
# $((framesNumber / 20))
cat ./final/*.jpg | ffmpeg -f image2pipe -r 25 -vcodec mjpeg -i - -vcodec libx264 out.mp4;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment