So the first post, and I suppose a sort of "making of", for Test-Videos, in this post I'll be explaining the process of making the videos found on the Big Buck Bunny MP4s Page.
Instead of going through all the different containers, I will only focus on the Big Buck Bunny MP4s Videos, while I could go through all the different contains, only slight adjustments are required for actually using a different container so there is no real benefit in covering them all.
A quick intro
In making the MP4 videos for the Big Buck Bunny test videos I wanted to start fresh, I wanted a good source of Big Buck Bunny ( it's a video I am rather fond of ), so a quick search and I found this 4k version, it was just waiting for me to play around with it!
So from this super high res video I started playing, creating little sample videos of various sizes and qualities, but creating these manually took a lot of time, so I end up creating a large batch file to do all the hard work for me.
The Batch File
So being a batch file, I'm sure you can tell I use a Windows computer, for the sake of this post I will be using a much more simplified version of the actual batch script, the full one contains a lot of extra code to handle anything I throw at and do many things that are far beyond the scope of this post, so I won't be including any of that nonsense here.
So to get straight to it this is a basic but still very handy version of the script, once made, simply dropping any kind of video onto the script itself will cause it to create the transcoded video in the same location of the original video.
Please note this is specific to the Big Buck Bunny MP4 Videos, so while it may seem like a good idea to copy and paste for yourself, the results will most likely be a video you didn't quite expect.
@echo off setlocal EnableDelayedExpansion set _dir=%~dp0 set _vid=%~dpnx1 set _bitrate=8000k %_dir%ffmpeg -ss 28 -i "%_vid%" -t 10 -c:v libx264 -preset:v placebo -b:v %_bitrate% -bufsize %_bitrate% -minrate %_bitrate% -pix_fmt yuv420p -r 30 -an -strict strict -movflags +faststart -vf scale='1920':'-1' -pass 1 -f mp4 -y NUL %_dir%ffmpeg -ss 28 -i "%_vid%" -t 10 -c:v libx264 -preset:v placebo -b:v %_bitrate% -bufsize %_bitrate% -minrate %_bitrate% -pix_fmt yuv420p -r 30 -an -strict strict -movflags +faststart -vf scale='1920':'-1' -pass 2 -f mp4 "%~dpn1_conv.mp4" endlocal
You will need to create the .bat yourself, notepad will do fine, copy and paste the script above and save with the .bat extension, then download FFmpeg and place it in the same directory as the .bat file, once done, drag and drop any video onto the .bat file and watch FFmpeg do its thing.
Also you may want to change the '-preset:v placebo' to '-preset:v medium' for a quicker conversion, placebo is incredibly slow and only returns marginally better results than the next slowest preset 'veryslow'. More information can be found here ffmpeg.org/wiki/Encode/H.264
Explaining the script
So lets go through what is happening, I'm not going to cover batch specifics here as that would make this a very long read indeed.
Right, so to start,
This simply creates a variable _dir that stores the .bat files location, this is also where it calls FFmpeg from, so wherever your .bat file is, put ffmpeg.exe right next to it.
This stores the absolute location of the video that was dropped onto the .bat file in _vid.
There are no checks to make sure the dropped file is actually a video, so dropping other files onto the .bat file will cause undesired effects.
This is where we set the targeted bitrate, using it as a variable just makes life easier when changing it for future conversions.
In the Big Buck Bunny MP4 videos, I wanted to have a specific file size for the videos, so the bitrate I entered had to be precise. So to get the desired file size, I needed to know the file size and the videos length, in this case, it was easily known, all the videos are 10 seconds long and the file size was simply a matter of deciding what I preferred.
So knowing these two values, I can work out the required bitrate,
( [Target File Size in MB] * 8000 ) / [Video Length in Seconds]
This results in
( 30 * 8000 ) / 10.
So for a 10 second long video that I want to be 30MB in size, I use the bitrate of 24000KB, easy.
And on to the last and most important part,
%_dir%ffmpeg -ss 28 -i "%_vid%" -t 10 -c:v libx264 -preset:v placebo -b:v %_bitrate% -bufsize %_bitrate% -minrate %_bitrate% -pix_fmt yuv420p -r 30 -an -strict strict -movflags +faststart -vf scale='1920':'-1' -pass 1 -f mp4 -y NUL
This calls ffmpeg using the location from
_dir, sets the starting position to 28 seconds
-ss 28, tells it the video we are transcoding is
The duration of the video is to be 10 seconds long
-t 10, the video codec to use is libx264,
-c:v libx264, we want to use the x264 preset placebo,
-preset:v placebo and we want a very specific bitrate,
-b:v %_bitrate% -bufsize %_bitrate% -minrate %_bitrate% -maxrate %_bitrate%.
Use the compatible pixel format yuv420p,
-pix_fmt yuv420p, set a frame rate of 30 frames per second,
-r 30, disable all audio,
-an, tell the encoder to conform to strict standards ( for everyday use this is not needed ), move the header to the start of the file, ( this is mainly for streaming uses ),
-movflags +faststart, resize the video to my desired dimensions,
-vf scale='1920':'-1', -1 tells FFmpeg to choose the correct height based on the width we chose.
Tell FFmpeg which pass we are on,
-pass 1, tell it the correct format,
-f mp4, that we want to overwrite any files which may already exist,
-y, output the transcoded video to
NUL, in Windows this is the equivelent of /dev/null on UNIX machine, it sends the output to the NUL device which discards any input.
On the last pass
-pass 2, we want to output the actual video and not discard it,
"%~dpn1_conv.mp4", this tells FFmpeg to out the video in the same location as the video file that was dropped onto it, with the same name but append "_conv" to the filename.
Well I hope this brings some insight into the making of Test-Videos.co.uk and potentially some assistance in the use of FFmpeg, albeit very limited.