[FFmpeg-devel] [PATCH]Support audio-only vmd files

Carl Eugen Hoyos cehoyos at ag.or.at
Fri May 3 08:39:06 CEST 2013


Hi!

Attached patch allows decoding of the (audio-only) files in 
http://samples.ffmpeg.org/game-formats/sierra-vmd/lastdynasty/ beginning 
with "HR".

Please comment, Carl Eugen
-------------- next part --------------
diff --git a/libavformat/sierravmd.c b/libavformat/sierravmd.c
index b0b582d..e109a01 100644
--- a/libavformat/sierravmd.c
+++ b/libavformat/sierravmd.c
@@ -64,7 +64,7 @@ typedef struct VmdDemuxContext {
 
 static int vmd_probe(AVProbeData *p)
 {
-    int w, h;
+    int w, h, sample_rate;
     if (p->buf_size < 16)
         return 0;
     /* check if the first 2 bytes of the file contain the appropriate size
@@ -73,7 +73,9 @@ static int vmd_probe(AVProbeData *p)
         return 0;
     w = AV_RL16(&p->buf[12]);
     h = AV_RL16(&p->buf[14]);
+    sample_rate = AV_RL16(&p->buf[804]);
-    if (!w || w > 2048 || !h || h > 2048)
+    if ((!w || w > 2048 || !h || h > 2048) &&
+        sample_rate != 22050)
         return 0;
 
     /* only return half certainty since this check is a bit sketchy */
@@ -84,12 +86,12 @@ static int vmd_read_header(AVFormatContext *s)
 {
     VmdDemuxContext *vmd = s->priv_data;
     AVIOContext *pb = s->pb;
-    AVStream *st = NULL, *vst;
+    AVStream *st = NULL, *vst = NULL;
     unsigned int toc_offset;
     unsigned char *raw_frame_table;
     int raw_frame_table_size;
     int64_t current_offset;
-    int i, j;
+    int i, j, width, height;
     unsigned int total_frames;
     int64_t current_audio_pts = 0;
     unsigned char chunk[BYTES_PER_FRAME_RECORD];
@@ -101,6 +103,9 @@ static int vmd_read_header(AVFormatContext *s)
     if (avio_read(pb, vmd->vmd_header, VMD_HEADER_SIZE) != VMD_HEADER_SIZE)
         return AVERROR(EIO);
 
+    width = AV_RL16(&vmd->vmd_header[12]);
+    height = AV_RL16(&vmd->vmd_header[14]);
+    if (width && height) {
     if(vmd->vmd_header[24] == 'i' && vmd->vmd_header[25] == 'v' && vmd->vmd_header[26] == '3')
         vmd->is_indeo3 = 1;
     else
@@ -114,8 +119,8 @@ static int vmd_read_header(AVFormatContext *s)
     vst->codec->codec_type = AVMEDIA_TYPE_VIDEO;
     vst->codec->codec_id = vmd->is_indeo3 ? AV_CODEC_ID_INDEO3 : AV_CODEC_ID_VMDVIDEO;
     vst->codec->codec_tag = 0;  /* no fourcc */
-    vst->codec->width = AV_RL16(&vmd->vmd_header[12]);
-    vst->codec->height = AV_RL16(&vmd->vmd_header[14]);
+    vst->codec->width = width;
+    vst->codec->height = height;
     if(vmd->is_indeo3 && vst->codec->width > 320){
         vst->codec->width >>= 1;
         vst->codec->height >>= 1;
@@ -123,6 +128,7 @@ static int vmd_read_header(AVFormatContext *s)
     vst->codec->extradata_size = VMD_HEADER_SIZE;
     vst->codec->extradata = av_mallocz(VMD_HEADER_SIZE + FF_INPUT_BUFFER_PADDING_SIZE);
     memcpy(vst->codec->extradata, vmd->vmd_header, VMD_HEADER_SIZE);
+    }
 
     /* if sample rate is 0, assume no audio */
     vmd->sample_rate = AV_RL16(&vmd->vmd_header[804]);
@@ -156,7 +162,8 @@ static int vmd_read_header(AVFormatContext *s)
         num = st->codec->block_align;
         den = st->codec->sample_rate * st->codec->channels;
         av_reduce(&num, &den, num, den, (1UL<<31)-1);
+        if (vst)
-        avpriv_set_pts_info(vst, 33, num, den);
+            avpriv_set_pts_info(vst, 33, num, den);
         avpriv_set_pts_info(st, 33, num, den);
     }
 


More information about the ffmpeg-devel mailing list