code taken out from ffmpeg's code base example's to make it usable in other programs.