Hello everyone,
I’ve recently been working with Topaz Video AI and noticed an odd behavior. When attempting to slow down videos using the software, I found that while the video itself slows down as intended, the audio remains at its original 1x speed. This results in audio and video being out of sync, which, as you can imagine, is far from ideal.
I’ve created a bash script as a workaround to address this issue. This script slows down the audio of a video to match a 4x or 8x slowdown while retaining the video’s original duration.
Prerequisites:
You must have ffmpeg
installed on your system for this script to work. If you haven’t already installed it, you can find the installation instructions for various platforms on the official site.
The Script:
#!/bin/bash
# Check if correct number of inputs were provided
if [ "$#" -ne 2 ]; then
echo "Usage: $0 <input_video_file> <slowdown_factor>"
echo "<slowdown_factor> can be either 4x or 8x."
exit 1
fi
# Get the video duration in seconds
duration=$(ffmpeg -i "$1" 2>&1 | grep "Duration" | awk '{print $2}' | awk -F: '{if ($3 ~ /\./) split($3,s,"."); else s[1]=$3; print $1*3600 + $2*60 + s[1]}')
# Determine which audio filter to use based on the slowdown factor
if [ "$2" == "4x" ]; then
audio_filter="atempo=0.5,atempo=0.5,atrim=0:$duration"
elif [ "$2" == "8x" ]; then
audio_filter="atempo=0.5,atempo=0.5,atempo=0.5,atrim=0:$duration"
else
echo "Invalid slowdown factor. Please choose either 4x or 8x."
exit 1
fi
# Apply slowdown to audio and trim to match the original video's duration
ffmpeg -i "$1" -c:v copy -filter:a "$audio_filter" -shortest "${1%.*}_slowed_audio.mp4"
echo "Processing complete! Output saved to ${1%.*}_slowed_audio.mp4"
Usage:
To use the script, save it to a file (e.g., slowdown_audio.sh
), grant it execute permissions with
chmod +x slowdown_audio.sh
Then, run it like this:
For 4x slowdown:
./slowdown_audio.sh input_video_file.mp4 4x
For 8x slowdown:
./slowdown_audio.sh input_video_file.mp4 8x
Replace input_video_file.mp4
with the path to your actual video file. The script will create a new video file with slowed audio and the same video duration.
I hope this helps anyone facing the same issue with Topaz Video AI. If there are updates or fixes to the software in the future that address this, I hope someone will let us know here in this thread. In the meantime, this script should be a good workaround.
Happy editing!