Last active
March 15, 2024 14:33
-
-
Save bojidar-bg/a73df27ce96d34242a95173a54a022fe to your computer and use it in GitHub Desktop.
Unsilence w/ MLT
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -e | |
if [ "$#" -ne 4 ]; then | |
echo "Usage: $0 source-file silencedetect-args speedup-factor output-file" | |
echo " E.g.: $0 file.mkv n=-35dB:d=0.25 2.5 file.mlt" | |
exit 1; | |
fi | |
TIME_REMAP=$(ffmpeg -i "$1" -vn -af silencedetect="$2" -nostats -f null - 2>&1 | awk 'BEGIN {o=i=0;s=0;m='"$3"'} $4 == "silence_start:" {o+=$5-i;i=$5;printf ":%f=%f;",o,i} $4 == "silence_end:" {o+=($5-i)/m;i=$5;printf ":%f=%f;",o,i}') | |
OUT=$(echo $TIME_REMAP | sed -Ee 's/.+;.//;s/=.+//') | |
#melt "$1" -consumer xml | sed -E 's|out=".+"|out=":'"$OUT"'"|;s|<producer|<chain|;s|</producer>|<link id="link0"><property name="mlt_service">timeremap</property><property name="pitch">1</property><property name="image_mode">nearest</property><property name="time_map">'"$TIME_REMAP"'</property></link></chain>|' > "$4" | |
melt -chain "$1" out="$OUT" -link timeremap pitch=1 image_mode=nearest time_map="$TIME_REMAP" -consumer xml:"$4" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment