How to build the ultimate media converter (no experience required)

We've concentrated very much on the basics thus far, but that's not always powerful enough. What if we want to change the resolution of the output video? Use a different audio codec? Ignore the first few seconds of the video, maybe just convert five seconds from somewhere in the middle? None of this is any problem, but it's going to require a little more work.

Resizing a video is a key first step when you'd like to play it on a mobile device, and once again FFMPEG has several tools to help. The most powerful is the scale filter:

ffmpeg -i video.mpg -vf scale=720:480 squashed.mp4

Here our video file is being re-encoded at a resolution of 720 x 480. That's fine, unless of course your input video is a different aspect ratio, in which case it'll look squashed or stretched. To avoid problems, use -1 as one of the scale values, like so:

ffmpeg -i video.mpg -vf scale=720:-1 aspect.mp4

This time FFMPEG sets the output width to 720 pixels, then calculates the height to match its aspect ratio, which should mean it looks just fine.

Trimming unwanted footage is another way to cut file size, and it's also fairly easy:

ffmpeg -ss 5 -t 30 -i video.mpg out.mp4

The -ss 5 option tells FFMPEG to start converting from around the 5 second point of the input video (this may not be exact – it depends on keyframes and other issues), and -t 30 indicates that you only want the next 30 seconds converting.

This should now be producing good results, but if your mobile device can't play the video at all then it could mean you need to use another codec. Exactly what's best will depend on your hardware and the source movie, but you could start with something like one (not both) of these:

ffmpeg -i -vcodec mpeg4 -acodec mp3 recoded2.mp4

ffmpeg -i -vcodec h264 -acodec aac recoded2.mp4

The first command sets our output video codec to MPEG4, and audio to MP3, very standard settings. The second creates an Apple-friendly H.264 video using AAC audio, as long as there's a suitable AAC encoder available (if there's a problem, FFMPEG will give you an alternative encoder – like libvo_aacenc – and all you have to do is use that instead of 'aac'). Both are very standard settings and should play on most modern devices.

If there are still problems or further tweaks you want to make, then it's just a matter of finding those options in the official documentation, and using them in your FFMPEG command. (We've considered options individually here, just for clarity, but FFMPEG will take as many as you can fit on the command line.)

Here's an all-in-one example:

ffmpeg -ss 5 -i -vf scale=640:-1 -vcodec mpeg4 -b:V 2000k -acodec mp3 -b:a 128k recoded.mp4

You should now be able to see that we're trimming the first five seconds, resizing the video, setting new video and audio codecs and defining new bitrates: not bad at all for a single line. It's still not exactly convenient to enter that every time you need to do something, of course, but that can be avoided with a little work.

ffmpeg all in one

FFMPEG can handle most media conversion tasks

Drag and drop conversions

FFMPEG's various options aren't difficult to understand, as we've seen. And while it's not naturally easy to use, creating a few batch files can make a real difference.

To begin, add the FFMPEG BIN folder to your system's PATH, so that Windows can find it. In Explorer, right click This PC, select Properties > Advanced system settings > Environment Variables, double click "Path" in the System Variables list, and add a semi-colon and your BIN folder to the end of the current path (C:\PROGRAM FILES (X86)\Something would become C:\PROGRAM FILES (X86)\Something;C:\FFMPEG\bin).

To test this, open a command prompt, type ffmpeg and press [Enter]: if you see help on FFMPEG syntax, rather than "ffmpeg is not recognised..." then it's worked just fine.

With the preparations complete, use Notepad to create a batch file called To-MP4.bat, containing the following line:

ffmpeg -i %1 %1.mp4

Now drag and drop any video onto that file and it'll launch FFMPEG with your source file as a parameter, like "ffmpeg -i c:\video\ c:\". Your new file will appear in the same folder as the source, with the same name, and an MP4 extension, without you having to type anything at all.

Create additional batch files as required, replacing MP4 with some other extension, for whatever other conversions you need.

This approach is simple, but limited, as it only converts one file at a time. To work with a group of files, use a batch file like this:

for %%a in (*.avi) do ffmpeg -i "%%a" "%%a".mp4

Place this file in a folder containing your source AVIs, double click it, and just wait for any conversions to finish.

There's a lot more scope for batch file trickery here, but even these core basic steps will take you a long way. Use different extensions, add extra commands, string them together to create your own scripts, maybe use Task Scheduler to run automatically, and you'll soon have the ultimate in media conversion toolkits – with no other software required.

Mike Williams
Lead security reviewer

Mike is a lead security reviewer at Future, where he stress-tests VPNs, antivirus and more to find out which services are sure to keep you safe, and which are best avoided. Mike began his career as a lead software developer in the engineering world, where his creations were used by big-name companies from Rolls Royce to British Nuclear Fuels and British Aerospace. The early PC viruses caught Mike's attention, and he developed an interest in analyzing malware, and learning the low-level technical details of how Windows and network security work under the hood.