[FFmpeg-devel] [PATCH] avformat/xmv: Handle zero sized packet at end of file (PR #20985)

2025-11-20 Thread GXTX via ffmpeg-devel
PR #20985 opened by GXTX
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20985
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20985.patch

Fixes: #20982

This doesn't appear with every XMV.


>From 797d63a4d77ab06dafedb4d76a8393481bcc7b2f Mon Sep 17 00:00:00 2001
From: wutno 
Date: Thu, 20 Nov 2025 16:19:49 -0500
Subject: [PATCH] avformat/xmv: Handle zero sized packet at end of file

---
 libavformat/xmv.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/libavformat/xmv.c b/libavformat/xmv.c
index ed59f7b85b..63ae4a05a7 100644
--- a/libavformat/xmv.c
+++ b/libavformat/xmv.c
@@ -417,6 +417,12 @@ static int xmv_fetch_new_packet(AVFormatContext *s)
 /* Seek to it */
 xmv->this_packet_offset = xmv->next_packet_offset;
 if (avio_seek(pb, xmv->this_packet_offset, SEEK_SET) != 
xmv->this_packet_offset)
+/* It's possible the packet we're about to work on has no size. This 
can
+ * happen when it's the last packet of the XMV. So, let's check if 
we're
+ * at the end of the file again and gracefully close out.
+ */
+if (xmv->this_packet_offset == xmv->next_packet_offset)
+return AVERROR_EOF;
 return AVERROR(EIO);
 
 /* Update the size */
-- 
2.49.1

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


[FFmpeg-devel] [PATCH] avformat/xmv: Better handling of audio compressions relation to sample blocks (PR #20986)

2025-11-20 Thread GXTX via ffmpeg-devel
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 
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]