Fix for Topaz Video AI's Audio slow down issue using a custom macOS bash or Windows Powershell script

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!

2 Likes

I think you should indicate that this relates to macos or linux not windows.

Done. Also here’s how you can create a Windows PowerShell script to achieve the same effect as the Bash script:

  1. Open a text editor and paste the following PowerShell script:
param (
    [Parameter(Mandatory=$true)]
    [string]$inputVideo,
    [Parameter(Mandatory=$true)]
    [ValidateSet("4x", "8x")]
    [string]$slowdownFactor
)

# Get video duration in seconds
$duration = & ffmpeg -i $inputVideo 2>&1 | Select-String "Duration" | ForEach-Object {
    $time = $_.ToString().Split(",")[0].Split(":")[1].Trim()
    $h, $m, $s = $time -split ":"
    $totalSeconds = ($h * 3600) + ($m * 60) + [math]::Round($s)
    return $totalSeconds
}

# Determine the audio filter based on the slowdown factor
if ($slowdownFactor -eq "4x") {
    $audioFilter = "atempo=0.5,atempo=0.5,atrim=0:$duration"
} elseif ($slowdownFactor -eq "8x") {
    $audioFilter = "atempo=0.5,atempo=0.5,atempo=0.5,atrim=0:$duration"
}

# Process the video
& ffmpeg -i $inputVideo -c:v copy -filter:a $audioFilter -shortest "$($inputVideo.TrimEnd('.mp4'))_slowed_audio.mp4"

Write-Output "Processing complete! Output saved to $($inputVideo.TrimEnd('.mp4'))_slowed_audio.mp4"
  1. Save the file with a .ps1 extension, for example, slowdown_audio.ps1.
  2. Before running the script, ensure you’ve set the execution policy in PowerShell to allow scripts. Open PowerShell as an administrator and run:
Set-ExecutionPolicy RemoteSigned
  1. Now, you can run the script from the PowerShell:
.\slowdown_audio.ps1 -inputVideo "path_to_your_video.mp4" -slowdownFactor "4x"

Or for 8x slowdown:

.\slowdown_audio.ps1 -inputVideo "path_to_your_video.mp4" -slowdownFactor "8x"

Replace path_to_your_video.mp4 with the path to your actual video file.

Note: This script assumes that ffmpeg is available in your system’s PATH. If it’s not, you’ll need to provide the full path to the ffmpeg executable or add it to the system’s PATH.