SMUSH ANIM files with subversion 2 provide additional fields for framerate and samplerate, use them if available, otherwise default to 12 fps which is the default for almost all ANIMv2 since 1995. Fixes the too-fast playback of test files from LucasArts games released 1995-1997. It was not noticed since Audio for those isn't decoded by ffmpeg.
Unified · Split
| @@ -51,7 +51,7 @@ static int smush_read_header(AVFormatContext *ctx) · 50 unmodified lines | ||
| 51 | 51 | AVStream *vst, *ast; |
| 52 | 52 | uint32_t magic, nframes, size, subversion, i; |
| 53 | 53 | uint32_t width = 0, height = 0, got_audio = 0, read = 0; |
| 54 | − uint32_t sample_rate, channels, palette[256]; | |
| 54 | + uint32_t sample_rate, channels, palette[256], frame_rate = 15; | |
| 55 | 55 | int ret; |
| 56 | 56 | |
| 57 | 57 | magic = avio_rb32(pb); |
| @@ -64,6 +64,7 @@ static int smush_read_header(AVFormatContext *ctx) · 6 unmodified lines | ||
| 64 | 64 | size = avio_rb32(pb); |
| 65 | 65 | if (size < 3 * 256 + 6) |
| 66 | 66 | return AVERROR_INVALIDDATA; |
| 67 | + size -= 3 * 256 + 6; | |
| 67 | 68 | |
| 68 | 69 | smush->version = 0; |
| 69 | 70 | subversion = avio_rl16(pb); |
| @@ -76,7 +77,17 @@ static int smush_read_header(AVFormatContext *ctx) · 6 unmodified lines | ||
| 76 | 77 | for (i = 0; i < 256; i++) |
| 77 | 78 | palette[i] = avio_rb24(pb); |
| 78 | 79 | |
| 79 | − avio_skip(pb, size - (3 * 256 + 6)); | |
| 80 | + if (subversion > 1) { | |
| 81 | + if (size < 12) | |
| 82 | + return AVERROR_INVALIDDATA; | |
| 83 | + size -= 12; | |
| 84 | + frame_rate = avio_rl32(pb); | |
| 85 | + avio_skip(pb, 4); // max size of FRME chunk in file | |
| 86 | + sample_rate = avio_rl32(pb); | |
| 87 | + if (frame_rate < 1 || frame_rate > 70) | |
| 88 | + frame_rate = 12; | |
| 89 | + } | |
| 90 | + avio_skip(pb, size); | |
| 80 | 91 | } else if (magic == MKBETAG('S', 'A', 'N', 'M')) { |
| 81 | 92 | if (avio_rb32(pb) != MKBETAG('S', 'H', 'D', 'R')) |
| 82 | 93 | return AVERROR_INVALIDDATA; |
| @@ -146,7 +157,7 @@ static int smush_read_header(AVFormatContext *ctx) · 63 unmodified lines | ||
| 146 | 157 | |
| 147 | 158 | smush->video_stream_index = vst->index; |
| 148 | 159 | |
| 149 | − avpriv_set_pts_info(vst, 64, 1, 15); | |
| 160 | + avpriv_set_pts_info(vst, 64, 1, frame_rate); | |
| 150 | 161 | |
| 151 | 162 | vst->start_time = 0; |
| 152 | 163 | vst->duration = |