Solution using ffmpeg's concat protocol
You must first find the files you want to merge (newer than one day)
find path/to/files -name '*.mp3' -mtime -1
And merge them as described in another question. Finally the string used for concatination must be modified to be valid for rm (quotes instead of pipes etc).
The final script is then:
#!/bin/bash
concat=$(echo -n "concat:" && find path/to/files -name '*.mp3' -mtime -1 -exec echo -n "{}|" \;)
ffmpeg -i "${concat%|}" -acodec copy output.mp3
IFS=$'\n'
for i in $(echo $concat | sed -e 's/^concat://' -e 's/|$//' -e 's/|/\n/g');
do rm -i $i
done
${concat%|}strips the final pipe in the variable and the sed expression creates a list of files (one per line) to be deleted by rm.
Sortable solution (needs ffmpeg 1.1 or newer)
With more recent versions of ffmpeg the files that shall be concatenated can be read from a file. This allows easy sorting of the snippets.
#!/bin/bash
IFS=$'\n'
concatlist=$(find /path/to/files -name '*.mp3' -mtime -1 -printf "file '%p'\n" | sort)
ffmpeg -f concat -i <(echo "$concatlist") -c copy output.mp3
for i in $(echo "$concatlist" | sed -e "s/^file '//" -e "s/'$//"); do
rm -i "$i"
done
This solution fails if one of the filenames contains a single quote ('). If anyone knows how to correct this, please change it.
path/to/fileswith/home/jhvisser/Music/Streamripper_ripshowever I get the following errors: http://pastebin.com/95TtHkXW – ComputerLocus Oct 08 '13 at 17:34echo $concatprint after executing the first line? – Tim Oct 08 '13 at 18:27concat:– ComputerLocus Oct 08 '13 at 19:52.mp3is case sensitive (use-inamefor case insensitive). Play around with `find path/to/files -name '.mp3' -mtime -1` until you match the files you want. – Tim Oct 08 '13 at 20:19rm -i "$i"work? The files are not in a particular order. I am right now writing another version, which is sortable viasort, but it will probably not work with your oldffmpegversion – Tim Oct 08 '13 at 20:49rm -i "$i"is not working. Not being deleted. – ComputerLocus Oct 09 '13 at 01:05