Skip to content

Conversation

825i
Copy link

@825i 825i commented Jun 21, 2025

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

@tatsumoto-ren
Copy link
Member

tatsumoto-ren commented Jun 21, 2025

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?

@825i
Copy link
Author

825i commented Jun 21, 2025

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
Copy link
Author

825i commented Jun 21, 2025

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.

@tatsumoto-ren
Copy link
Member

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 tatsumoto-ren force-pushed the impd-macos-silicon branch 2 times, most recently from 328b5c9 to 3df09d0 Compare June 21, 2025 21:38
@tatsumoto-ren
Copy link
Member

replaced readlink -f calls.

@tatsumoto-ren
Copy link
Member

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

}

825i and others added 2 commits August 17, 2025 16:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants