1

I have a lot of audio files to convert and I like this to happen automatically when moving a folder with files into another folder, where the magic should happen. It's on a debian system.

Any help would be greatly appreciated.

1 Answers1

3

Ensure you have inotifywait & ffmpeg installed, set the 3 vars at the start to the correct settings, then try

#!/bin/bash

watch_dir="WHEREEVER" convert_from="flac" convert_to="mp3"

inotifywait -qmr -e 'move,close_write'
--include ".${convert_from}" --format '%w%f%0'
--no-newline "$watch_dir" | while IFS= read -r -d '' file do ffmpeg -i "$file" -ab 320k
-map_metadata 0 -id3v2_version 3
"${file/%.${convert_from}/.${convert_to}" > "$watch_dir"/log.txt 2>&1 rm -- "$file" done

terdon
  • 242,166
Bib
  • 2,380
  • That looks spectacular, thank you :) Sorry for my ignorance, but I tried to adjust it to what I want it to do and failed. It's a bit more simplistic than your beautiful script. What I like it do is to go into the found folders (and subfolders) and run a wee script I have myself. Is there any change you can enlighten me? – Robert van Wingen Nov 14 '23 at 11:55
  • 2
    The -r switch means it will look recursively. If you want to call your own script, then just replace the 2 ffmpeg & rm lines. However I would advise against it as I am not sure you understand how it works. – Bib Nov 14 '23 at 12:05
  • @RobertvanWingen: Did you have inotifywait and ffmpeg installed? – Seamus Nov 14 '23 at 13:28
  • I do have those installed but I don't want to use ffmpeg, or mp3. I have my own script that converts, renames and adjust the volume. I just need a script that runs that on folders that are moved to the folder that's monitored. Pretty please :) – Robert van Wingen Nov 14 '23 at 15:15
  • 1
    In that case, just replace the ffmpeg & rm lines with the name of your own script & have that script accept just a single argument & act upon it. You will probably need to adjust the convert_from var to something meaningful. It's just a simnple regex. Oh, and that script came pretty much out of the man page for inotifywait. – Bib Nov 14 '23 at 15:18