PR #20986 opened by GXTX
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20986
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20986.patch

Fixes #20983

I believe this is mostly correct, however, I did run into *another* file that 
fails to en/decode properly when compression is 1 and bitrate is 44100, 
specifically the Valve intro XMV found on Half-Life 2.

This is odd because it has the same header info from a different file which is 
properly handled.

HL2: Valve_Leader.xmv
```
Version: 4
Video Width: 280
Video Height: 1e0
Duration: 44ef
# of audio tracks: 1
    0: Compression: 1, Channels: 2, Sample Rate: ac44, BPS: 10, Flags: 0
```
HL2: Demo_Attract.xmv
```
Version: 4
Video Width: 280
Video Height: 1e0
Duration: 1fad9
# of audio tracks: 1
    0: Compression: 1, Channels: 2, Sample Rate: ac44, BPS: 10, Flags: 0
```

In either case the changes here make FFmpeg's XMV en/decoder mostly functional.
Let me know if I can provide any samples, etc. and I can obviously remove the 
`#if 0` block if requested.



>From 86bee2b7118224064b9e4df90956f7148fc45717 Mon Sep 17 00:00:00 2001
From: wutno <[email protected]>
Date: Thu, 20 Nov 2025 16:24:08 -0500
Subject: [PATCH] avformat/xmv: Better handling of audio compressions relation
 to sample blocks

---
 libavformat/xmv.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/libavformat/xmv.c b/libavformat/xmv.c
index ed59f7b85b..098b0df0f6 100644
--- a/libavformat/xmv.c
+++ b/libavformat/xmv.c
@@ -194,7 +194,10 @@ static int xmv_read_header(AVFormatContext *s)
                                 packet->sample_rate *
                                 packet->channels;
         packet->block_align   = XMV_BLOCK_ALIGN_SIZE * packet->channels;
-        packet->block_samples = 64;
+        if (packet->compression == 1)
+            packet->block_samples = XMV_BLOCK_ALIGN_SIZE / packet->channels;
+        else
+            packet->block_samples = 64;
         packet->codec_id      = ff_wav_codec_get_id(packet->compression,
                                                     packet->bits_per_sample);
 
@@ -202,6 +205,12 @@ static int xmv_read_header(AVFormatContext *s)
 
         packet->frame_size  = 0;
         packet->block_count = 0;
+    
+#if 0
+        if (packet->compression == 1 && packet->sample_rate == 44100) {
+            av_log(s, AV_LOG_WARNING, "We may not be able to handle this 
properly...\n");
+        }
+#endif
 
         /* TODO: ADPCM'd 5.1 sound is encoded in three separate streams.
          *       Those need to be interleaved to a proper 5.1 stream. */
@@ -340,7 +349,7 @@ static int xmv_process_packet_header(AVFormatContext *s)
             ast->codecpar->sample_rate           = packet->sample_rate;
             ast->codecpar->bits_per_coded_sample = packet->bits_per_sample;
             ast->codecpar->bit_rate              = packet->bit_rate;
-            ast->codecpar->block_align           = 36 * packet->channels;
+            ast->codecpar->block_align           = XMV_BLOCK_ALIGN_SIZE * 
packet->channels;
 
             avpriv_set_pts_info(ast, 32, packet->block_samples, 
packet->sample_rate);
 
-- 
2.49.1

_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to