init
This commit is contained in:
commit
30fae5b7ee
27
license
Normal file
27
license
Normal file
@ -0,0 +1,27 @@
|
||||
Copyright (c) 2016, stephen mcquay
|
||||
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
* Neither the name of smcquay nor the names of its contributors
|
||||
may be used to endorse or promote products derived from this software
|
||||
without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
60
mov.go
Normal file
60
mov.go
Normal file
@ -0,0 +1,60 @@
|
||||
package mov
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"os"
|
||||
"time"
|
||||
)
|
||||
|
||||
const epochAdjust = 2082844800
|
||||
|
||||
// Created attempts to find a created time from the metadata in a .mov file.
|
||||
func Created(path string) (time.Time, error) {
|
||||
var r time.Time
|
||||
f, err := os.Open(path)
|
||||
if err != nil {
|
||||
return r, err
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
buf := [8]byte{}
|
||||
for {
|
||||
_, err := f.Read(buf[:])
|
||||
if err != nil {
|
||||
return r, err
|
||||
}
|
||||
if bytes.Equal(buf[4:8], []byte("moov")) {
|
||||
break
|
||||
} else {
|
||||
atomSize := binary.BigEndian.Uint32(buf[:])
|
||||
f.Seek(int64(atomSize)-8, 1)
|
||||
}
|
||||
}
|
||||
|
||||
_, err = f.Read(buf[:])
|
||||
if err != nil {
|
||||
return r, err
|
||||
}
|
||||
|
||||
s := string(buf[4:8])
|
||||
switch s {
|
||||
case "mvhd":
|
||||
if _, err := f.Seek(4, 1); err != nil {
|
||||
return r, err
|
||||
}
|
||||
_, err = f.Read(buf[:4])
|
||||
if err != nil {
|
||||
return r, err
|
||||
}
|
||||
i := int64(binary.BigEndian.Uint32(buf[:4]))
|
||||
c := i - epochAdjust
|
||||
u := time.Unix(c, 0).Local()
|
||||
return u, nil
|
||||
case "cmov":
|
||||
return r, errors.New("moov atom is compressed")
|
||||
default:
|
||||
return r, errors.New("expected to find 'mvhd' header, didn't")
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user