avformat: split out common SMJPEG code