aboutsummaryrefslogtreecommitdiffstats
path: root/core/metadata.cpp
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2018-07-10 20:03:26 +0200
committerGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2018-07-14 08:32:30 +0200
commit02ad18d4d8480985ca400613031b89340404ab55 (patch)
treec145bac78f5a2cb5206152d7011caa31566e385a /core/metadata.cpp
parent52cc51f9061f578932ede736ed591b36e69b8695 (diff)
downloadsubsurface-02ad18d4d8480985ca400613031b89340404ab55.tar.gz
Metadata: extract duration fom QuickTime/MP4-style containers
We want the duration of videos for two reasons: - To display the duration of the video in the profile plot. - To be able to determine which dive a video is closer to if the start is not during a dive. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'core/metadata.cpp')
-rw-r--r--core/metadata.cpp9
1 files changed, 9 insertions, 0 deletions
diff --git a/core/metadata.cpp b/core/metadata.cpp
index 2397cd44b..877205ad4 100644
--- a/core/metadata.cpp
+++ b/core/metadata.cpp
@@ -158,18 +158,26 @@ static bool parseMP4(QFile &f, metadata *metadata)
if (f.read(&data[0], atom_size) != static_cast<int>(atom_size))
break;
uint64_t timestamp = 0;
+ uint32_t timescale = 0;
+ uint64_t duration = 0;
// First byte is version. We know version 0 and 1
switch (data[0]) {
case 0:
timestamp = getBE<uint32_t>(&data[4]);
+ timescale = getBE<uint32_t>(&data[12]);
+ duration = getBE<uint32_t>(&data[16]);
break;
case 1:
timestamp = getBE<uint64_t>(&data[4]);
+ timescale = getBE<uint32_t>(&data[20]);
+ duration = getBE<uint64_t>(&data[24]);
break;
default:
// For unknown versions: ignore -> maybe we find a parseable "mdhd" atom later in this file
break;
}
+ if (timescale > 0)
+ metadata->duration.seconds = lrint((double)duration / timescale);
// Timestamp is given as seconds since midnight 1904/1/1. To be convertible to the UNIX epoch
// it must be larger than 2082844800.
if (timestamp >= 2082844800) {
@@ -194,6 +202,7 @@ static bool parseMP4(QFile &f, metadata *metadata)
extern "C" mediatype_t get_metadata(const char *filename_in, metadata *data)
{
data->timestamp = 0;
+ data->duration.seconds = 0;
data->latitude.udeg = 0;
data->longitude.udeg = 0;