0

I have this loop to find mp4 files that I want to convert to webm.

find "./$1" -type f -iname "*.mp4" | while IFS== read -r f; do
        echo "found: $f"
        fn=$( echo "$f" | rev | cut -d '.' -f 2- | rev )
        fWebm="${fn}.webm"
        #ffmpeg -i "$f" -c:v libvpx-vp9 -crf 30 -b:v 0 -b:a 128k -c:a libopus "$fWebm"
        if [ -f "$fWebm" ]; then
                echo "removing $f"
                #rm "$f"
        else
                echo "not removing $f"
        fi
        echo "Done."
done

If I uncomment the ffmpeg line then it converts the first video then quits. Why? How can I get it to continue with the rest of the files?

6
  • My guess in such situations is always that find | while read breaks in surprising ways. That's why we usually strongly discourage doing that, and recommend using find … -exec … or, even better here, simply not using find but globbing; you can replace your whole find … ; do line with a simple shopt -s nullglob globstar nocaseglob; for f in **/*.mp4 ; do. Commented May 15, 2024 at 9:43
  • ah, and by the way, your fn= is creative, but a) should be in quotes "$(…)" (!) and b) setting shopt -s nocasematch at the beginning and doing fWebm="${f/%.mp4/.webm} is probably a bit easier on the mind of the reader. Commented May 15, 2024 at 9:49
  • Also mywiki.wooledge.org/BashFAQ/089 . This is particular to ffmpeg. Commented May 15, 2024 at 10:32
  • 1
    @Marcus, fn=$(foo) is exactly the same as fn="$(foo)", since a (scalar) assignment isn't subject to splitting and globbing anyway. (Barring bugs which e.g. Bash has had in some corner cases.) Commented May 15, 2024 at 10:33
  • find | while read f is fine as long as the filenames are nice. find | while IFS= read -r f is better (it should pretty much leave newlines in filenames as the only issue). But setting IFS== seems odd, it would split on equal signs and that doesn't seem too useful here. Commented May 15, 2024 at 10:35

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.