]> git.tuebingen.mpg.de Git - paraslash.git/blobdiff - mp4.c
mp4: Introduce mp4ff_get_duration().
[paraslash.git] / mp4.c
diff --git a/mp4.c b/mp4.c
index 548f78ec391e95f892fdba61cf2140db25a473d0..46aec2db6cf42ab50ecb2d99aef2bd0c7b4181f8 100644 (file)
--- a/mp4.c
+++ b/mp4.c
@@ -765,7 +765,6 @@ static int32_t tag_add_field(struct mp4ff_metadata *tags, const char *item,
 {
        if (!item || (item && !*item) || !value)
                return 0;
-
        tags->tags = para_realloc(tags->tags,
                (tags->count + 1) * sizeof(struct mp4ff_tag));
        tags->tags[tags->count].item = para_strdup(item);
@@ -1408,6 +1407,24 @@ static int32_t sample_to_offset(const struct mp4ff *f, int32_t track,
        return chunk_offset2;
 }
 
+/**
+ * Return the number of milliseconds of the given track.
+ *
+ * \param f As returned by \ref mp4ff_open_read(), must not be NULL.
+ * \param track Between zero and the value returned by \ref mp4ff_total_tracks().
+ *
+ * The function returns zero if the audio file is of zero length or contains a
+ * corrupt track header.
+ */
+uint64_t mp4ff_get_duration(const struct mp4ff *f, int32_t track)
+{
+       const struct mp4ff_track *t = f->track[track];
+
+       if (t->timeScale == 0)
+               return 0;
+       return t->duration * 1000 / t->timeScale;
+}
+
 void mp4ff_set_sample_position(struct mp4ff *f, int32_t track, int32_t sample)
 {
        int32_t offset = sample_to_offset(f, track, sample);