Convert all .ape files to .flac in different subfolders
Solution 1
The command that you need is:
find /path/to/MainDir/ -type f -name "*.ape" -execdir sh -c ' avconv -i "$1" "${1%.ape}.flac" ' _ {} \;
This will find each file that has .ape
suffix and then convert it with the same filename with .flac
suffix to the same location as original file is located.
{}
is the path of current found file.
See the test from here
Solution 2
The (python) script below should do the job. Copy it into an empty file, save it as convert.py
, set the directory to the files in the head section of the script (convert_dir =
) and run it by the command:
python3 /path/to/convert.py
The script
#!/usr/bin/env python3
convert_dir = "/path/to/folder/tobeconverted"
import os
import subprocess
for root, dirs, files in os.walk(convert_dir):
for name in files:
if name.endswith(".ape"):
# filepath+name
file = root+"/"+name
# to use in other (convert) commands: replace the "avconv -i" by your command, and;
# replace (".ape", ".flac") by the input / output extensions of your conversion
command = "avconv -i"+" "+file+" "+file.replace(".ape", ".flac")
subprocess.Popen(["/bin/bash", "-c", command])
else:
pass
Solution 3
Now that ffmpeg is preferred over avconv again, and there are cheap many core computers ($60 for an 8 core XU4) I fount the following to be most effective;
#!/bin/bash
#
# ape2flac.sh
#
function f2m(){
FILE=$(echo "$1" | perl -p -e 's/.ape$//g');
if [ ! -f "$FILE".flac ] ; then
ffmpeg -v quiet -i "$FILE.ape" "$FILE.flac"
fi
}
export -f f2m
find "$FOLDER" -name '*.ape' | xargs -I {} -P $(nproc) bash -c 'f2m "$@"' _ "{}"
Related videos on Youtube
tigerjack
Updated on September 18, 2022Comments
-
tigerjack almost 2 years
I was trying to convert some .ape files to .flac files using
avconv
on command line; obviously,avconv
is not the main point here; its syntax is pretty straightforward,avconv -i inputApeFile.ape outputFlacFile.flac
.The point is that the files are nested in more subfolders; i.e., I have the Artist folder, then various CD subfolders, each of one contain different .ape files. How can I convert all the files and then save them in the same folder of the original file but with the .flac extension?
If it is possible, I'd like to use only shell command on a single line without using scripts. I think it should be something like that
avconv -i 'ls -R | grep ape' '???'
but I'm stuck with the second part (maybe using
sed
??!?) -
tigerjack over 9 yearsthanks for your reply and your time Jacob. However, if it is possible, I'd like to use only shell command on a single line without using script (sorry for that, I had to specifiy this before)
-
Jacob Vlijm over 9 years@tigerjack89 Well, maybe someone els could use it in similar situations; the syntax <command> <inputfile> <outputfile> is pretty common.
-
evilsoup over 9 yearsThis won't work;
avconv
can't take input files from STDIN like that. -
tigerjack over 9 yearswhat about the output folder?
-
Edward Torvalds over 9 years@evilsoup I have updated the answer, xargs can solve the issue. please try this.