Last active
June 9, 2021 03:03
-
-
Save liangchaoboy/10e986628fc98eee817ad78e47d30759 to your computer and use it in GitHub Desktop.
转码耗时统计
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 获取转码使用耗时 | |
func getQn() { | |
fi, err := os.Open("/disk4/liangchao/202168_flv") | |
if err != nil { | |
fmt.Printf("Error: %s\n", err) | |
return | |
} | |
defer fi.Close() | |
br := bufio.NewReader(fi) | |
var qnliveS QnLive | |
for { | |
a, _, c := br.ReadLine() | |
if c == io.EOF { | |
break | |
} | |
err := json.Unmarshal(a, &qnliveS) | |
if err != nil { | |
fmt.Println(err) | |
} | |
tw, errt := time.Parse("2006-01-02T15:04:05Z07:00", qnliveS.EndTime) | |
if errt != nil { | |
fmt.Println(errt) | |
} | |
left := getLastTime(qnliveS.Resource) - tw.Unix() | |
fmt.Println(qnliveS.Objkey, getLastTime(qnliveS.Resource), left) | |
} | |
} | |
//QnLive struct | |
type QnLive struct { | |
EndTime string `json:"end_time"` | |
Objkey string `json:"objkey"` | |
Resource string `json:"resource"` | |
StartTime string `json:"start_time"` | |
Status string `json:"status"` | |
Stream string `json:"stream"` | |
} | |
// 获取生成文件的 lastModified | |
func getLastTime(str string) int64 { | |
req, errReq := http.NewRequest("HEAD", str, nil) | |
c := &http.Client{} | |
if errReq != nil { | |
fmt.Println(errReq) | |
} | |
resp, err := c.Do(req) | |
if err != nil { | |
fmt.Println(err) | |
} | |
v := resp.Header.Get("Last-Modified") | |
tm2, err2 := time.Parse("Mon, 02 Jan 2006 15:04:05 GMT", v) | |
if err2 != nil { | |
fmt.Println(err2) | |
} | |
return tm2.Unix() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment