ffmpeg batch scripts

DataMine
by DataMine · 5 posts
1 year ago in Batch
Posted 1 year ago · Author
This is a collection of batch scripts I put together for doing audio/video work. I'll give brief instructions on how to use them but I'm going to assume you already familiar with batch scripts. If you're not, here's a YouTube tutorial: viewtopic.php?p=165068#p165068

Convert MP4 to WebM
This script allows you to convert an MP4 file to WebM by dragging n' dropping.

Spoiler: mp4towebm

Instructions
  1. Create a new text file.
  2. Copy and paste the code below into it.
  3. Replace
    ffmpeg\ffmpeg
    with the path to your fmmpeg executable.
  4. Save it as batch script (.bat file) in the same folder as the ffmpeg folder.
  5. Finally drag n' drop an mp4 file onto it.
Code
@echo on
"%~dp0ffmpeg\ffmpeg" -i %1 -c:v libvpx-vp9 -crf 23 -b:v 0 "%~n1".webm
pause


Convert FLV to MP4
This script allows you to convert an FLV file to MP4 by dragging n' dropping.

Spoiler: flvtomp4

Instructions
  1. Create a new text file.
  2. Copy and paste the code below into it.
  3. Replace
    ffmpeg-5.1.2-essentials_build\bin\ffmpeg
    with the path to your fmmpeg executable.
  4. Save it as batch script (.bat file) in the same folder as the ffmpeg folder.
  5. Finally drag n' drop an mp4 file onto it.

Note: This script requires ffmpeg with H.264 video encoding support via libx264. You can download a pre-compiled copy of ffmpeg with this support here: https://www.gyan.dev/ffmpeg/builds/

Code
@echo on
"%~dp0ffmpeg-5.1.2-essentials_build\bin\ffmpeg" -i %1 -c:v libx264 -crf 19 -strict experimental "%~n1".mp4
pause


Convert M4A to MP3
This script allows you to convert an M4A file to MP3 by dragging n' dropping.

Spoiler: m4atomp3

Instructions
  1. Create a new text file.
  2. Copy and paste the code below into it.
  3. Replace
    ffmpeg\ffmpeg
    with the path to your fmmpeg executable.
  4. Save it as batch script (.bat file) in the same folder as the ffmpeg folder.
  5. Finally drag n' drop an mp4 file onto it.

Code
@echo on
"%~dp0ffmpeg\ffmpeg" -i %1 -c:v copy -c:a libmp3lame -q:a 4 "%~n1".mp3
pause


If you want the command prompt window to automatically close after the any of these scripts are completed, remove
pause
from the end of the scripts.



For those who are are interested in a more detailed explanation on how these scripts work,
%~dp0
is the ffmpeg executable path instead of the dropped file path. So if you have ffmpeg installed in
c:\ffmpeg
%~dp0\ffmpeg\ffmpeg
will translate to
c:\ffmpeg\ffmpeg.exe
. If you don't use this, it will attempt to look for ffmpeg in the same folder as the file you want to convert, unless you hard code the full path to your ffmpeg executable.

%1
is the full path of the dropped file. So if you drag and drop a file from your desktop,
%1
will translate to
C:\Users\[your username]\Desktop\[your file].[ext]
. This allows you to drag and drop a file from anywhere without having to modify the script for each new file, making the script reusable.

%~n1
is the full path to the dropped file without an extension.
C:\Users\[your username]\Desktop\[your file].[ext]
becomes
C:\Users\[your username]\Desktop\[your file]
. This is necessary so your converted file is named correctly. Otherwise you'd have to manually edit the script for each file you wanted to convert.
Posted 1 year ago
@DataMine


Thank you sir! This right here is quite amazing and I'll be finding some good uses for it soon. It's simple without any extra fluff or misc features that aren't needed. :D
Posted 1 year ago · Author
@Xacto


Yay at least 1 person found this thread useful, loool.

ffmpeg is amazingly capable, unfortunately most people these days seem to use websites instead. A simple script and an offline application are much better. I actually just used one of these this morning, lol.
Posted 1 year ago
DataMine wrote:
@XactoYay at least 1 person found this thread useful, loool.ffmpeg is amazingly capable, unfortunately most people these days seem to use websites instead. A simple script and an offline application are much better. I actually just used one of these this morning, lol.

@DataMine


Websites are inconvenient to use, however, it's also true that there are many GUI tools that simplify the various steps, or rather, that are capable of doing the same things via a GUI while providing support for even more audio/video formats, thus allowing different conversions to be performed.

For example, I usually use XMedia Recode (on Windows) or Handbrake (on Linux) to do the same things... and many more.

Edit: obviously both can use ffmpeg as well as other types of encoders to convert files.
Posted 1 year ago · Author
@Amarok78


My issue with websites is they require a network connection, are often slow, typically require payment, have lots of restrictions and worst of all, require giving them a copy of the file. Makes no sense to go through all that to perform a small task like converting a file.

When it comes to GUI vs CLI, For me, it depends on the task. If it's something simple like converting a file and the options don't change frequently, a cli automated by a script is preferred. For heavy tasks with lots of settings to customize or input to select, a GUI is typically better.

Speaking of Linux, I grew quite fond of being able to run simple tasks in the terminal globally. I've sort of replicated the system on my Windows machine. I've got a folder containing batch scripts that I assign aliases to using the PATH environment variable. This allows me to run them in the terminal just by typing the alias from anywhere in the filesystem.

For example I wrote a small file renamer utility. It takes a directory as input so I can use the Windows Explorer trick to open a command prompt in any directory, type in
renamer -r
and it'll use that directory as the argument and rename everything that matches the utilities settings. So much quicker and easier than running a program and filling out the settings.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Sign in

Already have an account? Sign in here

SIGN IN NOW

Create an account

Sign up for a new account in our community. It's easy!

REGISTER A NEW ACCOUNT
Select a forum Protection     Help & Support     Introductions     Mafia News     IMVU News General Discussion     IMVU Lounge        IMVU Series / Roleplaying        Social Games     Mafia Market     Mafia Tools        Premium IMVU Tools        Off Topic Tools     Off Topic     Contests Creator Corner     Graphics Design        Photoshop        GIMP     Basic Creator Help     Catalog And Product Showcase     3D Meshing        3Ds Max        Sketchup        Blender Gangsters with Connections     White Hat Activities        Google Hacking        Trackers Programming Corner     Coding        Python        .Net (C#, VB, etc)        Flash        JAVA        Autoit        Batch        HTML & CSS        Javascript        PHP        Other        IMVU Homepage Codes           General           About me Panel           Messages Panel           Special Someone Panel           Visitors Panel           New Products Panel           Rankings Panel           Wishlist Panel           My Badges Panel           Outfits Panel           Url Panel           Groups Panel           Slideshow Panel           My Room Panel           Sandbox panel           Layouts     Help & Requests Free Credits     Approved Methods     Submit Methods Free Money     Approved Methods     Submit Methods Adult Corner     Get Mafia AP Here     AP Lounge        AP Social Games        Casual Dating Tips     IMVU Slave Market & Escorts