factor out ffmpeg code