0

I have this script, which creates a directory for each file, and moves the file into the directory.

#!/bin/bash
for file in *; do
  if [[ -f "$file" ]]; then
    mkdir "${file%.*}"
    mv "$file" "${file%.*}"
  fi
done

Now, I need to 'visit' each file (all MP4) inside its directory, then create a JPG from each frame with ffmpeg leaving JPGs inside that directory.

I create JPGs from MP4's with ..

ffmpeg -i FILENAME.mp4 -y -f image2 -c:v mjpeg %03d.jpg

I don't know how to ensure the extracted JPGs appear inside their associated MP4's directory. If I apply the ffmpeg extraction in the foregoing, JPGs will go in a higher-level directory, I think.

  • 2
    If you already know how to navigate the file system tree, and you know how to extract frames, what part are you still missing? – undercat supports Monica Jun 8 '18 at 16:28
2

If you can't specify the output directory to ffmpeg itself, simply run in within the wanted directory using a subshell, e.g.

( cd $directory && ffmpeg ... )
0

Thanks for the great suggestions.

If you can't specify the output directory to ffmpeg itself, simply run it within the wanted directory using a subshell, e.g. ( cd $directory && ffmpeg ... )

This makes sense. I'm not sure how $directory will be set to the correct directory in question.

I'm also not sure how I'd go back to the previous directory when ffmpeg is done, given that the tree traversal may be too complex for "cd.."

Thank you again for your kind assistance. Eric

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.