This is an automated email from the git hooks/post-receive script.

Git pushed a commit to branch master
in repository ffmpeg.

The following commit(s) were added to refs/heads/master by this push:
     new 38353ad6c3 avformat/mov,movenc: handle the loci location independently 
of the locale
38353ad6c3 is described below

commit 38353ad6c3f9912ac0912cfee7763fd18da4badb
Author:     Baptiste Coudurier <[email protected]>
AuthorDate: Thu Nov 12 13:57:21 2026 -0800
Commit:     Baptiste Coudurier <[email protected]>
CommitDate: Tue Nov 17 18:56:16 2026 +0000

    avformat/mov,movenc: handle the loci location independently of the locale
    
    Print it in the QuickTime ISO 6709 format from the exact 16.16 values,
    and parse it with av_sscanf(), rounding to the nearest 16.16 value.
    Fixes #25916.
    
    Signed-off-by: Baptiste Coudurier <[email protected]>
---
 libavformat/mov.c                                  | 23 +++++++++++-------
 libavformat/movenc.c                               | 28 +++++++++-------------
 tests/fate/mov.mak                                 | 12 ++++++++++
 .../fate/{mov-composer-metadata => mov-mp4-loci}   |  9 +++----
 ...-composer-metadata => mov-mp4-loci-no-altitude} |  9 +++----
 5 files changed, 43 insertions(+), 38 deletions(-)

diff --git a/libavformat/mov.c b/libavformat/mov.c
index eba7619ed1..7c91c32999 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -286,7 +286,8 @@ static int mov_metadata_loci(MOVContext *c, AVIOContext 
*pb, unsigned len)
     char language[4] = { 0 };
     char buf[200], place[100];
     uint16_t langcode = 0;
-    double longitude, latitude, altitude;
+    int32_t longitude, latitude, altitude;
+    int64_t lat, lon, alt;
     const char *key = "location";
 
     if (len < 4 + 2 + 1 + 1 + 4 + 4 + 4) {
@@ -312,15 +313,19 @@ static int mov_metadata_loci(MOVContext *c, AVIOContext 
*pb, unsigned len)
                "loci too short (%u bytes left, need at least %d)\n", len, 12);
         return AVERROR_INVALIDDATA;
     }
-    longitude = ((int32_t) avio_rb32(pb)) / (float) (1 << 16);
-    latitude  = ((int32_t) avio_rb32(pb)) / (float) (1 << 16);
-    altitude  = ((int32_t) avio_rb32(pb)) / (float) (1 << 16);
+    longitude = avio_rb32(pb);
+    latitude  = avio_rb32(pb);
+    altitude  = avio_rb32(pb);
 
