gottem
parent
1f1b3bf503
commit
500a115bd1
|
|
@ -0,0 +1,7 @@
|
|||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "src-lib"
|
||||
version = "0.1.0"
|
||||
|
|
@ -0,0 +1,58 @@
|
|||
#! /bin/bash
|
||||
|
||||
py="$(cat <<EOF
|
||||
from sys import stdin; lines = [i.strip() for i in stdin.readlines()];
|
||||
def keyword(line):
|
||||
return "keep" if "keep" in line else "drop"
|
||||
somelines = lines[:1]
|
||||
for i in range(1, len(lines)):
|
||||
if keyword(somelines[-1]) != keyword(lines[i]):
|
||||
somelines.append(lines[i-1])
|
||||
somelines.append(lines[i])
|
||||
somelines = [(keyword(i), i.split("pts_time:")[1].split()[0]) for i in somelines]
|
||||
|
||||
# just the keeps
|
||||
somelines = [i for i in somelines[2:] if i[0] == "keep"]
|
||||
|
||||
# translate to floats
|
||||
drops = []
|
||||
for i in range(0, len(somelines), 2):
|
||||
start = float(somelines[i][1])
|
||||
if len(somelines) > i+1:
|
||||
stop = float(somelines[i+1][1])
|
||||
if stop - start > 1:
|
||||
drops.append((start, stop))
|
||||
#else:
|
||||
# drops.append((start, "inf"))
|
||||
|
||||
# extend around
|
||||
for i in range(len(drops)):
|
||||
drops[i] = (drops[i][0] - 1.0, drops[i][1] + 1.0)
|
||||
|
||||
# combine near
|
||||
for i in range(len(drops)-1, 0, -1):
|
||||
first_start, first_stop = drops[i-1]
|
||||
secnd_start, secnd_stop = drops[i]
|
||||
if secnd_start - first_stop < 5:
|
||||
drops = drops[:i-1] + [(first_start, secnd_stop)] + drops[i+1:]
|
||||
|
||||
# output
|
||||
print("\n".join([
|
||||
f'{i[0]:.2f},{i[1]-i[0]:.2f}' for i in drops
|
||||
]))
|
||||
EOF
|
||||
)"
|
||||
|
||||
d=$(mktemp -d)
|
||||
echo d=$d >&2
|
||||
for span in $(
|
||||
ffmpeg -i $f -vf mpdecimate -loglevel debug -f null - 2>&1 \
|
||||
| grep Parsed_mpdecimate_0 \
|
||||
| grep -E ' (keep|drop) ' \
|
||||
| python3 -c "$py"
|
||||
); do
|
||||
n=$((n+1))
|
||||
ffmpeg -y -ss ${span%,*} -i "$f" -t ${span#*,} "$d/$(printf "%05d" $(ls "$d" | wc -l)).${f##*.}"
|
||||
done
|
||||
ls $d
|
||||
echo rm -rf "$d"
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
#! /bin/bash
|
||||
|
||||
set -euo pipefail
|
||||
f="${1:-"/Users/breel/Movies/bel_1_1.mp4"}"
|
||||
g="$f.2.${f##*.}"
|
||||
|
||||
echo ffmpeg -i "$f" -vf mpdecimate -loglevel debug -f null -
|
||||
echo ffmpeg -y -i "$f" -vf mpdecimate=hi=16:lo=16:frac=1:max=1000 -vsync vfr $g
|
||||
|
||||
# https://stackoverflow.com/questions/62648760/use-debug-log-from-ffmpeg-mpdecimate-to-remove-frames-of-another-input-file
|
||||
|
||||
echo ffmpeg -i "$f" -vf "split=2[full][crop];[crop]mpdecimate=hi=16:lo=16:frac=1:max=1000[crop];[crop][full]overlay" "$g"
|
||||
|
||||
if [ ! -f ./mpdecimate_trim.py ]; then
|
||||
wget -O ./mpdecimate_trim.py https://github.com/KenjiTakahashi/mpdecimate_trim/raw/master/mpdecimate_trim.py
|
||||
fi
|
||||
echo cp "$f" "$g"
|
||||
echo python3 "./mpdecimate_trim.py" "$g"
|
||||
|
||||
# https://superuser.com/questions/984841/ffmpeg-remove-parts-without-motion
|
||||
|
||||
echo ffmpeg -y -i "$f" -vf "select=gt(scene\,0.003),setpts=N/(25*TB)" "$g"
|
||||
|
||||
# https://stackoverflow.com/questions/35675529/using-ffmpeg-how-to-do-a-scene-change-detection-with-timecode
|
||||
|
||||
echo 'ffmpeg -y -i "$f" -filter:v "select='gt(scene,0.50)',showinfo" -f null - 2>&1 | grep showinfo | grep pts_time:[0-9.]* -o | grep [0-9.]* -o'
|
||||
|
||||
# https://stackoverflow.com/questions/40966394/how-to-simply-remove-duplicate-frames-from-a-video-using-ffmpeg
|
||||
|
||||
#ffmpeg -y -i "$f" -vsync cfr "$g".tmp.${f##*.}
|
||||
#ffmpeg -y -i "$g".tmp.${f##*.} -vf "select='if(gt(scene,0.003),st(1,t),lte(t-ld(1),1))',setpts=N/FRAME_RATE/TB" "$g"
|
||||
#rm "$g".tmp.${f##*.}
|
||||
|
||||
# https://stackoverflow.com/questions/37088517/remove-sequentially-duplicate-frames-when-using-ffmpeg
|
||||
|
||||
# ffmpeg -i $f -vf mpdecimate -loglevel debug -f null - 2>&1 | grep Parsed_mpdecimate_0 | grep ' keep '
|
||||
# ffmpeg -i input.mp4 -vf mpdecimate,setpts=N/FRAME_RATE/TB out.mp4
|
||||
# ffmpeg -i "$f" -vf "split=2[full][crop];[crop]mpdecimate=hi=16:lo=16:frac=1:max=1000[crop];[crop][full]overlay" "$g"
|
||||
ffmpeg -y -i "$f" -vf "split=2[full][crop];[crop]mpdecimate,setpts=N/FRAME_RATE/TB[crop];[crop][full]overlay" "$g"
|
||||
Loading…
Reference in New Issue