impd icon indicating copy to clipboard operation
impd copied to clipboard

push macos silicon compatible impd

Open 825i opened this issue 6 months ago • 6 comments

Description - What does this PR do?

Provides an impd that works on MacOS Apple Silicon.

My performance is 34x higher than using the original impd. The application features all work flawlessly on MacOS Silicon, eg. M4 Pro/Max.

Note that you will need to downoad ffmpeg eg. with homebrew.

Related: #16

825i avatar Jun 21 '25 09:06 825i

It seems this version has to be checked out on top of v0.8, not on the current HEAD.

So as it seems, Macos doesn't support readlink -f, mktemp --tmpdir, and some other commands. Instead of changing impd itself, can this be solved by installing a different version of bash?

tatsumoto-ren avatar Jun 21 '25 09:06 tatsumoto-ren

I think I was just using an older version of impd, or not sure why I changed that. You should be able to just change it to the current. Yeah MacOS doesn't support those. There might be ways around that, didn't care to investigate because it wasn't necessary for my needs.

Note that I made this to work entirely to my own standard which I use with a batch process script because as mentioned I just don't use immersionpod etc. the only thing I care about is being able to rip my entire library as condensed audio. Sorry that it isn't like a rewrite in order to maintain the exact same functionality. I was really just trying to get it to make proper use of Apple's new silicon.

Basically, I run this which runs impd in the same dir. It iterates over my entire library and condenses everything. So the version issue would be due to me using this bash script on top of it.

#!/bin/bash

# Set up trap for graceful exit
trap 'echo -e "\nScript terminated by user"; exit 0' SIGINT SIGTERM

# Check for existing .ogg files
if ls newaudio/*.ogg >/dev/null 2>&1; then
    echo "WARNING: Audio files already exist in newaudio folder!"
    echo "Please remove or move existing .ogg files before running this script."
    echo "Press 'q' to exit..."
    
    while read -r -n1 key; do
        if [[ $key == "q" ]]; then
            echo
            exit 0
        fi
    done
fi

# Initialize counter and exit flag
count=1
exit_flag=0

# Set up background key check
read_input() {
    while read -r -n1 key; do
        if [[ $key == "q" ]]; then
            exit_flag=1
            kill -SIGINT $
            break
        fi
    done
}
read_input & 
input_pid=$!

# Count total files
total=$(ls -1 newvideos/* | wc -l)

echo "Starting audio extraction for $total files..."
echo "-------------------------------------------"

# Process each video file
for video in newvideos/*; do
    # Check exit flag
    if [ $exit_flag -eq 1 ]; then
        break
    fi
    
    # Get first 10 chars of filename
    basename=$(basename "$video")
    prefix=${basename:0:10}
    
    # Create output filename
    outfile="newaudio/${prefix}${count}.ogg"
    
    # Show progress
    echo -e "\nProcessing file $count of $total: $basename -> ${prefix}${count}.ogg"
    
    # Run impd command with local path
    ./impd condense -i "$video" -o "$outfile"
    
    # Check if command was successful
    if [ $? -eq 0 ]; then
        echo "DONE: $basename"
    else
        echo "ERROR processing: $basename"
    fi
    
    # Increment counter
    ((count++))
done

# Clean up background process
kill $input_pid 2>/dev/null

echo "-------------------------------------------"
echo "All files processed successfully!"
echo "Press 'q' to exit..."

# Wait for 'q' key
while read -r -n1 key; do
    if [[ $key == "q" ]]; then
        echo
        break
    fi
done

825i avatar Jun 21 '25 10:06 825i

Sometime in my free time, I could clone impd and go through and rewrite it again to support Apple Silicon whilst trying as best as I can to preserve the original functionality. That said, most of the stuff I changed I think is precisely why it is so much faster. As I doubt it's all just up to the fact that Apple is using an ARM chip.

825i avatar Jun 21 '25 10:06 825i

I think we could try to abstract operations like readlink -f and make them cross-platform. For example, make a special function that calls readlink -f on GNU and something else on macos.

tatsumoto-ren avatar Jun 21 '25 10:06 tatsumoto-ren

replaced readlink -f calls.

tatsumoto-ren avatar Jun 21 '25 21:06 tatsumoto-ren

we can define a function like this to abstract all grep calls

_grep() {
	if [[ "$(uname)" == "Darwin" ]]; then
		if command -v ggrep >/dev/null 2>&1; then
			ggrep "$@"
		else
			echo "ggrep is not installed." >&2
			exit 1
		fi
	else
		grep "$@"
	fi

}

tatsumoto-ren avatar Jun 22 '25 12:06 tatsumoto-ren