1

I am completing a project in which I have mountains of .h264 video files that all need to be converted into good quality .avi files. They need to be .avi because I'm using DeepLabCut on them after. I have been able to do this file by file with the code:

ffmpeg -i practicevid_5.h264 -q:v 6 practicevid_5_2.avi

However, I would ideally like to be able to convert an entire folder of these files to save time. Please let me know if you can help out with this.

TheEagle
  • 5,808
  • 3
  • 11
  • 39
oliopti
  • 21
  • 2
  • See [this answer](https://stackoverflow.com/a/33766147/) in How do you convert an entire directory with ffmpeg? – llogan Jan 27 '21 at 17:23

1 Answers1

1

If you are using bash:

cd /the/dir/the/h264/videos/are/in
for input in *.h264; do ffmpeg -i $input -q:v 6 ${input/.h264/_2.avi}; done

In Windows default shell:

for %%input in (*.h264) do ffmpeg %%input -q:v 6 %input:.h264=_2.avi%

Couldn't test the windows sample, as i do not have a windows machine !

TheEagle
  • 5,808
  • 3
  • 11
  • 39
  • Thank you! I will give this a try. I am using Linux! – oliopti Jan 27 '21 at 13:41
  • @oliopti Thats good, because i used the bash version multiple times already ! – TheEagle Jan 27 '21 at 13:49
  • I navigated to the folder, and used the code you suggested ffmpeg -i $input -q:v 6 ${input/.h264/.avi} , typed just like this. However, I am getting the following error -q:v: Protocol not found. Did you mean file: -q:v? – oliopti Jan 27 '21 at 13:52
  • @oliopti first, there was a typo in my post which i fixed, and second, please copy paste the second line of my code when you are in the right folder and see if the error persists. – TheEagle Jan 27 '21 at 13:59
  • @oliopti The cause of the error is that you typed in only the `ffmpeg ...` part and left out the for loop. This caused the `$input` variable to be empty, and ffmpeg got `-q:v` as input file. The `-q` is then interpreted as an internet protocol, and as such a protocol doesn't exist, it gives you that error. The solution of that is to copy paste the second line of my code. – TheEagle Jan 27 '21 at 14:02
  • Thank you so much I was able to do batch conversions using the WinFF GUI. I will also make this edit to the terminal command that you've suggested. Thank you for your attention and help!!! – oliopti Jan 28 '21 at 14:09