mirror of
https://github.com/krau/SaveAny-Bot.git
synced 2026-07-09 22:41:55 +08:00
feat: add MP4 metadata extraction and integrate gomedia for video handling
This commit is contained in:
36
storage/telegram/util.go
Normal file
36
storage/telegram/util.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package telegram
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/yapingcat/gomedia/go-mp4"
|
||||
)
|
||||
|
||||
type MP4Info struct {
|
||||
Duration int
|
||||
Width int
|
||||
Height int
|
||||
}
|
||||
|
||||
func getMP4Info(r io.ReadSeeker) (*MP4Info, error) {
|
||||
d := mp4.CreateMp4Demuxer(r)
|
||||
|
||||
tracks, err := d.ReadHead()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, track := range tracks {
|
||||
if track.Cid == mp4.MP4_CODEC_H264 {
|
||||
info := d.GetMp4Info()
|
||||
return &MP4Info{
|
||||
Duration: int(info.Duration / info.Timescale),
|
||||
Width: int(track.Width),
|
||||
Height: int(track.Height),
|
||||
}, nil
|
||||
}
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("no h264 track found")
|
||||
}
|
||||
Reference in New Issue
Block a user