diff --git a/libavformat/cdxl.c b/libavformat/cdxl.c
index 185b745..c73ec72 100644
--- a/libavformat/cdxl.c
+++ b/libavformat/cdxl.c
@@ -37,6 +37,7 @@ typedef struct CDXLDemuxContext {
     uint8_t     header[CDXL_HEADER_SIZE];
     int         video_stream_index;
     int         audio_stream_index;
+    int64_t     filesize;
 } CDXLDemuxContext;
 
 static int cdxl_read_probe(AVProbeData *p)
@@ -84,7 +85,7 @@ static int cdxl_read_probe(AVProbeData *p)
 static int cdxl_read_header(AVFormatContext *s)
 {
     CDXLDemuxContext *cdxl = s->priv_data;
-    int ret;
+    int frames, ret;
 
     if (cdxl->framerate && (ret = av_parse_video_rate(&cdxl->fps, cdxl->framerate)) < 0) {
         av_log(s, AV_LOG_ERROR,
@@ -92,6 +93,8 @@ static int cdxl_read_header(AVFormatContext *s)
         return ret;
     }
 
+    cdxl->filesize = avio_size(s->pb);
+
     cdxl->read_chunk         =  0;
     cdxl->video_stream_index = -1;
     cdxl->audio_stream_index = -1;
@@ -129,6 +132,8 @@ static int cdxl_read_packet(AVFormatContext *s, AVPacket *pkt)
     audio_size   = AV_RB16(&cdxl->header[22]);
     image_size   = FFALIGN(width, 16) * height * cdxl->header[19] / 8;
     video_size   = palette_size + image_size;
+    
+    frames       = cdxl->filesize / (audio_size + video_size);
 
     if (palette_size > 512)
         return AVERROR_INVALIDDATA;
@@ -175,6 +180,8 @@ static int cdxl_read_packet(AVFormatContext *s, AVPacket *pkt)
             st->codec->codec_id      = AV_CODEC_ID_CDXL;
             st->codec->width         = width;
             st->codec->height        = height;
+            if(!cdxl->framerate)
+            st->duration             = frames * audio_size;
             st->start_time           = 0;
             cdxl->video_stream_index = st->index;
             if (cdxl->framerate)
