1
if [ -d "$1" ]; then
 echo If files are media, screenshots will be made to ~/Screenshots
 for media in $(find "${1%/}/"* -name '*.mkv' -or -name '*.mp4'); do ffmpeg -hide_banner -loglevel panic -ss 00:08:0.0 -i "$media"  -vframes 1 ~/Screenshots/$(basename "$media").screenshot1.png; done
 for media in $(find "${1%/}/"* -name '*.mkv' -or -name '*.mp4'); do ffmpeg -hide_banner -loglevel panic -ss 00:12:0.0 -i "$media"  -vframes 1 ~/Screenshots/$(basename "$media").screenshot2.png; done
 for media in $(find "${1%/}/"* -name '*.mkv' -or -name '*.mp4'); do ffmpeg -hide_banner -loglevel panic -ss 00:20:0.0 -i "$media"  -vframes 1 ~/Screenshots/$(basename "$media").screenshot3.png; done
fi

I'm trying to make 3 screenshots of all mkv/mp4 files to ~/Screenshots. But I keep failing and I can't find the source of the issue? It seems to fail only when there spaces in the name of the files but I quoted everything.

2
  • What is the error you are seeing?
    – Inian
    Apr 5, 2018 at 8:00
  • No error since I suppress everything. But I see that basename does not return a full file path ending with .mkv as it does when there is no space in the filenames. And I tried quoting it too. just create a ~/Screenshots folder and run this code you'll see
    – Freedo
    Apr 5, 2018 at 8:04

1 Answer 1

1

The issue comes from you iterating over the results of find. See here for more info. To prove it, just do the following from your media folder and see how the filenames get mangled:

for media in $(find -name '*.mkv' -or -name '*.mp4'); do echo "$media"; done

You can replace your find with globs, like so:

for media in "$1"/*.mp4; do stuff; done
for media in "$1"/*.mkv; do stuff; done

Or to make it simpler using brace expansion:

for media in "$1"/*.{mp4,mkv}; do stuff; done

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .