mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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>
This commit is contained in:
parent
52cc51f906
commit
02ad18d4d8
2 changed files with 10 additions and 0 deletions
|
@ -158,18 +158,26 @@ static bool parseMP4(QFile &f, metadata *metadata)
|
||||||
if (f.read(&data[0], atom_size) != static_cast<int>(atom_size))
|
if (f.read(&data[0], atom_size) != static_cast<int>(atom_size))
|
||||||
break;
|
break;
|
||||||
uint64_t timestamp = 0;
|
uint64_t timestamp = 0;
|
||||||
|
uint32_t timescale = 0;
|
||||||
|
uint64_t duration = 0;
|
||||||
// First byte is version. We know version 0 and 1
|
// First byte is version. We know version 0 and 1
|
||||||
switch (data[0]) {
|
switch (data[0]) {
|
||||||
case 0:
|
case 0:
|
||||||
timestamp = getBE<uint32_t>(&data[4]);
|
timestamp = getBE<uint32_t>(&data[4]);
|
||||||
|
timescale = getBE<uint32_t>(&data[12]);
|
||||||
|
duration = getBE<uint32_t>(&data[16]);
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
timestamp = getBE<uint64_t>(&data[4]);
|
timestamp = getBE<uint64_t>(&data[4]);
|
||||||
|
timescale = getBE<uint32_t>(&data[20]);
|
||||||
|
duration = getBE<uint64_t>(&data[24]);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
// For unknown versions: ignore -> maybe we find a parseable "mdhd" atom later in this file
|
// For unknown versions: ignore -> maybe we find a parseable "mdhd" atom later in this file
|
||||||
break;
|
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
|
// Timestamp is given as seconds since midnight 1904/1/1. To be convertible to the UNIX epoch
|
||||||
// it must be larger than 2082844800.
|
// it must be larger than 2082844800.
|
||||||
if (timestamp >= 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)
|
extern "C" mediatype_t get_metadata(const char *filename_in, metadata *data)
|
||||||
{
|
{
|
||||||
data->timestamp = 0;
|
data->timestamp = 0;
|
||||||
|
data->duration.seconds = 0;
|
||||||
data->latitude.udeg = 0;
|
data->latitude.udeg = 0;
|
||||||
data->longitude.udeg = 0;
|
data->longitude.udeg = 0;
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
struct metadata {
|
struct metadata {
|
||||||
timestamp_t timestamp;
|
timestamp_t timestamp;
|
||||||
|
duration_t duration;
|
||||||
degrees_t latitude;
|
degrees_t latitude;
|
||||||
degrees_t longitude;
|
degrees_t longitude;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue