new time conversion of timestamp fields

This commit is contained in:
Martin Riedl 2024-10-17 18:12:50 +02:00
parent 2ccceedda9
commit 99266c3834
Signed by: martinr92
GPG key ID: FB68DA65516A804C
2 changed files with 30 additions and 8 deletions

21
DateTime.go Normal file
View file

@ -0,0 +1,21 @@
// Copyright 2024 Martin Riedl
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package gomp4
import "time"
func since1904ToTime(sec int64) time.Time {
return time.Date(1904, time.January, 1, 0, 0, 0, 0, time.UTC).Add(time.Second * time.Duration(sec))
}

View file

@ -16,6 +16,7 @@ package gomp4
import ( import (
"encoding/binary" "encoding/binary"
"time"
) )
// MovieHeaderBox Movie Header Box struct // MovieHeaderBox Movie Header Box struct
@ -32,16 +33,16 @@ type MovieHeaderBox struct {
*FullBox *FullBox
// is an integer that declares the creation time of the presentation (in seconds // is an integer that declares the creation time of the presentation (in seconds
// since midnight, Jan. 1, 1904, in UTC time) // since midnight, Jan. 1, 1904, in UTC time)
CreationTimeV0 uint32 CreationTimeV0 time.Time
// is an integer that declares the creation time of the presentation (in seconds // is an integer that declares the creation time of the presentation (in seconds
// since midnight, Jan. 1, 1904, in UTC time) // since midnight, Jan. 1, 1904, in UTC time)
CreationTimeV1 uint64 CreationTimeV1 time.Time
// is an integer that declares the most recent time the presentation was // is an integer that declares the most recent time the presentation was
// modified (in seconds since midnight, Jan. 1, 1904, in UTC time) // modified (in seconds since midnight, Jan. 1, 1904, in UTC time)
ModificationTimeV0 uint32 ModificationTimeV0 time.Time
// is an integer that declares the most recent time the presentation was // is an integer that declares the most recent time the presentation was
// modified (in seconds since midnight, Jan. 1, 1904, in UTC time) // modified (in seconds since midnight, Jan. 1, 1904, in UTC time)
ModificationTimeV1 uint64 ModificationTimeV1 time.Time
// is an integer that specifies the timescale for the entire presentation; this is the // is an integer that specifies the timescale for the entire presentation; this is the
// number of time units that pass in one second. For example, a time coordinate system that // number of time units that pass in one second. For example, a time coordinate system that
// measures time in sixtieths of a second has a time scale of 60. // measures time in sixtieths of a second has a time scale of 60.
@ -81,14 +82,14 @@ func ParseMovieHeaderBox(filePosition uint64, headerSize uint32, content []byte)
position := 4 position := 4
if box.Version == 1 { if box.Version == 1 {
box.CreationTimeV1 = binary.BigEndian.Uint64(content[4:12]) box.CreationTimeV1 = since1904ToTime(int64(binary.BigEndian.Uint64(content[4:12])))
box.ModificationTimeV1 = binary.BigEndian.Uint64(content[12:20]) box.ModificationTimeV1 = since1904ToTime(int64(binary.BigEndian.Uint64(content[12:20])))
box.Timescale = binary.BigEndian.Uint32(content[20:24]) box.Timescale = binary.BigEndian.Uint32(content[20:24])
box.DurationV1 = binary.BigEndian.Uint64(content[24:32]) box.DurationV1 = binary.BigEndian.Uint64(content[24:32])
position += 28 position += 28
} else { // version == 0 } else { // version == 0
box.CreationTimeV0 = binary.BigEndian.Uint32(content[4:8]) box.CreationTimeV0 = since1904ToTime(int64(binary.BigEndian.Uint32(content[4:8])))
box.ModificationTimeV0 = binary.BigEndian.Uint32(content[8:12]) box.ModificationTimeV0 = since1904ToTime(int64(binary.BigEndian.Uint32(content[8:12])))
box.Timescale = binary.BigEndian.Uint32(content[12:16]) box.Timescale = binary.BigEndian.Uint32(content[12:16])
box.DurationV0 = binary.BigEndian.Uint32(content[16:20]) box.DurationV0 = binary.BigEndian.Uint32(content[16:20])
position += 16 position += 16