Batch process ffmpeg?
5,950
Solution 1
Python solution
from sh import ffmpeg
from os import listdir
from os.path import split
from sys import argv
[ffmpeg("-i '{0}' -acodec libmp3lame 'Converted\{0}'".format(_file))
for _file in sum([listdir(split(arg)[0]) for arg in argv], [])]
Solution 2
Do this not simply work?
for file in *.avi;do ffmpeg -i "$file" -acodec libmp3lame "Converted\\$file";done
Edit:
There seem to by a backslash problem...
Try this:
for file in *.avi;do ffmpeg -i "$file" -acodec libmp3lame 'Converted\\'"$file";done
or this:
for file in *.avi;do ffmpeg -i "$file" -acodec libmp3lame 'Converted\'"$file";done
Solution 3
In bash
the following will do what you want if your run it in the directory which has the .avi
files:
#!/bin/bash
for file in *.avi; do
ffmpeg -i "$file" -c:a libmp3lame "Converted\\$file";
done;
Related videos on Youtube
Author by
A T
Updated on September 18, 2022Comments
-
A T almost 2 years
Given an AVI encapsulated video with WMA2 audio and MP4 video how do I pass-through the video, convert the audio to MP3; then re-encapsulate the entire file into an AVI?
ffmpeg -i "foo bar.avi" -acodec libmp3lame "Converted\foo bar.avi"
Now how do I do that same command for every
.avi
file in this directory?(need a solution using bash or Windows CLI [
for
?])-
A T over 11 yearsNope; I am not.
-
anishsane over 11 yearsSo this command is successful & you see the output file generated as you want?
-
anishsane over 11 yearsBy the way, if you want to pass through video "AS-IS", then add
-vcodec copy
in the ffmpeg command line. It will save video conversion time + retain the same quality in video.
-
-
Admin over 11 yearsI was first ;-)
-
A T over 11 yearsThanks, but neither worked. I am using Cygwin bash if that makes a difference.
-
Admin over 11 yearsWas there any error message? How did it not work?
-
Admin over 11 years@imp25 Maybe do you need to escape the backslash: ` \\ ` instead of ` \ `
-
A T over 11 yearsNope, now getting same error (the final error I mentioned) on both
//
and `\\` -
Admin over 11 yearsWell, there is a conflict as Windows use ` \ ` for path and shell use ` \ ` for escape. Unfortunely ` \$var ` could be used to print effectively
$var
. So try the editer version, maybe. -
slhck over 11 yearsThe first version should work in Bash.