@@ -2,14 +2,15 @@ package vb_export
22
33import (
44 "fmt"
5+ "strings"
6+
57 "github.com/bcc-code/bcc-media-flows/activities"
68 "github.com/bcc-code/bcc-media-flows/common"
79 "github.com/bcc-code/bcc-media-flows/services/rclone"
810 "github.com/bcc-code/bcc-media-flows/services/telegram"
911 "github.com/bcc-code/bcc-media-flows/utils"
1012 wfutils "github.com/bcc-code/bcc-media-flows/utils/workflows"
1113 "go.temporal.io/sdk/workflow"
12- "strings"
1314)
1415
1516/*
@@ -44,6 +45,10 @@ func VBExportToAbekas(ctx workflow.Context, params VBExportChildWorkflowParams)
4445 return nil , err
4546 }
4647
48+ if len (analyzeResult .VideoStreams ) == 0 && len (analyzeResult .AudioStreams ) > 0 {
49+ return VBExportToAbekasAudioOnly (ctx , params )
50+ }
51+
4752 if analyzeResult .HasAlpha {
4853 rcloneDestination := deliveryFolder .Append ("Abekas-AVCI" , params .InputFile .Base ())
4954
@@ -123,3 +128,67 @@ func VBExportToAbekas(ctx workflow.Context, params VBExportChildWorkflowParams)
123128 ID : params .ParentParams .VXID ,
124129 }, nil
125130}
131+
132+ func VBExportToAbekasAudioOnly (ctx workflow.Context , params VBExportChildWorkflowParams ) (* VBExportResult , error ) {
133+ logger := workflow .GetLogger (ctx )
134+ logger .Info ("Starting audio-only export to Abekas" )
135+
136+ abekasOutputDir := params .TempDir .Append ("abekas_audio_output" )
137+ err := wfutils .CreateFolder (ctx , abekasOutputDir )
138+ if err != nil {
139+ return nil , err
140+ }
141+
142+ fileToTranscode := params .InputFile
143+
144+ // loudness normalization
145+ normalizedPath := abekasOutputDir .Append (params .InputFile .BaseNoExt () + "_normalized" + params .InputFile .Ext ())
146+
147+ normalizeResult , err := wfutils .Execute (ctx , activities .Audio .NormalizeAudioActivity ,
148+ activities.NormalizeAudioParams {
149+ FilePath : params .InputFile ,
150+ OutputPath : normalizedPath ,
151+ TargetLUFS : - 23.0 ,
152+ PerformOutputAnalysis : false ,
153+ }).Result (ctx )
154+
155+ if err != nil {
156+ return nil , err
157+ }
158+
159+ if ! normalizeResult .IsSilent && normalizeResult .FilePath .Local () != params .InputFile .Local () {
160+ fileToTranscode = normalizeResult .FilePath
161+ } else {
162+ logger .Info ("Audio normalization skipped" )
163+ }
164+
165+ // Convert to WAV PCM 48kHz 24bit
166+ transcodeInput := common.WavAudioInput {
167+ Path : fileToTranscode ,
168+ DestinationPath : abekasOutputDir ,
169+ }
170+
171+ var audioRes * common.AudioResult
172+ err = wfutils .Execute (ctx , activities .Audio .TranscodeToAudioWav , transcodeInput ).Get (ctx , & audioRes )
173+ if err != nil {
174+ return nil , err
175+ }
176+
177+ rcloneDestination := deliveryFolder .Append ("Abekas-WAV" , params .OriginalFilenameWithoutExt + ".wav" )
178+
179+ err = wfutils .RcloneWaitForFileGone (ctx , rcloneDestination , telegram .ChatOslofjord , 10 )
180+ if err != nil {
181+ return nil , err
182+ }
183+
184+ err = wfutils .RcloneCopyFileWithNotifications (ctx , audioRes .OutputPath , rcloneDestination , rclone .PriorityHigh , rcloneNotificationOptions )
185+ if err != nil {
186+ return nil , err
187+ }
188+
189+ notifyExportDone (ctx , params , "abekas" , audioRes .OutputPath )
190+
191+ return & VBExportResult {
192+ ID : params .ParentParams .VXID ,
193+ }, nil
194+ }
0 commit comments