Compare commits
	
		
			3 Commits
		
	
	
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|   | 4b060bc442 | ||
|   | 9f075c6682 | ||
|   | 0e06666006 | 
| @@ -20,7 +20,13 @@ import ( | ||||
| ) | ||||
|  | ||||
| var MIME = []byte{11, 22, 111, 222, 11, 22, 111, 222} | ||||
| var listTag = []string{"{server_id}", "{host_name}", "{host_name_short}", "{host_name_long}", "{stream_name}", "{channel_name}", "{stream_id}", "{channel_id}", "{start_year}", "{start_month}", "{start_day}", "{start_hour}", "{start_minute}", "{start_second}", "{start_millisecond}", "{start_unix_second}", "{start_unix_millisecond}", "{start_time}", "{start_pts}", "{end_year}", "{end_month}", "{end_day}", "{end_hour}", "{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}", "{host_name}", "{host_name_short}", "{host_name_long}", | ||||
| 	"{stream_name}", "{channel_name}", "{stream_id}", "{channel_id}", | ||||
| 	"{start_year}", "{start_month}", "{start_day}", "{start_hour}", "{start_minute}", "{start_second}", | ||||
| 	"{start_millisecond}", "{start_unix_second}", "{start_unix_millisecond}", "{start_time}", "{start_pts}", | ||||
| 	"{end_year}", "{end_month}", "{end_day}", "{end_hour}", "{end_minute}", "{end_second}", | ||||
| 	"{end_millisecond}", "{end_unix_millisecond}", "{end_unix_second}", "{end_time}", "{end_pts}", "{duration_second}", "{duration_millisecond}"} | ||||
|  | ||||
| const ( | ||||
| 	MP4 = "mp4" | ||||
| @@ -28,20 +34,20 @@ const ( | ||||
| ) | ||||
|  | ||||
| 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 | ||||
| 	mpoint                                                           []string | ||||
| 	start, end                                                       time.Time | ||||
| 	pstart, pend                                                     time.Duration | ||||
| 	started                                                          bool | ||||
| 	serverID, streamName, channelName, streamID, channelID, hostname string | ||||
| 	muxer                                                                       *mp4.Muxer | ||||
| 	format                                                                      string | ||||
| 	limit                                                                       int | ||||
| 	d                                                                           *os.File | ||||
| 	m                                                                           *os.File | ||||
| 	dur                                                                         time.Duration | ||||
| 	h                                                                           int | ||||
| 	gof                                                                         *Gof | ||||
| 	patch                                                                       string | ||||
| 	mpoint                                                                      []string | ||||
| 	start, end                                                                  time.Time | ||||
| 	pstart, pend                                                                time.Duration | ||||
| 	started                                                                     bool | ||||
| 	serverID, streamName, channelName, streamID, channelID, hostLong, hostShort string | ||||
| } | ||||
|  | ||||
| type Gof struct { | ||||
| @@ -70,7 +76,11 @@ func init() { | ||||
| } | ||||
|  | ||||
| func NewMuxer(serverID, streamName, channelName, streamID, channelID string, mpoint []string, patch, format string, limit int) (m *Muxer, err error) { | ||||
| 	hostname, _ := os.Hostname() | ||||
| 	hostLong, _ := os.Hostname() | ||||
| 	var hostShort string | ||||
| 	if p, _, ok := strings.Cut(hostLong, "."); ok { | ||||
| 		hostShort = p | ||||
| 	} | ||||
| 	m = &Muxer{ | ||||
| 		mpoint:      mpoint, | ||||
| 		patch:       patch, | ||||
| @@ -83,7 +93,8 @@ func NewMuxer(serverID, streamName, channelName, streamID, channelID string, mpo | ||||
| 		channelName: channelName, | ||||
| 		streamID:    streamID, | ||||
| 		channelID:   channelID, | ||||
| 		hostname:    hostname, | ||||
| 		hostLong:    hostLong, | ||||
| 		hostShort:   hostShort, | ||||
| 	} | ||||
| 	return | ||||
| } | ||||
| @@ -247,11 +258,11 @@ func (m *Muxer) filePatch() (string, error) { | ||||
| 		case "{server_id}": | ||||
| 			ts = strings.Replace(ts, "{server_id}", m.serverID, -1) | ||||
| 		case "{host_name}": | ||||
| 			ts = strings.Replace(ts, "{host_name}", m.hostname, -1) | ||||
| 			ts = strings.Replace(ts, "{host_name}", m.hostLong, -1) | ||||
| 		case "{host_name_short}": | ||||
| 			ts = strings.Replace(ts, "{host_name_short}", m.hostname, -1) | ||||
| 			ts = strings.Replace(ts, "{host_name_short}", m.hostShort, -1) | ||||
| 		case "{host_name_long}": | ||||
| 			ts = strings.Replace(ts, "{host_name_long}", m.hostname, -1) | ||||
| 			ts = strings.Replace(ts, "{host_name_long}", m.hostLong, -1) | ||||
| 		case "{stream_name}": | ||||
| 			ts = strings.Replace(ts, "{stream_name}", m.streamName, -1) | ||||
| 		case "{channel_name}": | ||||
| @@ -263,21 +274,21 @@ func (m *Muxer) filePatch() (string, error) { | ||||
| 		case "{start_year}": | ||||
| 			ts = strings.Replace(ts, "{start_year}", fmt.Sprintf("%d", m.start.Year()), -1) | ||||
| 		case "{start_month}": | ||||
| 			ts = strings.Replace(ts, "{start_month}", fmt.Sprintf("%d", int(m.start.Month())), -1) | ||||
| 			ts = strings.Replace(ts, "{start_month}", fmt.Sprintf("%02d", int(m.start.Month())), -1) | ||||
| 		case "{start_day}": | ||||
| 			ts = strings.Replace(ts, "{start_day}", fmt.Sprintf("%d", m.start.Day()), -1) | ||||
| 			ts = strings.Replace(ts, "{start_day}", fmt.Sprintf("%02d", m.start.Day()), -1) | ||||
| 		case "{start_hour}": | ||||
| 			ts = strings.Replace(ts, "{start_hour}", fmt.Sprintf("%d", m.start.Hour()), -1) | ||||
| 			ts = strings.Replace(ts, "{start_hour}", fmt.Sprintf("%02d", m.start.Hour()), -1) | ||||
| 		case "{start_minute}": | ||||
| 			ts = strings.Replace(ts, "{start_minute}", fmt.Sprintf("%d", m.start.Minute()), -1) | ||||
| 			ts = strings.Replace(ts, "{start_minute}", fmt.Sprintf("%02d", m.start.Minute()), -1) | ||||
| 		case "{start_second}": | ||||
| 			ts = strings.Replace(ts, "{start_second}", fmt.Sprintf("%d", m.start.Second()), -1) | ||||
| 			ts = strings.Replace(ts, "{start_second}", fmt.Sprintf("%02d", m.start.Second()), -1) | ||||
| 		case "{start_millisecond}": | ||||
| 			ts = strings.Replace(ts, "{start_millisecond}", fmt.Sprintf("%d", m.start.Nanosecond()/1000/1000), -1) | ||||
| 		case "{start_unix_millisecond}": | ||||
| 			ts = strings.Replace(ts, "{start_unix_millisecond}", fmt.Sprintf("%d", m.end.UnixMilli()), -1) | ||||
| 			ts = strings.Replace(ts, "{start_unix_millisecond}", fmt.Sprintf("%d", m.start.UnixMilli()), -1) | ||||
| 		case "{start_unix_second}": | ||||
| 			ts = strings.Replace(ts, "{start_unix_second}", fmt.Sprintf("%d", m.end.Unix()), -1) | ||||
| 			ts = strings.Replace(ts, "{start_unix_second}", fmt.Sprintf("%d", m.start.Unix()), -1) | ||||
| 		case "{start_time}": | ||||
| 			ts = strings.Replace(ts, "{start_time}", fmt.Sprintf("%s", m.start.Format("2006-01-02T15:04:05-0700")), -1) | ||||
| 		case "{start_pts}": | ||||
| @@ -285,17 +296,17 @@ func (m *Muxer) filePatch() (string, error) { | ||||
| 		case "{end_year}": | ||||
| 			ts = strings.Replace(ts, "{end_year}", fmt.Sprintf("%d", m.end.Year()), -1) | ||||
| 		case "{end_month}": | ||||
| 			ts = strings.Replace(ts, "{end_month}", fmt.Sprintf("%d", int(m.end.Month())), -1) | ||||
| 			ts = strings.Replace(ts, "{end_month}", fmt.Sprintf("%02d", int(m.end.Month())), -1) | ||||
| 		case "{end_day}": | ||||
| 			ts = strings.Replace(ts, "{end_day}", fmt.Sprintf("%d", m.end.Day()), -1) | ||||
| 			ts = strings.Replace(ts, "{end_day}", fmt.Sprintf("%02d", m.end.Day()), -1) | ||||
| 		case "{end_hour}": | ||||
| 			ts = strings.Replace(ts, "{end_hour}", fmt.Sprintf("%d", m.end.Hour()), -1) | ||||
| 			ts = strings.Replace(ts, "{end_hour}", fmt.Sprintf("%02d", m.end.Hour()), -1) | ||||
| 		case "{end_minute}": | ||||
| 			ts = strings.Replace(ts, "{end_minute}", fmt.Sprintf("%d", m.end.Minute()), -1) | ||||
| 			ts = strings.Replace(ts, "{end_minute}", fmt.Sprintf("%02d", m.end.Minute()), -1) | ||||
| 		case "{end_second}": | ||||
| 			ts = strings.Replace(ts, "{end_second}", fmt.Sprintf("%d", m.end.Second()), -1) | ||||
| 			ts = strings.Replace(ts, "{end_second}", fmt.Sprintf("%02d", m.end.Second()), -1) | ||||
| 		case "{end_millisecond}": | ||||
| 			ts = strings.Replace(ts, "{end_millisecond}", fmt.Sprintf("%d", m.start.Nanosecond()/1000/1000), -1) | ||||
| 			ts = strings.Replace(ts, "{end_millisecond}", fmt.Sprintf("%d", m.end.Nanosecond()/1000/1000), -1) | ||||
| 		case "{end_unix_millisecond}": | ||||
| 			ts = strings.Replace(ts, "{end_unix_millisecond}", fmt.Sprintf("%d", m.end.UnixMilli()), -1) | ||||
| 		case "{end_unix_second}": | ||||
|   | ||||
		Reference in New Issue
	
	Block a user