Skip to content

Commit

Permalink
Merge pull request #204 from gaohan085/dev
Browse files Browse the repository at this point in the history
fix bug
  • Loading branch information
gaohan085 authored Mar 25, 2024
2 parents cff3e4a + 40b489e commit 064a4ed
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
38 changes: 34 additions & 4 deletions database/video-convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (v *VideoConvert) Create() error {
}

func (v *VideoConvert) Update() error {
return Db.Model(&VideoConvert{}).Where("play_source = ?", v.PlaySource).Updates(v).Error
return Db.Model(&VideoConvert{}).Where("play_source = ?", v.PlaySource).Updates(&v).Error
}

func (v *VideoConvert) UpdateStatus(s string) error {
Expand Down Expand Up @@ -173,12 +173,12 @@ func (v *VideoConvert) ConvertOnFFmpegServer(chInter chan<- int, chDone chan<- i
cmd.Stdin = strings.NewReader(script)
if err := cmd.Start(); err != nil {
chInter <- 0
v.Status = "converting"

v.PostVideoData()
return err
}

v.Status = "converting"
v.PostVideoData()

if err := cmd.Wait(); err != nil {
chInter <- 0
return err
Expand Down Expand Up @@ -241,3 +241,33 @@ func (v *VideoConvert) PostVideoData() {
req.Header.Set("Content-Type", "application/json")
http.DefaultClient.Do(req)
}

func (v *VideoConvert) UpdateDurationOnFFmpegServer() error { //DONE TEST
var script = fmt.Sprintf(`ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 -sexagesimal %s`, v.PlaySource)

cmd := exec.Command("bash")
cmd.Stdin = strings.NewReader(script)

stdout, err := cmd.StdoutPipe()
if err != nil {
return err
}

if err := cmd.Start(); err != nil {
return err
}

scanner := bufio.NewScanner(stdout)

for scanner.Scan() {
line := scanner.Text()
duration, err := lib.DurationInSeconds(line)
if err != nil {
return err
}

v.Duration = duration
}

return cmd.Wait()
}
2 changes: 1 addition & 1 deletion handlers/v2/post-to-convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func ConvertVideo(ctx *fiber.Ctx) error {

go func() error {
chDone, chInter := make(chan int, 1024), make(chan int, 1024)
if err := video.UpdateDuration(); err != nil {
if err := video.UpdateDurationOnFFmpegServer(); err != nil {
return err
}

Expand Down

0 comments on commit 064a4ed

Please sign in to comment.