hey @vaporeon_ is there a good way to parallelize the following bash script I'm using to convert FLACs to MP3s?
#!/usr/bin/env bash
find "./${1}" | while read -r file; do
case $(file -b "${file}") in
'FLAC '*)
echo "${file}"
ffmpeg -nostdin -i "${file}" -ab 320k -map_metadata 0 -id3v2_version 3 "${file%flac}mp3" -v 16
;;
*)
;;
esac
done
@wallhackio Does FFmpeg not already use all available CPU cores for converting a file in parallel? I thought FFmpeg did that, at least for videos.
(If not, I can type up something, but first want to confirm that it isn't already being parallel inside FFMPEG)
@vaporeon_ a little searching tells me that audio encoding is typically handled with a single thread
@wallhackio Hm, assuming the audio files are mostly of similar length, does something like this work? I didn't test it, but you get the idea, right?
case $(file -b "${file}") in
'FLAC '*)
echo "${file}"
ffmpeg -nostdin -i "${file}" -ab 320k -map_metadata 0 -id3v2_version 3 "${file%flac}mp3" -v 16 &
i=$(($i+1))
if [ $i -eq `nproc` ] ; then
wait # Wait for all `nproc` jobs to finish
i=0
fi
;;
@wallhackio Initialize i to 0 before starting that entire pipeline, of course
@vaporeon_ for some reason this will quit before finishing all of the files...
@vaporeon_ @wallhackio this was purrobably the issue, windows was purrobably reaping all the child purrocesses immediately so it could kill the VM as soon as bash was done
@aescling @vaporeon_ this actually didn't work which I find infinitely baffling
@vaporeon_ @wallhackio caleb asked me in purrivate if i had any idea what was happening, and funnily enough you had already identified what i ended up believing the purroblem to be, aside from not realizing he was using WSL