Skip to content

Commit

Permalink
testing
Browse files Browse the repository at this point in the history
  • Loading branch information
deepch committed Jan 10, 2024
1 parent 385d9cc commit 4df258b
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 19 deletions.
14 changes: 14 additions & 0 deletions av/pktque/filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,20 @@ func (self *AVSync) check(i int) (start time.Duration, end time.Duration, correc
return
}

type CalcDuration struct {
LastTime map[int8]time.Duration
}

func (self *CalcDuration) ModifyPacket(pkt *av.Packet, streams []av.CodecData, videoidx int, audioidx int) (drop bool, err error) {
if tmp, ok := self.LastTime[pkt.Idx]; ok && tmp != 0 {
pkt.Duration = pkt.Time - self.LastTime[pkt.Idx]
} else if pkt.Time < 100*time.Millisecond {
pkt.Duration = pkt.Time
}
self.LastTime[pkt.Idx] = pkt.Time
return
}

// Make packets reading speed as same as walltime, effect like ffmpeg -re option.
type Walltime struct {
firsttime time.Time
Expand Down
49 changes: 30 additions & 19 deletions format/nvr/muxer.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,27 @@ import (
)

var MIME = []byte{11, 22, 111, 222, 11, 22, 111, 222}
var listTag = []string{"{host_name}", "{stream_name}", "{channel_name}", "{stream_id}", "{channel_id}", "{start_year}", "{start_month}", "{start_day}", "{start_minute}", "{start_second}", "{start_millisecond}", "{start_unix_second}", "{start_unix_millisecond}", "{start_time}", "{start_pts}", "{end_year}", "{end_month}", "{end_day}", "{end_minute}", "{end_second}", "{end_millisecond}", "{start_unix_second}", "{start_unix_millisecond}", "{end_time}", "{end_pts}", "{duration_second}", "{duration_millisecond}"}
var listTag = []string{"{server_id}", "{hostname_short}", "{hostname_long}", "{stream_name}", "{channel_name}", "{stream_id}", "{channel_id}", "{start_year}", "{start_month}", "{start_day}", "{start_minute}", "{start_second}", "{start_millisecond}", "{start_unix_second}", "{start_unix_millisecond}", "{start_time}", "{start_pts}", "{end_year}", "{end_month}", "{end_day}", "{end_minute}", "{end_second}", "{end_millisecond}", "{start_unix_second}", "{start_unix_millisecond}", "{end_time}", "{end_pts}", "{duration_second}", "{duration_millisecond}"}

const (
MP4 = "mp4"
NVR = "nvr"
)

type Muxer struct {
muxer *mp4.Muxer
format string
limit int
d *os.File
m *os.File
dur time.Duration
h int
gof *Gof
patch string
start, end time.Time
pstart, pend time.Duration
started bool
hostName, streamName, channelName, streamID, channelID string
muxer *mp4.Muxer
format string
limit int
d *os.File
m *os.File
dur time.Duration
h int
gof *Gof
patch string
start, end time.Time
pstart, pend time.Duration
started bool
serverID, streamName, channelName, streamID, channelID, hostname string
}

type Gof struct {
Expand Down Expand Up @@ -64,18 +64,20 @@ func init() {

}

func NewMuxer(hostName, streamName, channelName, streamID, channelID, patch string, format string, limit int) (m *Muxer, err error) {
func NewMuxer(serverID, streamName, channelName, streamID, channelID, patch string, format string, limit int) (m *Muxer, err error) {
hostname, _ := os.Hostname()
m = &Muxer{
patch: patch,
h: -1,
gof: &Gof{},
format: format,
limit: limit,
hostName: hostName,
serverID: serverID,
streamName: streamName,
channelName: channelName,
streamID: streamID,
channelID: channelID,
hostname: hostname,
}
return
}
Expand Down Expand Up @@ -186,7 +188,12 @@ func (m *Muxer) OpenNVR() (err error) {
func (m *Muxer) OpenMP4() (err error) {
m.WriteTrailer()
m.start = time.Now().UTC()
if m.d, err = os.CreateTemp("", "rtspvideo.*.mp4"); err != nil {

p := m.filePatch()
if err = os.MkdirAll(filepath.Dir(p), 0755); err != nil {
return
}
if m.d, err = os.Create(filepath.Dir(p) + "/tmp.mp4"); err != nil {
return
}
m.muxer = mp4.NewMuxer(m.d)
Expand All @@ -202,8 +209,12 @@ func (m *Muxer) filePatch() string {
m.end = time.Now().UTC()
for _, s := range listTag {
switch s {
case "{host_name}":
ts = strings.Replace(ts, "{host_name}", m.hostName, -1)
case "{server_id}":
ts = strings.Replace(ts, "{host_name}", m.serverID, -1)
case "{hostname_short}":
ts = strings.Replace(ts, "{host_name}", m.hostname, -1)
case "{hostname_long}":
ts = strings.Replace(ts, "{host_name}", m.hostname, -1)
case "{stream_name}":
ts = strings.Replace(ts, "{stream_name}", m.streamName, -1)
case "{channel_name}":
Expand Down

0 comments on commit 4df258b

Please sign in to comment.