Kill FFmpeg process smoothly

by GarciaPL on Thursday, 3 April 2014

Let's assume that you use FFmpeg distribution in your application. One of your function is for instance saving some HLS stream (HTTP Live Streaming) into file. I suppose you are using python subprocess module to create process in Linux OS to obtain this stream to your hard disk.

In normal way if you would like to stop saving this content using FFmpeg on your storage, you will just press 'q' button while you are in terminal. Due to this FFmpeg will be able to finish saving content and do not damage the file at the end.

There is some kind of problem if you would like to kill this FFmpeg process in smooth way without damaging the file while you do not have access to the terminal.

You can use below solution written in Python to kill this FFmpeg process from your application. Only input which you need to ensure is PID (Process IDentifier) which describes your  process. You can use below shell code in Linux :

ps -ef | grep ffmpeg | awk '{print $2}'

Once you know PID of your FFmpeg process just use this Python code :
import psutil
import os
import signal

pids = psutil.get_pid_list()

for pid in pids:
      if (pid == <your_PID>):
One thing is worthy of attention. You suppose to use mainly signal.SIGINT while you invoke os.kill function, because of it simulates in FFmpeg case the user interrupt of this process (typically initiated by pressing Control-C) which allow to FFmpeg to end his work properly.

Reference : [1] Subprocess Docs [2] Sending sighup signal to some external [3] Unix signal - SIGINT

FFmpeg parse video/audio bitrate

by GarciaPL on Tuesday, 25 March 2014

Have you ever thought how receive the bitrate of your video/audio file using ffmpeg in command line ? Before I will show you a solution of this problem I would like to paste below some example output of video file which can be obtained using ffmpeg :

ffmpeg version git-2013-10-30-94a80e3 Copyright (c) 2000-2013 the FFmpeg developers
  built on Oct 30 2013 15:46:23 with gcc 4.8 (Ubuntu/Linaro 4.8.1-10ubuntu8)
  configuration: --prefix=/home/user/ffmpeg_build --extra-cflags=-I/home/user/ffmpeg_build/include --extra-ldflags=-L/home/luszcwoj/ffmpeg_build/lib --bindir=/home/luszcwoj/bin --extra-libs=-ldl --enable-gpl --enable-libass --enable-libfdk-aac --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-nonfree --enable-x11grab
  libavutil      52. 48.100 / 52. 48.100
  libavcodec     55. 39.100 / 55. 39.100
  libavformat    55. 19.104 / 55. 19.104
  libavdevice    55.  5.100 / 55.  5.100
  libavfilter     3. 90.100 /  3. 90.100
  libswscale      2.  5.101 /  2.  5.101
  libswresample   0. 17.104 /  0. 17.104
  libpostproc    52.  3.100 / 52.  3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'aquarium.mp4':
    major_brand     : isom
    minor_version   : 0
    compatible_brands: isom3gp4
    creation_time   : 2013-09-08 23:38:41
  Duration: 00:00:03.44, start: 0.000000, bitrate: 3933 kb/s
    Stream #0:0(eng): Video: h264 (Baseline) (avc1 / 0x31637661), yuvj420p(pc), 640x480 [SAR 1:1 DAR 4:3], 2250 kb/s, 29.70 fps, 29.67 tbr, 90k tbn, 30 tbc (default)
      creation_time   : 2013-09-08 23:38:41
      handler_name    : VideoHandle
    Stream #0:1(eng): Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 123 kb/s (default)
      creation_time   : 2013-09-08 23:38:41
      handler_name    : SoundHandle

If you would like to get the bitrate just use this command :
ffmpeg -i aquarium.mp4 2>&1 | grep bitrate: | awk '{print $6}'

Reference : [1] FFmpeg Home Page

Remove all tables from a MySQL schema

by GarciaPL on Thursday, 6 March 2014

A few days ago I found very useful solution (thanks for Biomathematicus!) for deleting tables from a MySQL schema. I know that it could be quite difficult for some developers (also for me) to manually remove every table from schema without removing this schema itself. So, there is a two-step solution which is going to help you removing a lot of tables from SQL database.

1) List all tables in the MySQL schema :

SELECT CONCAT('drop table ',table_name,'; ')
FROM information_schema.tables
WHERE table_schema = 'yourDatabaseName';

2) Copy result and paste it to query window and execute.
drop table table1; 
drop table table2;

Reference : [1] Remove all tables from mysql schema

Confitura 2013 - my participation

by GarciaPL on Sunday, 9 February 2014

I really really would like to share with a video of my participation on conference called "Confitura" in the year 2013.

Confitura is the largest free conference for Java developers in Europe and even the largest event of its kind in Poland. 6 July this year on the campus of the University of Warsaw will be the next edition of our conference. From year to year we develop and we host a growing number of enthusiasts programming, a year ago there were more than 800. This year we expect nearly 1,000 people, for whom we have prepared five parallel tracks of almost 30 lectures.

More information you can find on :

Video :

You can see when I am talking a lot of about many interesting and clever things starting from 0:34 second of this video ;) Enjoy.

Django - 'charmap' codec can't encode characters in position

by GarciaPL on Wednesday, 1 January 2014

I used to have a problem while I was developing some application using Django (Python Web Framework). This problem occurs when I received some data from some kind of source using for example JSON notation. When this data contains some custom characters which should be saved in Unicode notation, I received and error like this one :

'charmap' codec can't encode characters in position
The solution of this issue is quite easy - everything applies to encoding of your file with source code. In this case I used to editor called PyDev (Eclipse based) in which you should go to :
Windows -> Preferences -> General -> Workspace
after that change option 'Text File Encoding' to UTF-8

References : [1] Django Python Web Framework [2] Newcomer error in parsing tweet json unicodeencodeerror charmap codec cant encode characters in position 13-63: character maps to <undefined>

phpPgAdmin - Login disallowed

by GarciaPL on Saturday, 21 December 2013

Few days ago I had pleasure to install on my web server called XAMPP delivered by Apache Friends one of the management tool for PostgreSQL called PhpPgAdmin. I must to say that installation is very easy, all you have to do is to put extracted files of this tool to htdocs folder, edit config located on phpPgAdmin/conf/ and just run index.php through your web browser.

Unfortunately in my case there was some issue with connecting to PostgreSQL database. I had message something like "Login disallowed". I spent a lot of time to figure out the right solution, which I am going to share with you.

Just go to file on this path - phpPgAdmin/conf/ and just change

$conf['extra_login_security'] = true


$conf['extra_login_security'] = false

Reference : [1] PhpPgAdmin Home Page [2] XAMPP Home Page