1
I am trying to find all *.flac files in a directory tree, encode them with ffmpeg, and then output them to a corresponding tree in another location. I am using Cygwin on Windows 10. This is what I have so far:
$ find /cygdrive/d/Users/Drew/Music/beets/Music -type f -name '*\.flac' > files
$ while read line; do ffmpeg -i "$line" -f null "$(echo $line | sed 's/\.flac/\.mp3/' | sed 's/Music\/beets/Desktop/')"; done < files
The first command has generated a good list of files (that I can tell), but the while loop gives ffmpeg errors every other file due to the leading '/' being trimmed:
cygdrive/d/Users/Drew/Music/beets/Music/$uicideboy$/Eternal Grey/06 Uglier.flac: No such file or directory
and occasionally another error seemingly randomly when 2 characters are trimmed:
Parse error, at least 3 arguments were expected, only 1 given in string 'ygdrive/d/Users/Drew/Music/beets/Music/$uicideboy$/Eternal Grey/08 Elysian Fields.flac'
Is there some newline problem going on here that I can not detect? Is it something else? Why is this happening?
Does it work with
– slhck – 2019-02-19T08:53:54.787read -r
? http://mywiki.wooledge.org/BashFAQ/0011
Cross-site duplicate of stackoverflow: When reading a file line by line, I only get to execute ffmpeg on the first line. See also BashFAQ #89: I'm reading a file line by line and running ssh or ffmpeg, only the first line gets processed!
– Gordon Davisson – 2019-02-20T01:11:48.7972
Does this answer your question? 'while read' loop through lines in text file losing characters in Bash script. is FFmpeg line to blame?
– Kamil Maciorowski – 2019-12-31T23:39:11.577