[FFmpeg-cvslog] Merge commit 'b84f3a40034d28828c4ca639d012479a7eaace28'

Clément Bœsch git at videolan.org
Fri Jun 24 11:08:27 CEST 2016


ffmpeg | branch: master | Clément Bœsch <clement at stupeflix.com> | Fri Jun 24 11:08:33 2016 +0200| [2c45254a773f22f1c3b80acae9e8619c22088047] | committer: Clément Bœsch

Merge commit 'b84f3a40034d28828c4ca639d012479a7eaace28'

* commit 'b84f3a40034d28828c4ca639d012479a7eaace28':
  movenc: Write 'loci' geotag metadata for 3gp and mp4

Merged-by: Clément Bœsch <clement at stupeflix.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=2c45254a773f22f1c3b80acae9e8619c22088047
---

 libavformat/movenc.c |   53 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 53 insertions(+)

diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index 4a6184e..bf57174 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -2964,6 +2964,57 @@ static int mov_write_tmpo_tag(AVIOContext *pb, AVFormatContext *s)
     return size;
 }
 
+/* 3GPP TS 26.244 */
+static int mov_write_loci_tag(AVFormatContext *s, AVIOContext *pb)
+{
+    int lang;
+    int64_t pos = avio_tell(pb);
+    double latitude, longitude, altitude;
+    int32_t latitude_fix, longitude_fix, altitude_fix;
+    AVDictionaryEntry *t = get_metadata_lang(s, "location", &lang);
+    const char *ptr, *place = "";
+    char *end;
+    const char *astronomical_body = "earth";
+    if (!t)
+        return 0;
+
+    ptr = t->value;
+    longitude = strtod(ptr, &end);
+    if (end == ptr) {
+        av_log(s, AV_LOG_WARNING, "malformed location metadata\n");
+        return 0;
+    }
+    ptr = end;
+    latitude = strtod(ptr, &end);
+    if (end == ptr) {
+        av_log(s, AV_LOG_WARNING, "malformed location metadata\n");
+        return 0;
+    }
+    ptr = end;
+    altitude = strtod(ptr, &end);
+    /* If no altitude was present, the default 0 should be fine */
+    if (*end == '/')
+        place = end + 1;
+
+    latitude_fix  = (int32_t) ((1 << 16) * latitude);
+    longitude_fix = (int32_t) ((1 << 16) * longitude);
+    altitude_fix  = (int32_t) ((1 << 16) * altitude);
+
+    avio_wb32(pb, 0);         /* size */
+    ffio_wfourcc(pb, "loci"); /* type */
+    avio_wb32(pb, 0);         /* version + flags */
+    avio_wb16(pb, lang);
+    avio_write(pb, place, strlen(place) + 1);
+    avio_w8(pb, 0);           /* role of place (0 == shooting location, 1 == real location, 2 == fictional location) */
+    avio_wb32(pb, latitude_fix);
+    avio_wb32(pb, longitude_fix);
+    avio_wb32(pb, altitude_fix);
+    avio_write(pb, astronomical_body, strlen(astronomical_body) + 1);
+    avio_w8(pb, 0);           /* additional notes, null terminated string */
+
+    return update_size(pb, pos);
+}
+
 /* iTunes track or disc number */
 static int mov_write_trkn_tag(AVIOContext *pb, MOVMuxContext *mov,
                               AVFormatContext *s, int disc)
