From 02dfc7c291e210702c2fc49ca4703c6689037641 Mon Sep 17 00:00:00 2001 From: Gregory Ballantine Date: Wed, 31 Aug 2022 23:53:51 -0400 Subject: [PATCH] Finished the transcoding job --- adept.go | 2 +- transcoder/transcoder.go | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 transcoder/transcoder.go diff --git a/adept.go b/adept.go index 6ea06a0..9403105 100644 --- a/adept.go +++ b/adept.go @@ -17,7 +17,7 @@ func main() { // archive file r.ArchiveFile(i.Name()) // transcode file - // TODO - t.Transcode(i.Name()) + transcoder.Transcode(i.Name()) // clean up source file r.CleanupFile(i.Name()) } diff --git a/transcoder/transcoder.go b/transcoder/transcoder.go new file mode 100644 index 0000000..a1f37af --- /dev/null +++ b/transcoder/transcoder.go @@ -0,0 +1,36 @@ +package transcoder + +import ( + "fmt" + "log" + "os" + "os/exec" + "path/filepath" + + "github.com/spf13/viper" +) + +func Transcode(inFile string) { + // create ingest and archive paths + ingestPath := filepath.Join(viper.GetString("transcoder.repository"), "ingest", inFile) + outputPath := filepath.Join(viper.GetString("transcoder.repository"), "output", inFile) + + log.Printf("Transcoding video file %s.", ingestPath) + + cmd := exec.Command("/usr/bin/ffmpeg", + "-i", ingestPath, + "-y", + "-f", viper.GetString("transcoder.video_format"), + "-c:v", viper.GetString("transcoder.video_codec"), + "-s", viper.GetString("transcoder.video_resolution"), + "-r", viper.GetString("transcoder.video_framerate"), + "-vf", fmt.Sprintf("format=%s", viper.GetString("transcoder.video_color")), + "-profile:v", viper.GetString("transcoder.video_profile"), + "-c:a", viper.GetString("transcoder.audio_codec"), + outputPath) + + if err := cmd.Run(); err != nil { + log.Fatalf("Error while transcoding: %s.", err) + os.Exit(1) + } +}