+ avio_seek(pb, -FLIC_PREAMBLE_SIZE, SEEK_CUR);
+
+ /* Time to figure out the framerate:
+ * If the first preamble's magic number is 0xAAAA then this file is from
+ * X-COM: Terror from the Deep. If on the other hand there is a FLIC chunk
+ * magic number at offset 0x10 assume this file is from Magic Carpet instead.
+ * If neither of the above is true then this is a normal FLIC file.
+ */
+ if (AV_RL16(&preamble[4]) == FLIC_TFTD_CHUNK_AUDIO) {
+ /* TFTD videos have an extra 22050 Hz 8-bit mono audio stream */
+ ast = avformat_new_stream(s, NULL);
+ if (!ast)
+ return AVERROR(ENOMEM);
+
+ flic->audio_stream_index = ast->index;
+
+ /* all audio frames are the same size, so use the size of the first chunk for block_align */
+ ast->codec->block_align = AV_RL32(&preamble[0]);
+ ast->codec->codec_type = AVMEDIA_TYPE_AUDIO;
+ ast->codec->codec_id = AV_CODEC_ID_PCM_U8;
+ ast->codec->codec_tag = 0;
+ ast->codec->sample_rate = FLIC_TFTD_SAMPLE_RATE;
+ ast->codec->channels = 1;
+ ast->codec->sample_fmt = AV_SAMPLE_FMT_U8;
+ ast->codec->bit_rate = st->codec->sample_rate * 8;
+ ast->codec->bits_per_coded_sample = 8;
+ ast->codec->channel_layout = AV_CH_LAYOUT_MONO;
+ ast->codec->extradata_size = 0;
+
+ /* Since the header information is incorrect we have to figure out the
+ * framerate using block_align and the fact that the audio is 22050 Hz.
+ * We usually have two cases: 2205 -> 10 fps and 1470 -> 15 fps */
+ avpriv_set_pts_info(st, 64, ast->codec->block_align, FLIC_TFTD_SAMPLE_RATE);
+ avpriv_set_pts_info(ast, 64, 1, FLIC_TFTD_SAMPLE_RATE);
+ } else if (AV_RL16(&header[0x10]) == FLIC_CHUNK_MAGIC_1) {
+ avpriv_set_pts_info(st, 64, FLIC_MC_SPEED, 70);