Commit 6d026e3cd8 for ffmpeg
commit 6d026e3cd8a0796d976d12163d9933cb98aea654
Author: Baptiste Coudurier <baptiste.coudurier@gmail.com>
Date: Sun Nov 22 12:26:02 2026 -0800
avformat/mov: preserve precision when reading float32 metadata
Use nine significant digits and locate the radix from the scientific notation layout so multibyte separators survive normalization.
Signed-off-by: Baptiste Coudurier <baptiste.coudurier@gmail.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
diff --git a/libavformat/mov.c b/libavformat/mov.c
index 14e8dbc9bc..bf30384e47 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -636,12 +636,23 @@ retry:
}
} else if (data_type == 23 && str_size >= 4) { // BE float32
float val = av_int2float(avio_rb32(pb));
- if (snprintf(str, str_size_alloc, "%f", val) >= str_size_alloc) {
+ int scientific = isfinite(val) && val != 0;
+ int len = scientific ? snprintf(str, str_size_alloc, "%.8e", val)
+ : snprintf(str, str_size_alloc, "%g", val);
+ if (len < 0 || len >= str_size_alloc) {
av_log(c->fc, AV_LOG_ERROR,
- "Failed to store the float32 number (%f) in string.\n", val);
+ "Failed to store the float32 number (%.8e) in string.\n", val);
av_free(str);
return AVERROR_INVALIDDATA;
}
+ if (scientific) {
+ /* The radix separates one leading digit from eight digits
+ * before the exponent, regardless of its encoding. */
+ char *radix = str + (*str == '-') + 1;
+ const char *fraction = strrchr(str, 'e') - 8;
+ *radix = '.';
+ memmove(radix + 1, fraction, strlen(fraction) + 1);
+ }
} else if (data_type > 1 && data_type != 4) {
// data_type can be 0 if not set at all above. data_type 1 means
// UTF8 and 4 means "UTF8 sort". For any other type (UTF16 or e.g.
diff --git a/tests/fate/mov.mak b/tests/fate/mov.mak
index e95a444d38..47bc1fc4ec 100644
--- a/tests/fate/mov.mak
+++ b/tests/fate/mov.mak
@@ -569,7 +569,7 @@ fate-mov-yuv2-color-range: CMD = run_with_temp \
"$(call MOV_YUV2_GEN,$(MOV_YUV2_SRC))" "$(MOV_YUV2_PROBE) -color_range tv" mov
# The numeric QuickTime keys keep their type through a remux, a non-number
-# stays a string.
+# stays a string. The float32 3effffff (0.49999997) must not round to 0.5.
FATE_MOV_FFMPEG_FFPROBE-$(call ALLYES, COLOR_FILTER MPEG4_ENCODER MOV_MUXER \
MOV_DEMUXER FRAMECRC_MUXER \
FILE_PROTOCOL PIPE_PROTOCOL) \
@@ -581,7 +581,7 @@ tests/data/mov-mdta-numeric.mov: ffmpeg$(PROGSSUF)$(EXESUF) | tests/data
-flags +bitexact -fflags +bitexact -movflags use_metadata_tags \
-metadata com.apple.quicktime.full-frame-rate-playback-intent=1 \
-metadata com.apple.quicktime.live-photo.auto=1 \
- -metadata com.apple.quicktime.live-photo.vitality-score=0.918638 \
+ -metadata com.apple.quicktime.live-photo.vitality-score=0.49999997 \
-metadata com.apple.quicktime.live-photo.vitality-scoring-version=4294967296 \
-metadata com.apple.quicktime.location.role=north \
-metadata com.apple.quicktime.rating.user=-0 \
diff --git a/tests/ref/fate/mov-mdta-numeric b/tests/ref/fate/mov-mdta-numeric
index b6552e3594..cc5326bc9d 100644
--- a/tests/ref/fate/mov-mdta-numeric
+++ b/tests/ref/fate/mov-mdta-numeric
@@ -1,4 +1,4 @@
-b99988f76ef12b0f73e1fad4c64d60fc *tests/data/fate/mov-mdta-numeric.mov
+f47ccb864f2f9e0d8fe30bc6eb2123a9 *tests/data/fate/mov-mdta-numeric.mov
1337 tests/data/fate/mov-mdta-numeric.mov
#extradata 0: 30, 0x434804d7
#tb 0: 1/16384
@@ -11,10 +11,10 @@ b99988f76ef12b0f73e1fad4c64d60fc *tests/data/fate/mov-mdta-numeric.mov
TAG:major_brand=qt
TAG:minor_version=512
TAG:compatible_brands=qt
-TAG:com.apple.quicktime.rating.user=-0.000000
+TAG:com.apple.quicktime.rating.user=-0
TAG:com.apple.quicktime.location.role=north
TAG:com.apple.quicktime.live-photo.vitality-scoring-version=4294967296
TAG:com.apple.quicktime.full-frame-rate-playback-intent=1
TAG:com.apple.quicktime.live-photo.auto=1
-TAG:com.apple.quicktime.live-photo.vitality-score=0.918638
+TAG:com.apple.quicktime.live-photo.vitality-score=4.99999970e-01
[/FORMAT]