I'm trying to automatically convert flac files moved to a folder into mp3 in another folder.
My current line of code is this:
inotifywait -m -r -q -e moved_to --format "'%w%f'" ~/test | xargs -I x flac -cd x - | lame -b 320 - /media/1tb/x.mp3
To explain how this works so far, inotifywait monitors ~/test recursively for files moved there, outputting the path and filename to a pipe. xargs takes that name and creates the proper flac command, replacing x with the filename and decoding the file to another pipe. In the new pipe lame processes the output of flac into mp3 under /media. I want xargs to either reach across the pipe in some way, replacing the x in the lame command or in some way send it to a variable both commands can access or something. I tried messing around with named pipes and that jazz but the fact that there is actual data being piped between the two commands has me in way over my head.
Any suggestions would be appreciated, and if something is unclear, please let me know.