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) + } +}