Transcode Task Handling
This commit is contained in:
parent
fea955fb79
commit
13ea1cb755
6 changed files with 164 additions and 20 deletions
79
task/transcode.go
Normal file
79
task/transcode.go
Normal file
|
@ -0,0 +1,79 @@
|
|||
package task
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"git.lastassault.de/speatzle/morffix/config"
|
||||
"git.lastassault.de/speatzle/morffix/constants"
|
||||
"git.lastassault.de/speatzle/morffix/task/log"
|
||||
"git.lastassault.de/speatzle/morffix/types"
|
||||
)
|
||||
|
||||
func RunTranscode(conf config.Config, t *types.Task, data types.TranscodeData) {
|
||||
ctx := context.TODO()
|
||||
l := log.GetTaskLogger(t)
|
||||
|
||||
// TODO Figure out how to get correct file ending
|
||||
src_path := filepath.Join(conf.Worker.TempDir, fmt.Sprintf("src-%v-%v.mkv", t.ID, t.FileID))
|
||||
dst_path := filepath.Join(conf.Worker.TempDir, fmt.Sprintf("dst-%v-%v.mkv", t.ID, t.FileID))
|
||||
|
||||
// Set ffmpeg input path
|
||||
if len(data.Command.InputFiles) == 0 {
|
||||
l.ErrorContext(ctx, "FFmpeg Command has no input files")
|
||||
return
|
||||
}
|
||||
|
||||
data.Command.InputFiles[0].Path = src_path
|
||||
|
||||
// Set ffmpeg output path
|
||||
if len(data.Command.OutputFiles) == 0 {
|
||||
l.ErrorContext(ctx, "FFmpeg Command has no output files")
|
||||
return
|
||||
}
|
||||
|
||||
data.Command.OutputFiles[0].Path = dst_path
|
||||
|
||||
// TODO cleanup file when done
|
||||
defer func() {
|
||||
err := os.Remove(src_path)
|
||||
if err != nil {
|
||||
l.ErrorContext(ctx, "Removing Source File", "err", err, "path", src_path)
|
||||
} else {
|
||||
l.InfoContext(ctx, "Source File Removed Succesfully", "path", src_path)
|
||||
}
|
||||
}()
|
||||
|
||||
err := downloadFile(ctx, l, conf.Worker.Address, src_path, t)
|
||||
if err != nil {
|
||||
l.ErrorContext(ctx, "Source File Download Failed", "err", err)
|
||||
return
|
||||
}
|
||||
|
||||
// TODO cleanup file when done
|
||||
defer func() {
|
||||
err := os.Remove(dst_path)
|
||||
if err != nil {
|
||||
l.ErrorContext(ctx, "Removing Destination File", "err", err, "path", dst_path)
|
||||
} else {
|
||||
l.InfoContext(ctx, "File Destination Removed Succesfully", "path", dst_path)
|
||||
}
|
||||
}()
|
||||
|
||||
err = runFfmpegCommand(ctx, l, conf, data.Command)
|
||||
if err != nil {
|
||||
l.ErrorContext(ctx, "FFmpeg Failed", "err", err)
|
||||
return
|
||||
}
|
||||
|
||||
err = uploadFile(ctx, l, conf.Worker.Address, dst_path, t)
|
||||
if err != nil {
|
||||
l.ErrorContext(ctx, "File Upload Failed", "err", err)
|
||||
return
|
||||
}
|
||||
|
||||
l.InfoContext(ctx, "Task Success")
|
||||
t.Status = constants.TASK_STATUS_SUCCESS
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue