0

I have a folder with multiple subfolders with mkv files

main directory

then

Directory A Dir B Dir C Dir D Dir E Dir F Dir G

I need a script that will search all directories for .mkv and convert to .mp4

i currently have this script

for file in *.mkv; do ffmpeg -i "$file" -c:a aac -q:a 2 -c:v copy "${file%.m kv}.mp4"; done

but it only works if the .sh file is placed in each dir

genpfault
  • 47,669
  • 9
  • 68
  • 119
burro me
  • 25
  • 5
  • You can use `find`. Here is a [simplistic example](https://stackoverflow.com/a/41105794/1109017). – llogan Sep 23 '19 at 18:03
  • So it would be find - name for file in *.mkv; do ffmpeg -i "$file" -c:a aac -q:a 2 -c:v copy "${file%.m kv}.mp4"; done – burro me Sep 23 '19 at 18:42
  • thanks but when i run that terminal doesnt even open – burro me Sep 25 '19 at 14:33
  • I need to run it as a .sh file executable – burro me Sep 25 '19 at 17:27
  • Here's the output wheelzi@wheelzi:~$ cd /media/2be833ff-cb77-407c-974e-d9bd0df8d6b2/dl/sabnzbd/ wheelzi@wheelzi:/media/2be833ff-cb77-407c-974e-d9bd0df8d6b2/dl/sabnzbd$ find *.mkv -exec ffmpeg -i {} -c:a aac -q:a 2 -c:v copy {}.mp4 \; find: ‘*.mkv’: No such file or directory wheelzi@wheelzi:/media/2be833ff-cb77-407c-974e-d9bd0df8d6b2/dl/sabnzbd$ – burro me Sep 25 '19 at 18:07
  • wheelzi@wheelzi:/media/2be833ff-cb77-407c-974e-d9bd0df8d6b2/dl/sabnzbd/complete$ find *.mkv -exec ffmpeg -i {} -c:a aac -q:a 2 -c:v copy {}.mp4 \; find: ‘*.mkv’: No such file or directory wheelzi@wheelzi:/media/2be833ff-cb77-407c-974e-d9bd0df8d6b2/dl/sabnzbd/complete$ – burro me Sep 25 '19 at 18:22
  • wheelzi@wheelzi:/media/2be833ff-cb77-407c-974e-d9bd0df8d6b2/dl/sabnzbd/complete$ find *.mkv -exec ffmpeg -i {} -c:a aac -q:a 2 -c:v copy {}.mp4 \; find: ‘*.mkv’: No such file or directory wheelzi@wheelzi:/media/2be833ff-cb77-407c-974e-d9bd0df8d6b2/dl/sabnzbd/complete$ when I add the output here the *. Is changed to. – burro me Sep 25 '19 at 18:22
  • No but the are in the directories in there – burro me Sep 25 '19 at 18:31

1 Answers1

0

Use find:

find . -type f -name "*.mkv" -exec ffmpeg -y -i {} -c:a aac -q:a 2 -c:v copy {}.mp4 \;
llogan
  • 87,794
  • 21
  • 166
  • 190