4

I'm trying to batch encode 45 video files, and copy the encoded files into an existing subfolder called "encode"

I've used the suggested code from this question (https://stackoverflow.com/questions/5784661/how-do-you-convert-an-entire-directory-with-ffmpeg) But, I don't know how to capture the original file names (with spaces and punctuation) and use that as the new file name in the new directory.

Here's the code I'm using so far:

for i in *.mp4; do name=`echo "${i%.*}"`; echo $name; ffmpeg -i “$i” -vf "scale='if(gt(a*sar,16/9),640,-1)':'if(gt(a*sar,16/9),-1,360)',pad=640:360:(ow-iw)/2:(oh-ih)/2,setsar=1" -vcodec libx264 -b:v 1600k -bufsize:v 1600k -r 30000/1001 “encoded/$name.mp4” done It's giving me an "invalid argument" error message when I run it - probably because I haven't specified the names correctly(?)

The ffmpeg code that I'm using does work (I can encode individual file) but I haven't figured out how to batch encode the entire directory.

If anyone can let me know what I'm doing wrong, I would love to know!

Thank you!

4

The accepted answer in the question you're referring to uses additional unnecessary processes, legacy code, and doesn't prevent globbing or word splitting.

See the second answer which is shorter, simpler, and more efficient:

for f in *.mp4; do ffmpeg -i "$f" <additional options> "encoded/${f%.*}.mp4"; done

Secondly, don't use fancy quotes which will cause errors, so instead of “$varible” use "$variable".

  • Returns f was unexpected at this time. I feel like I'm missing something. – user24601 Jan 21 '17 at 17:20
  • I had to use for %f in (*.mp4); do ffmepg -i %f <additional options> %f.mp3. I got the batch to run correctly, but the extension is now duplicated. My files look like file.mp4.mp3. I'll figure it out soon, I'm sure. – user24601 Jan 21 '17 at 18:34
  • Acutally, I couldn't figure it out. Perhaps you can help: video.stackexchange.com/questions/20474/… – user24601 Jan 21 '17 at 20:15
  • @fredsbend Are you using Windows? My example is Bash shell (for Linux users). – llogan Jan 23 '17 at 6:15
  • @LordNeckbeard Yes, I'm on Windows 10. – user24601 Jan 23 '17 at 7:57
2

I think you can achieve what you need with my ffmpeg Windows front-end, where you can easily select output destination folder.

https://sourceforge.net/projects/ffmpeg-batch

It adds to ffmpeg a window fashion interface, progress bars and time remaining info, features I always missed when using ffmpeg.

  • Please make sure to clearly indicate if an answer refers to a software or product that you are affiliated with. I have altered the answer to include the needed information. – AJ Henderson Apr 25 '18 at 18:58
  • Yes indeed, thanks for the clarification, just trying to make people's life easier. – Eibel Apr 11 at 11:05
0

I'm trying to batch encode 45 video files, and copy the encoded files into an existing subfolder called "encode"

Try this: https://github.com/alessandro893/ffmpeg-batch-remux

  • Could you provide a little more detail on how to use the tool you linked to? Most people come here looking for more in depth answer than just a link. – Michael Liebman Aug 6 '18 at 23:48
0

To convert a file within the same format without the extension saved into file name in batch mode just add ~n to the final input, like so:

for %f in (*.mkv) do ffmpeg -i %f <additional options> %~nf.mp4

If one needs to reformat the codec and wishes to keep the same title and save in the same extension it must be saved into another folder. Start the ffmpeg command from the location of the original files. Navigate to that different folder and copy the entire location from the address bar and paste it exactly as is at the beginning of the output name. For this there must be " " around the whole output address. Replace everything within () with your address, and then remove the ().

for %a in (*.mp4) do ffmpeg -i "%a" <additional options> "(F:\VIDEO\New)\%~na.mp4"
New contributor
C.J. is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

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.