Code from ffmpeg tutorial by dragger