From a7cd5f2a4b69f69d8af0000263b1473fa1a3cd2b Mon Sep 17 00:00:00 2001 From: James Bunton Date: Sun, 12 Jul 2015 01:09:31 +1000 Subject: [PATCH] fix-pal-speedup - no more streaming, it causes problems --- fix-pal-speedup | 55 ++++++++++++++++++++++++++++--------------------- 1 file changed, 32 insertions(+), 23 deletions(-) diff --git a/fix-pal-speedup b/fix-pal-speedup index 39c4ba4..67397c0 100755 --- a/fix-pal-speedup +++ b/fix-pal-speedup @@ -15,52 +15,59 @@ FORCEFPS="24" SLOWDOWN="0.96" function mux_replace_audio { - infile="$1" - audiofile="$2" - outfile="$3" + local infile="$1" + local audiofile="$2" + local outfile="$3" - trackid="$(mkvmerge -i "$infile" | grep video | sed 's/^Track ID \(.\):.*$/\1/')" + local trackid="$(mkvmerge -i "$infile" | grep 'Track ID.*video' | sed 's/^Track ID \(.\):.*$/\1/')" mkvmerge -o "${outfile}" --default-duration "${trackid}:${FORCEFPS}fps" --no-audio "$infile" "$audiofile" } function extract_audio { - infile="$1" + local infile="$1" + local outfile="$2" - exec mpv \ + mpv \ --no-terminal \ --no-video \ - --ao pcm:waveheader:file=/dev/stdout \ + --ao "pcm:waveheader:file=${outfile}" \ "$infile" } function slow_audio { - exec sox \ + local infile="$1" + local outfile="$2" + + sox \ --temp "$tmpdir" \ - - \ - -t wav - \ + "$infile" \ + -t wav \ + "$outfile" \ speed "${SLOWDOWN}" \ gain -n \ channels 2 } function encode_audio { - outfile="$1" - exec lame \ + local infile="$1" + local outfile="$2" + + lame \ --preset standard \ - - \ - "${outfile}" + "${infile}" "${outfile}" } function convert_file { - infile="$1" - outfile="$2" - tmpdir="$(mktemp -d "${TMPDIR:-/var/tmp}/pal-XXXXXXXX")" - audiofile="${tmpdir}/audio.mp3" - - extract_audio "${infile}" | slow_audio | encode_audio "${audiofile}" - mux_replace_audio "${infile}" "${audiofile}" "${outfile}" - - rm -rf "$tmpdir" + local infile="$1" + local outfile="$2" + local audio1="${tmpdir}/audio1.wav" + local audio2="${tmpdir}/audio2.wav" + local audio3="${tmpdir}/audio3.mp3" + + extract_audio "${infile}" "${audio1}" + slow_audio "${audio1}" "${audio2}" + encode_audio "${audio2}" "${audio3}" + mux_replace_audio "${infile}" "${audio3}" "${outfile}" } @@ -75,6 +82,8 @@ for infile in "$@"; do continue fi + tmpdir="$(mktemp -d "${TMPDIR:-/var/tmp}/pal-XXXXXXXX")" convert_file "$infile" "$outfile" + rm -rf "$tmpdir" done -- 2.39.2