@@ -3179,6 +3230,7 @@ static int mov_write_udta_tag(AVIOContext *pb, MOVMuxContext *mov,
         mov_write_3gp_udta_tag(pb_buf, s, "albm", "album");
         mov_write_3gp_udta_tag(pb_buf, s, "cprt", "copyright");
         mov_write_3gp_udta_tag(pb_buf, s, "yrrc", "date");
+        mov_write_loci_tag(s, pb_buf);
     } else if (mov->mode == MODE_MOV) { // the title field breaks gtkpod with mp4 and my suspicion is that stuff is not valid in mp4
         mov_write_string_metadata(s, pb_buf, "\251ART", "artist",      0);
         mov_write_string_metadata(s, pb_buf, "\251nam", "title",       0);
@@ -3199,6 +3251,7 @@ static int mov_write_udta_tag(AVIOContext *pb, MOVMuxContext *mov,
     } else {
         /* iTunes meta data */
         mov_write_meta_tag(pb_buf, mov, s);
+        mov_write_loci_tag(s, pb_buf);
     }
 
     if (s->nb_chapters && !(mov->flags & FF_MOV_FLAG_DISABLE_CHPL))


======================================================================

diff --cc libavformat/movenc.c
index 4a6184e,aadfa06..bf57174
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@@ -2946,39 -2040,66 +2946,90 @@@ static int mov_write_string_metadata(AV
      return mov_write_string_tag(pb, name, t->value, lang, long_style);
  }
  
 +/* iTunes bpm number */
 +static int mov_write_tmpo_tag(AVIOContext *pb, AVFormatContext *s)
 +{
 +    AVDictionaryEntry *t = av_dict_get(s->metadata, "tmpo", NULL, 0);
 +    int size = 0, tmpo = t ? atoi(t->value) : 0;
 +    if (tmpo) {
 +        size = 26;
 +        avio_wb32(pb, size);
 +        ffio_wfourcc(pb, "tmpo");
 +        avio_wb32(pb, size-8); /* size */
 +        ffio_wfourcc(pb, "data");
 +        avio_wb32(pb, 0x15);  //type specifier
 +        avio_wb32(pb, 0);
 +        avio_wb16(pb, tmpo);        // data
 +    }
 +    return size;
 +}
 +
+ /* 3GPP TS 26.244 */
+ static int mov_write_loci_tag(AVFormatContext *s, AVIOContext *pb)
+ {
+     int lang;
+     int64_t pos = avio_tell(pb);
+     double latitude, longitude, altitude;
+     int32_t latitude_fix, longitude_fix, altitude_fix;
+     AVDictionaryEntry *t = get_metadata_lang(s, "location", &lang);
+     const char *ptr, *place = "";
+     char *end;
+     const char *astronomical_body = "earth";
+     if (!t)
+         return 0;
+ 
+     ptr = t->value;
+     longitude = strtod(ptr, &end);
+     if (end == ptr) {
+         av_log(s, AV_LOG_WARNING, "malformed location metadata\n");
+         return 0;
+     }
+     ptr = end;
+     latitude = strtod(ptr, &end);
+     if (end == ptr) {
+         av_log(s, AV_LOG_WARNING, "malformed location metadata\n");
+         return 0;
+     }
+     ptr = end;
+     altitude = strtod(ptr, &end);
+     /* If no altitude was present, the default 0 should be fine */
+     if (*end == '/')
+         place = end + 1;
+ 
+     latitude_fix  = (int32_t) ((1 << 16) * latitude);
+     longitude_fix = (int32_t) ((1 << 16) * longitude);
+     altitude_fix  = (int32_t) ((1 << 16) * altitude);
+ 
+     avio_wb32(pb, 0);         /* size */
+     ffio_wfourcc(pb, "loci"); /* type */
+     avio_wb32(pb, 0);         /* version + flags */
+     avio_wb16(pb, lang);
+     avio_write(pb, place, strlen(place) + 1);
+     avio_w8(pb, 0);           /* role of place (0 == shooting location, 1 == real location, 2 == fictional location) */
+     avio_wb32(pb, latitude_fix);
+     avio_wb32(pb, longitude_fix);
+     avio_wb32(pb, altitude_fix);
+     avio_write(pb, astronomical_body, strlen(astronomical_body) + 1);
+     avio_w8(pb, 0);           /* additional notes, null terminated string */
+ 
+     return update_size(pb, pos);
+ }
+ 
 -/* iTunes track number */
 +/* iTunes track or disc number */
  static int mov_write_trkn_tag(AVIOContext *pb, MOVMuxContext *mov,
 -                              AVFormatContext *s)
 +                              AVFormatContext *s, int disc)
  {
 -    AVDictionaryEntry *t = av_dict_get(s->metadata, "track", NULL, 0);
 +    AVDictionaryEntry *t = av_dict_get(s->metadata,
 +                                       disc ? "disc" : "track",
 +                                       NULL, 0);
      int size = 0, track = t ? atoi(t->value) : 0;
      if (track) {
 +        int tracks = 0;
 +        char *slash = strchr(t->value, '/');
 +        if (slash)
 +            tracks = atoi(slash + 1);
          avio_wb32(pb, 32); /* size */
 -        ffio_wfourcc(pb, "trkn");
 +        ffio_wfourcc(pb, disc ? "disk" : "trkn");
          avio_wb32(pb, 24); /* size */
          ffio_wfourcc(pb, "data");
          avio_wb32(pb, 0);        // 8 bytes empty



More information about the ffmpeg-cvslog mailing list