-    // Try to output in the same format as the ?xyz field
-    snprintf(buf, sizeof(buf), "%+08.4f%+09.4f",  latitude, longitude);
-    if (altitude)
-        av_strlcatf(buf, sizeof(buf), "%+f", altitude);
-    av_strlcatf(buf, sizeof(buf), "/%s", place);
+    // ISO 6709 string as written by QuickTime, independently of the locale
+    lat = llrint(fabs(latitude  * (10000.0 / (1 << 16))));
+    lon = llrint(fabs(longitude * (10000.0 / (1 << 16))));
+    alt = llrint(fabs(altitude  * (1000.0  / (1 << 16))));
+    snprintf(buf, sizeof(buf), 
"%c%02"PRId64".%04"PRId64"%c%03"PRId64".%04"PRId64
+             "%c%03"PRId64".%03"PRId64"/%s",
+             latitude  < 0 ? '-' : '+', lat / 10000, lat % 10000,
+             longitude < 0 ? '-' : '+', lon / 10000, lon % 10000,
+             altitude  < 0 ? '-' : '+', alt / 1000,  alt % 1000, place);
 
     if (*language && strcmp(language, "und")) {
         char key2[16];
diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index 27e1dd7718..293a85633e 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -4861,36 +4861,30 @@ static int mov_write_loci_tag(AVFormatContext *s, 
AVIOContext *pb)
 {
     int lang;
     int64_t pos = avio_tell(pb);
-    double latitude, longitude, altitude;
+    double latitude, longitude, altitude = 0;
     int32_t latitude_fix, longitude_fix, altitude_fix;
     AVDictionaryEntry *t = get_metadata_lang(s, "location", &lang);
     const char *ptr, *place = "";
-    char *end;
+    int n = 0;
     static const char *astronomical_body = "earth";
     if (!t)
         return 0;
 
     ptr = t->value;
-    latitude = strtod(ptr, &end);
-    if (end == ptr) {
+    if (av_sscanf(ptr, "%lf%lf%n", &latitude, &longitude, &n) < 2) {
         av_log(s, AV_LOG_WARNING, "malformed location metadata\n");
         return 0;
     }
-    ptr = end;
-    longitude = strtod(ptr, &end);
-    if (end == ptr) {
-        av_log(s, AV_LOG_WARNING, "malformed location metadata\n");
-        return 0;
-    }
-    ptr = end;
-    altitude = strtod(ptr, &end);
+    ptr += n;
     /* If no altitude was present, the default 0 should be fine */
-    if (*end == '/')
-        place = end + 1;
+    if (av_sscanf(ptr, "%lf%n", &altitude, &n) == 1)
+        ptr += n;
+    if (*ptr == '/')
+        place = ptr + 1;
 
-    latitude_fix  = (int32_t) ((1 << 16) * latitude);
-    longitude_fix = (int32_t) ((1 << 16) * longitude);
-    altitude_fix  = (int32_t) ((1 << 16) * altitude);
+    latitude_fix  = lrint(av_clipd((1 << 16) * latitude,  INT32_MIN, 
INT32_MAX));
+    longitude_fix = lrint(av_clipd((1 << 16) * longitude, INT32_MIN, 
INT32_MAX));
+    altitude_fix  = lrint(av_clipd((1 << 16) * altitude,  INT32_MIN, 
INT32_MAX));
 
     avio_wb32(pb, 0);         /* size */
     ffio_wfourcc(pb, "loci"); /* type */
diff --git a/tests/fate/mov.mak b/tests/fate/mov.mak
index 89e4ef9abc..ad45fb91e3 100644
--- a/tests/fate/mov.mak
+++ b/tests/fate/mov.mak
@@ -428,6 +428,18 @@ fate-mov-composer-metadata: CMD = transcode wav 
./tests/data/asynth-44100-2.wav
     "-af aresample -c:a pcm_s16le -t 0.05 -metadata composer=Bach" \
     "-af aresample -c:a pcm_s16le" "-show_entries format_tags"
 
+# 3GPP loci location: ties rounded to even, the altitude clipped to its
+# 16.16 range, and a missing altitude written as zero.
+FATE_MOV_FFMPEG_FFPROBE-$(call TRANSCODE, PCM_S16LE, MP4 MOV, WAV_DEMUXER 
ARESAMPLE_FILTER) \
+                       += fate-mov-mp4-loci fate-mov-mp4-loci-no-altitude
+fate-mov-mp4-loci fate-mov-mp4-loci-no-altitude: tests/data/asynth-44100-2.wav
+fate-mov-mp4-loci: CMD = transcode wav ./tests/data/asynth-44100-2.wav mp4 \
+    "-af aresample -c:a pcm_s16le -t 0.05 -metadata 
location=+00.03125-000.15625+32767.999999/Place" \
+    "-af aresample -c:a pcm_s16le" "-show_entries format_tags=location"
+fate-mov-mp4-loci-no-altitude: CMD = transcode wav 
./tests/data/asynth-44100-2.wav mp4 \
+    "-af aresample -c:a pcm_s16le -t 0.05 -metadata 
location=-33.8568+151.2153/" \
+    "-af aresample -c:a pcm_s16le" "-show_entries format_tags=location"
+
 FATE_MOV_FFMPEG_FFPROBE-$(call ALLYES, COLOR_FILTER SETPTS_FILTER 
MPEG4_ENCODER \
                                       MOV_MUXER MOV_DEMUXER FILE_PROTOCOL)     
 \
                                       += fate-mov-vfr-bframes-derived-duration
diff --git a/tests/ref/fate/mov-composer-metadata b/tests/ref/fate/mov-mp4-loci
similarity index 59%
copy from tests/ref/fate/mov-composer-metadata
copy to tests/ref/fate/mov-mp4-loci
index 36ac7861d8..61d8ec6046 100644
--- a/tests/ref/fate/mov-composer-metadata
+++ b/tests/ref/fate/mov-mp4-loci
@@ -1,5 +1,5 @@
-2e6eec0db55953fbfc36508c97ad1a8e *tests/data/fate/mov-composer-metadata.mov
-9497 tests/data/fate/mov-composer-metadata.mov
+354a338c45ee40362460a8f6e950289a *tests/data/fate/mov-mp4-loci.mp4
+9570 tests/data/fate/mov-mp4-loci.mp4
 #tb 0: 1/44100
 #media_type 0: audio
 #codec_id 0: pcm_s16le
@@ -9,8 +9,5 @@
 0,       1024,       1024,     1024,     4096, 0x18390b96
 0,       2048,       2048,      157,      628, 0x4db5381d
 [FORMAT]
-TAG:major_brand=qt  
-TAG:minor_version=512
-TAG:compatible_brands=qt  
-TAG:composer=Bach
+TAG:location=+00.0312-000.1562+32768.000/Place
 [/FORMAT]
diff --git a/tests/ref/fate/mov-composer-metadata 
b/tests/ref/fate/mov-mp4-loci-no-altitude
similarity index 59%
copy from tests/ref/fate/mov-composer-metadata
copy to tests/ref/fate/mov-mp4-loci-no-altitude
index 36ac7861d8..255d784fd4 100644
--- a/tests/ref/fate/mov-composer-metadata
+++ b/tests/ref/fate/mov-mp4-loci-no-altitude
@@ -1,5 +1,5 @@
-2e6eec0db55953fbfc36508c97ad1a8e *tests/data/fate/mov-composer-metadata.mov
-9497 tests/data/fate/mov-composer-metadata.mov
+5b04c9d342ab6b21efc99dbcf9421113 *tests/data/fate/mov-mp4-loci-no-altitude.mp4
+9565 tests/data/fate/mov-mp4-loci-no-altitude.mp4
 #tb 0: 1/44100
 #media_type 0: audio
 #codec_id 0: pcm_s16le
@@ -9,8 +9,5 @@
 0,       1024,       1024,     1024,     4096, 0x18390b96
 0,       2048,       2048,      157,      628, 0x4db5381d
 [FORMAT]
-TAG:major_brand=qt  
-TAG:minor_version=512
-TAG:compatible_brands=qt  
-TAG:composer=Bach
+TAG:location=-33.8568+151.2153+000.000/
 [/FORMAT]

-- 
To stop receiving notification emails like this one, please contact
[email protected].
_______________________________________________
ffmpeg-cvslog mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to