Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Convert video files to MP4 through FFMPEG

This is my personal list of functions that I wrote for converting mov files to mp4!

Command Flags

Flag Options Description
-codec:a libfaac, libfdk_aac, libvorbis Audio Codec
-quality best, good, realtime Video Quality
-b:a 128k, 192k, 256k, 320k Audio Bitrate
-codec:v mpeg4, libx264, libvpx-vp9 Video Codec
-b:v 1000, 2500, 5000, 8000 Video Bitrate
-vf scale -1:X Resize Video (X is height)
-qmin 10 -qmax 42 ??? https://gist.github.com/dvlden/b9d923cb31775f92fa54eb8c39ccd5a9#gistcomment-2972745
MP4 - 1080p

ffmpeg -i input.mov -preset slow -codec:a libfdk_aac -b:a 128k -codec:v libx264 -pix_fmt yuv420p -b:v 4500k -minrate 4500k -maxrate 9000k -bufsize 9000k -vf scale=-1:1080 output.mp4

MP4 - 720p

ffmpeg -i input.mov -preset slow -codec:a libfdk_aac -b:a 128k -codec:v libx264 -pix_fmt yuv420p -b:v 2500k -minrate 1500k -maxrate 4000k -bufsize 5000k -vf scale=-1:720 output.mp4

MP4 - 480p

ffmpeg -i input.mov -preset slow -codec:a libfdk_aac -b:a 128k -codec:v libx264 -pix_fmt yuv420p -b:v 1000k -minrate 500k -maxrate 2000k -bufsize 2000k -vf scale=854:480 output.mp4

MP4 - 360p

ffmpeg -i input.mov -preset slow -codec:a libfdk_aac -b:a 128k -codec:v libx264 -pix_fmt yuv420p -b:v 750k -minrate 400k -maxrate 1000k -bufsize 1500k -vf scale=-1:360 output.mp4

@C0DEF52

This comment has been minimized.

Copy link

@C0DEF52 C0DEF52 commented Aug 19, 2018

Great list, thank you! Also I've found that it is possible to use -2 instead of -1 in scale argument. It will automatically fix value to be divisible by 2.

@ealgase

This comment has been minimized.

Copy link

@ealgase ealgase commented Feb 17, 2019

Thanks, this is pretty useful!

@eladkarako

This comment has been minimized.

Copy link

@eladkarako eladkarako commented Mar 16, 2019

@C0DEF52 using -2 for MP4 scaling is a very good tip,
much better then my original solution to format=pix_fmts=yuv420p,crop=trunc(in_w/2)*2:trunc(in_h/2)*2,scale=-1:360 trac.ffmpeg.org/wiki/Scaling

@Cool-Programmer

This comment has been minimized.

Copy link

@Cool-Programmer Cool-Programmer commented Apr 25, 2019

Thanks. If someone is getting libfdk_aac unknown lib error, just use "aac" instead

Also this one is for 240p
ffmpeg -i inputVideo.mp4 -threads 0 -preset slow -s 320x240 -c:v libx264 outputVideo.mp4

@ADoncel

This comment has been minimized.

Copy link

@ADoncel ADoncel commented Jul 17, 2019

-qmin and -qmax refer to Quantization and it's important in signal analysis, this picture resume what it "does":

Quantization Levels

Quantization gray scale

Reference:
https://sisu.ut.ee/sites/default/files/imageprocessing/files/digitizn.pdf

@dvlden

This comment has been minimized.

Copy link
Owner Author

@dvlden dvlden commented Jul 17, 2019

Thank you for that summary. Highly helpful! @ADoncel

@theraw

This comment has been minimized.

Copy link

@theraw theraw commented Nov 25, 2019

nice thanks man

@dan-norris

This comment has been minimized.

Copy link

@dan-norris dan-norris commented Feb 3, 2020

Thanks. If someone is getting libfdk_aac unknown lib error, just use "aac" instead

Also this one is for 240p
ffmpeg -i inputVideo.mp4 -threads 0 -preset slow -s 320x240 -c:v libx264 outputVideo.mp4

Thank you!

@arcanosam

This comment has been minimized.

Copy link

@arcanosam arcanosam commented Mar 4, 2020

Thanks. If someone is getting libfdk_aac unknown lib error, just use "aac" instead

Also this one is for 240p
ffmpeg -i inputVideo.mp4 -threads 0 -preset slow -s 320x240 -c:v libx264 outputVideo.mp4

Thank you x2 😆

@eminyalcin

This comment has been minimized.

Copy link

@eminyalcin eminyalcin commented May 13, 2020

[solved]
hi brothers. help me please. i make screen recorder in vb.net only for me. i use m.e. encoder. so my output file name is date hours.xesc.
i need to convert xesc to mp4 files. i use ffmpeg for all jpeg files in folder to mp4 file. this is work. but dont work this code.
i choose height and width for screen recorder.
please help me. i need basic code for convert

Dim args, girdi, cikti As String
girdi = "C:\video\ScreenCapture_12.05.2020 17.16.25.xesc" 'for example
cikti = "C:\videokayit\output.mp4" 'for example
args = "-i " & girdi & " -preset slow -codec:a libfdk_aac -b:a 128k -codec:v libx264 -pix_fmt yuv420p -b:v 1000k -minrate 500k -maxrate 2000k -bufsize 2000k -vf scale=854:480 " & cikti

    Dim proc As New Process
    Dim proci As New ProcessStartInfo
    proci.Arguments = args
    proci.FileName = My.Application.Info.DirectoryPath & "\ffmpeg.exe"
    proci.CreateNoWindow = True
    proci.UseShellExecute = False
    proci.WindowStyle = ProcessWindowStyle.Hidden
    proc.StartInfo = proci
    proc.Start()
    Do Until proc.HasExited = True
        Me.Text = "SAVING"
    Loop
    Me.Text = "Screen Recorder"
    MsgBox("Done") 

i think ffmpeg need good names.
example
ScreenCapture_11.05.2020 19.37.16.xesc is not work
ScreenCapture_11.05.202019.37.16.xesc is work.

new my code

Dim args As String
args = " -y -i C:/videokayit/dene.xesc -s 432x240 -b:v 384k -ac 2 -r 15 -c:v mpeg4 -ar 22050 -b:a 64k -c:a aac C:/videokayit/dene.mp4"
Dim proc As New Process
Dim proci As New ProcessStartInfo
proci.Arguments = args
proci.FileName = My.Application.Info.DirectoryPath & "\ffmpeg.exe"
proci.CreateNoWindow = True
proci.UseShellExecute = False
proci.WindowStyle = ProcessWindowStyle.Hidden
proc.StartInfo = proci

proc.Start()

Do Until proc.HasExited = True
Me.Text = "Saving"
Loop
Me.Text = "Screen recorder"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment