Transcoding video files with FFMPEG to save space

FFMpeg image

So recently I almost run out of free disk space on my Google Drive – free 15G was mostly used by some video recorded with my mobile phone. Before purchasing any further space I decided to take a look on how much I could save on the space if I transcoded the video files that other way were not touched by anything since recorded. After while I learned on how to use the ffmpeg tool to achieve this – the results overcame my expectations.

The command:

$ffmpeg -i [input video file] -crf 28 -vcodec libx264 -preset veryslow [output video file].mp4

Then to tackle all the files in current directory I wrapped this in a simple FOR LOOP (BASH):

$for F in $(find ./ -maxdepth 1 -type f -iname '*.mp4'); do P=$(basename $F); echo $P; ls -lah $F; ffmpeg -i $F -crf 28 -vcodec libx264 -preset veryslow encoded/$P; done

The command above finds all video files in current directory that have extension *.mp4 and is transcoding all of them using the H.264 library with output being written to “encoded” directory under current location (the directory must exist!).

The transcoding takes significant amount of time so for large files it’s best to leave it to run over the night. Saved space vs. quality loss is brilliant – my files shrieked between 4-8 times and I was not able to observer any quality loss (most of the video files in question was taken with my Nexus 5 at HD quality).

Explanation of the used arguments:

-crf 28

Constant Rate Factor – The range of the quantizer scale is 0-51: where 0 is lossless, 23 is default, and 51 is worst possible. A lower value is a higher quality and a subjectively sane range is 18-28. Consider 18 to be visually lossless or nearly so: it should look the same or nearly the same as the input but it isn’t technically lossless.

-preset veryslow

The general guideline is to use the slowest preset that you have patience for. Current presets in descending order of speed are: ultrafast,superfast, veryfast, faster, fast, medium, slow, slower, veryslow, placebo. A slower preset will provide better compression (compression is quality per filesize).

The explanation is taken from here where more information is available.

Posted in The actual scratchpad | Tagged , , , , , , , , , | Leave a comment

A text based text enlarging tool ;)

So recently I have been playing with PIL in Python as I attempted to convert on the fly picture from my web camera to text-graphic… Yeah, I know, it doesn’t even sound right! This project is working but I havent called it yet done – when it is I certainly will publish it here.

Meanwhile (out of boredom) I wrote this tiny script that takes a string that then gets converted to a black&white picture which then gets interpreted a pixel by pixel and printed to the terminal with different character where a pixel belonged to black colour and different where it was white.

It’s easier to explain with an example so this is an output of the following command:

$ python ./ "" 15

The font can be specified within the script – I went for the TTF type of fonts.

I had no purpose for this script when writing it but I imagine it could be used to generate some MOTD (Message Of The Day) content or whatever else…

The script can be cloned from it’s repository here:
Hope you enjoy it.

Posted in Programming | Tagged , , , | Leave a comment

A bluetooth started song on a MPD server

This is a very simple Python script that I put together some time ago. I had only two goals on my mind when writing this: see if I can and fun. Both goals were achieved.

The script uses bluetooth module to scan for bluetooth device in surroundings and compares it with those provided in script itself. If it encounters a matching device then it will attempt to connect to the MPD server and play selected song. If the song is not on the current play list then it will try to find it in the library, add i to the play list and play.

I ran this script at my work desktop (Ubuntu with bluetooth dongle) and triggered it with my phone’s bluetooth (by enabling it and making visible) for couple of days when entering the office I felt like the Lord Vader with imperial march was started upon my arrival.

Full script can be obtained from my Bitbucket Git repository, below are only few “configuration” lines:

Define device and music track:

user3 = {
'title':"The Empire Strikes Back",

The “bt_addr” is of course the address of the bluetooth device that will trigger the action. The “song” holds a full path to the selected track from point of view of the MPD’s media library where “title” is a piece of title of the song by which we would be able to locate this one specific song in the whole MPD library – it will be used to find and add the track to the current playlist shouldn’t it be there already. “start_second” tells the MPD where to start the track – our track my start from specific moment for greater effect.

All that’s left is to ensure that it will be loud enough to bring an attention:


And start playing at selected moment:


The only issue I had with this is that it usually takes some time for the bluetooth device to be discovered and therefore it’s hard to synchronise with the music. Nevertheless it was fun for me and I hope it will be some use to you also.

Full script can be cloned from with following repository:

Posted in Programming | Tagged | Leave a comment