0

I am running a bash script to batch transcode videos on a LAMP server using find and ffmpeg

dir="/srv/videos"
for OUTPUT in "$(find $dir -iname *.AVI -o -iname *.MOV)"
do
    ffmpeg -i "$OUTPUT" "${OUTPUT%%.*}.mp4"  -hide_banner
done

ffmpeg returns an error if file has whitespaces

 /srv/videos/file with white spaces.MOV: No such file or directory

For files without white spaces it works fine.
If I print the filenames inside quotes it looks as though it should be working

for OUTPUT in "$(find $dir -iname *.MOV)"; do echo "$OUTPUT";done

returns

/srv/videos/file with white spaces.MOV

What do I need to alter to avoid the error please?

EDIT added "" to ${OUTPUT%%.*}.mp4, I get the same error and corrected extension capitalisation (mov to MOV)

  • You need quotes around `${OUTPUT%%.*}.mp4`. The fact that the error message is coming back with the whole filename is because you quoted the input option - try the call manually with the same filename properly quoted. Maybe `ffmpeg` has a bug? – Paul Hodges Feb 20 '19 at 14:23
  • Separate concern - your `find` is looking for `*.MOV`, but your error message is saying `/srv/videos/file with white spaces.mov` - I assume you're on a windoze system (like me). Does it work manually if you change the case, but still fail if you don't? (I'd be surprised, but I'd certainly check it.) – Paul Hodges Feb 20 '19 at 14:25
  • [Shellcheck](https://www.shellcheck.net/) identifies several problems with the code, and its report contains enough information to lead you to a good solution. – pjh Feb 20 '19 at 18:50
  • 1
    `${OUTPUT%%.*}` may remove too much of the `OUTPUT` string. `${OUTPUT%.*}` will remove only `.avi' or `.mov` (or `.Mov`, ...). – pjh Feb 20 '19 at 18:55

1 Answers1

2

you can try to get rid the for loop and just use the find command , eg smth like below :

find $dir -iname *.AVI -o -iname *.MOV | while read line; do ffmpeg -i "$line" ${line%%.*}.mp4  -hide_banner; done
nullPointer
  • 4,419
  • 1
  • 15
  • 27