From 34e397853a65d57904ddf982d3b462dbef6a4e29 Mon Sep 17 00:00:00 2001 From: Matjaz Debelak Date: Fri, 8 Nov 2024 12:41:36 +0100 Subject: [PATCH] Fix audio previews for MU1/2 --- services/transcode/preview.go | 82 +++++++++++++++++++++--------- services/transcode/preview_test.go | 59 +++++++++++++++++++++ 2 files changed, 118 insertions(+), 23 deletions(-) create mode 100644 services/transcode/preview_test.go diff --git a/services/transcode/preview.go b/services/transcode/preview.go index c0d304ec..09cd1c0e 100644 --- a/services/transcode/preview.go +++ b/services/transcode/preview.go @@ -5,6 +5,7 @@ import ( "fmt" "os" "path/filepath" + "sort" "strings" bccmflows "github.com/bcc-code/bcc-media-flows" @@ -29,19 +30,14 @@ type AudioPreviewResult struct { var previewWatermarkPath = environment.GetIsilonPrefix() + "/system/graphics/LOGO_BTV_Preview_960-540.mov" -func AudioPreview(input PreviewInput, progressCallback ffmpeg.ProgressCallback) (*AudioPreviewResult, error) { - out := &AudioPreviewResult{} - - info, err := ffmpeg.ProbeFile(input.FilePath) - if err != nil { - return nil, err - } - - isMU1 := strings.Contains(input.FilePath, "_MU1") - isMU2 := strings.Contains(input.FilePath, "_MU2") +type audioPreviewData struct { + FFMPEGParams []string + LanguageMap map[string]string +} +func prepareAudioPreview(isMU1, isMU2 bool, fileInfo *ffmpeg.FFProbeResult, inputFile, outputDir string) (*audioPreviewData, error) { audioStreams := []ffmpeg.FFProbeStream{} - for _, stream := range info.Streams { + for _, stream := range fileInfo.Streams { if stream.CodecType == "audio" { audioStreams = append(audioStreams, stream) } @@ -54,59 +50,99 @@ func AudioPreview(input PreviewInput, progressCallback ffmpeg.ProgressCallback) if len(audioStreams) == 16 { if isMU1 { for i, l := range bccmflows.LanguagesByMU1 { - fileName := filepath.Join(input.OutputDir, fmt.Sprintf("%d.%s.aac", i, l.ISO6391)) + if l.MU1ChannelStart != i { + continue // skip duplicated languages + } + + fileName := filepath.Join(outputDir, fmt.Sprintf("%d.%s.aac", i, l.ISO6391)) if l.MU1ChannelCount == 1 { - audioMap = append(audioMap, "-map", fmt.Sprintf("[0:%d]", l.MU1ChannelStart), fileName) + filterParts = append(filterParts, fmt.Sprintf("[0:%d]acopy[a%d]", l.MU1ChannelStart, i)) } else { filterParts = append(filterParts, fmt.Sprintf("[0:%d][0:%d]amerge=inputs=2[a%d]", l.MU1ChannelStart, l.MU1ChannelStart+1, i)) - audioMap = append(audioMap, "-map", fmt.Sprintf("[a%d]", i), fileName) } + audioMap = append(audioMap, "-map", fmt.Sprintf("[a%d]", i), fileName) + fileMap[l.ISO6391] = fileName } } else if isMU2 { for i, l := range bccmflows.LanguagesByMU2 { - fileName := filepath.Join(input.OutputDir, fmt.Sprintf("%d.%s.aac", i, l.ISO6391)) + if l.MU2ChannelStart != i { + continue // skip duplicated languages + } + + fileName := filepath.Join(outputDir, fmt.Sprintf("%d.%s.aac", i, l.ISO6391)) if l.MU2ChannelCount == 1 { - audioMap = append(audioMap, "-map", fmt.Sprintf("[0:%d]", l.MU2ChannelStart), fileName) + filterParts = append(filterParts, fmt.Sprintf("[0:%d]acopy[a%d]", l.MU2ChannelStart, i)) } else { filterParts = append(filterParts, fmt.Sprintf("[0:%d][0:%d]amerge=inputs=2[a%d]", l.MU2ChannelStart, l.MU2ChannelStart+1, i)) - audioMap = append(audioMap, "-map", fmt.Sprintf("[a%d]", i), fileName) } + audioMap = append(audioMap, "-map", fmt.Sprintf("[a%d]", i), fileName) fileMap[l.ISO6391] = fileName } } else { - return nil, fmt.Errorf("Unknow format of audio channels. Not generating preview") + return nil, fmt.Errorf("unknown format of audio channels. Not generating preview") } } else if len(audioStreams) == 1 && audioStreams[0].Channels == 64 { for i, l := range bccmflows.LanguageBySoftron { - fileName := filepath.Join(input.OutputDir, fmt.Sprintf("%d.%s.aac", i, l.ISO6391)) + fileName := filepath.Join(outputDir, fmt.Sprintf("%d.%s.aac", i, l.ISO6391)) filterParts = append(filterParts, fmt.Sprintf("[0:%d]pan=stereo|c0=c%d|c1=c%d[a%d]", audioStreams[0].Index, l.SoftronStartCh, l.SoftronStartCh+1, i)) audioMap = append(audioMap, "-map", fmt.Sprintf("[a%d]", i), fileName) fileMap[l.ISO6391] = fileName } } else { - return out, nil + return nil, nil } - out.AudioTracks = fileMap + // This is here to stabilize the string for unit tests + sort.Strings(filterParts) args := []string{ - "-i", input.FilePath, + "-i", inputFile, "-c:a", "aac", "-b:a", "64k", "-ar", "44100", "-ac", "2", "-profile:a", "aac_low", "-filter_complex", strings.Join(filterParts, ";"), + "-y", } + args = append(args, audioMap...) - _, err = ffmpeg.Do(args, ffmpeg.ProbeResultToInfo(info), progressCallback) + return &audioPreviewData{ + LanguageMap: fileMap, + FFMPEGParams: args, + }, nil +} + +func AudioPreview(input PreviewInput, progressCallback ffmpeg.ProgressCallback) (*AudioPreviewResult, error) { + out := &AudioPreviewResult{} + + isMU1 := strings.Contains(input.FilePath, "_MU1") + isMU2 := strings.Contains(input.FilePath, "_MU2") + + info, err := ffmpeg.ProbeFile(input.FilePath) if err != nil { return nil, err } + previewData, err := prepareAudioPreview(isMU1, isMU2, info, input.FilePath, input.OutputDir) + if err != nil { + return nil, err + } + + if previewData == nil { + return out, nil + } + + _, err = ffmpeg.Do(previewData.FFMPEGParams, ffmpeg.ProbeResultToInfo(info), progressCallback) + if err != nil { + return nil, err + } + + out.AudioTracks = previewData.LanguageMap + return out, nil } diff --git a/services/transcode/preview_test.go b/services/transcode/preview_test.go new file mode 100644 index 00000000..7d866360 --- /dev/null +++ b/services/transcode/preview_test.go @@ -0,0 +1,59 @@ +package transcode + +import ( + "encoding/json" + "testing" + + "github.com/bcc-code/mediabank-bridge/log" + "github.com/rs/zerolog" + + "github.com/bcc-code/bcc-media-flows/services/ffmpeg" + "github.com/stretchr/testify/assert" +) + +const jData = `{"streams":[{"index":0,"codec_name":"mpeg2video","codec_long_name":"MPEG-2 video","profile":"4:2:2","codec_type":"video","codec_tag_string":"[0][0][0][0]","codec_tag":"0x0000","width":1920,"height":1080,"coded_width":0,"coded_height":0,"closed_captions":0,"film_grain":0,"has_b_frames":1,"sample_aspect_ratio":"1:1","display_aspect_ratio":"16:9","pix_fmt":"yuv422p","level":2,"color_space":"bt709","color_transfer":"bt709","color_primaries":"bt709","field_order":"tt","refs":1,"id":"","r_frame_rate":"25/1","avg_frame_rate":"25/1","time_base":"1/25","start_pts":0,"start_time":"0.000000","duration_ts":17041,"duration":"681.640000","bit_rate":"50000000","bits_per_raw_sample":"","nb_frames":"","channels":0,"channel_layout":"","disposition":{"default":0,"dub":0,"original":0,"comment":0,"lyrics":0,"karaoke":0,"forced":0,"hearing_impaired":0,"visual_impaired":0,"clean_effects":0,"attached_pic":0,"timed_thumbnails":0,"captions":0,"descriptions":0,"metadata":0,"dependent":0,"still_image":0},"tags":{"creation_time":"0001-01-01T00:00:00Z","language":"","handler_name":"","vendor_id":"","encoder":"","timecode":"","DURATION":""}},{"index":1,"codec_name":"pcm_s24le","codec_long_name":"PCM signed 24-bit little-endian","profile":"","codec_type":"audio","codec_tag_string":"[0][0][0][0]","codec_tag":"0x0000","width":0,"height":0,"coded_width":0,"coded_height":0,"closed_captions":0,"film_grain":0,"has_b_frames":0,"sample_aspect_ratio":"","display_aspect_ratio":"","pix_fmt":"","level":0,"color_space":"","color_transfer":"","color_primaries":"","field_order":"","refs":0,"id":"","r_frame_rate":"0/0","avg_frame_rate":"0/0","time_base":"1/48000","start_pts":0,"start_time":"0.000000","duration_ts":32718720,"duration":"681.640000","bit_rate":"1152000","bits_per_raw_sample":"24","nb_frames":"","channels":1,"channel_layout":"","disposition":{"default":0,"dub":0,"original":0,"comment":0,"lyrics":0,"karaoke":0,"forced":0,"hearing_impaired":0,"visual_impaired":0,"clean_effects":0,"attached_pic":0,"timed_thumbnails":0,"captions":0,"descriptions":0,"metadata":0,"dependent":0,"still_image":0},"tags":{"creation_time":"0001-01-01T00:00:00Z","language":"","handler_name":"","vendor_id":"","encoder":"","timecode":"","DURATION":""}},{"index":2,"codec_name":"pcm_s24le","codec_long_name":"PCM signed 24-bit little-endian","profile":"","codec_type":"audio","codec_tag_string":"[0][0][0][0]","codec_tag":"0x0000","width":0,"height":0,"coded_width":0,"coded_height":0,"closed_captions":0,"film_grain":0,"has_b_frames":0,"sample_aspect_ratio":"","display_aspect_ratio":"","pix_fmt":"","level":0,"color_space":"","color_transfer":"","color_primaries":"","field_order":"","refs":0,"id":"","r_frame_rate":"0/0","avg_frame_rate":"0/0","time_base":"1/48000","start_pts":0,"start_time":"0.000000","duration_ts":32718720,"duration":"681.640000","bit_rate":"1152000","bits_per_raw_sample":"24","nb_frames":"","channels":1,"channel_layout":"","disposition":{"default":0,"dub":0,"original":0,"comment":0,"lyrics":0,"karaoke":0,"forced":0,"hearing_impaired":0,"visual_impaired":0,"clean_effects":0,"attached_pic":0,"timed_thumbnails":0,"captions":0,"descriptions":0,"metadata":0,"dependent":0,"still_image":0},"tags":{"creation_time":"0001-01-01T00:00:00Z","language":"","handler_name":"","vendor_id":"","encoder":"","timecode":"","DURATION":""}},{"index":3,"codec_name":"pcm_s24le","codec_long_name":"PCM signed 24-bit little-endian","profile":"","codec_type":"audio","codec_tag_string":"[0][0][0][0]","codec_tag":"0x0000","width":0,"height":0,"coded_width":0,"coded_height":0,"closed_captions":0,"film_grain":0,"has_b_frames":0,"sample_aspect_ratio":"","display_aspect_ratio":"","pix_fmt":"","level":0,"color_space":"","color_transfer":"","color_primaries":"","field_order":"","refs":0,"id":"","r_frame_rate":"0/0","avg_frame_rate":"0/0","time_base":"1/48000","start_pts":0,"start_time":"0.000000","duration_ts":32718720,"duration":"681.640000","bit_rate":"1152000","bits_per_raw_sample":"24","nb_frames":"","channels":1,"channel_layout":"","disposition":{"default":0,"dub":0,"original":0,"comment":0,"lyrics":0,"karaoke":0,"forced":0,"hearing_impaired":0,"visual_impaired":0,"clean_effects":0,"attached_pic":0,"timed_thumbnails":0,"captions":0,"descriptions":0,"metadata":0,"dependent":0,"still_image":0},"tags":{"creation_time":"0001-01-01T00:00:00Z","language":"","handler_name":"","vendor_id":"","encoder":"","timecode":"","DURATION":""}},{"index":4,"codec_name":"pcm_s24le","codec_long_name":"PCM signed 24-bit little-endian","profile":"","codec_type":"audio","codec_tag_string":"[0][0][0][0]","codec_tag":"0x0000","width":0,"height":0,"coded_width":0,"coded_height":0,"closed_captions":0,"film_grain":0,"has_b_frames":0,"sample_aspect_ratio":"","display_aspect_ratio":"","pix_fmt":"","level":0,"color_space":"","color_transfer":"","color_primaries":"","field_order":"","refs":0,"id":"","r_frame_rate":"0/0","avg_frame_rate":"0/0","time_base":"1/48000","start_pts":0,"start_time":"0.000000","duration_ts":32718720,"duration":"681.640000","bit_rate":"1152000","bits_per_raw_sample":"24","nb_frames":"","channels":1,"channel_layout":"","disposition":{"default":0,"dub":0,"original":0,"comment":0,"lyrics":0,"karaoke":0,"forced":0,"hearing_impaired":0,"visual_impaired":0,"clean_effects":0,"attached_pic":0,"timed_thumbnails":0,"captions":0,"descriptions":0,"metadata":0,"dependent":0,"still_image":0},"tags":{"creation_time":"0001-01-01T00:00:00Z","language":"","handler_name":"","vendor_id":"","encoder":"","timecode":"","DURATION":""}},{"index":5,"codec_name":"pcm_s24le","codec_long_name":"PCM signed 24-bit little-endian","profile":"","codec_type":"audio","codec_tag_string":"[0][0][0][0]","codec_tag":"0x0000","width":0,"height":0,"coded_width":0,"coded_height":0,"closed_captions":0,"film_grain":0,"has_b_frames":0,"sample_aspect_ratio":"","display_aspect_ratio":"","pix_fmt":"","level":0,"color_space":"","color_transfer":"","color_primaries":"","field_order":"","refs":0,"id":"","r_frame_rate":"0/0","avg_frame_rate":"0/0","time_base":"1/48000","start_pts":0,"start_time":"0.000000","duration_ts":32718720,"duration":"681.640000","bit_rate":"1152000","bits_per_raw_sample":"24","nb_frames":"","channels":1,"channel_layout":"","disposition":{"default":0,"dub":0,"original":0,"comment":0,"lyrics":0,"karaoke":0,"forced":0,"hearing_impaired":0,"visual_impaired":0,"clean_effects":0,"attached_pic":0,"timed_thumbnails":0,"captions":0,"descriptions":0,"metadata":0,"dependent":0,"still_image":0},"tags":{"creation_time":"0001-01-01T00:00:00Z","language":"","handler_name":"","vendor_id":"","encoder":"","timecode":"","DURATION":""}},{"index":6,"codec_name":"pcm_s24le","codec_long_name":"PCM signed 24-bit little-endian","profile":"","codec_type":"audio","codec_tag_string":"[0][0][0][0]","codec_tag":"0x0000","width":0,"height":0,"coded_width":0,"coded_height":0,"closed_captions":0,"film_grain":0,"has_b_frames":0,"sample_aspect_ratio":"","display_aspect_ratio":"","pix_fmt":"","level":0,"color_space":"","color_transfer":"","color_primaries":"","field_order":"","refs":0,"id":"","r_frame_rate":"0/0","avg_frame_rate":"0/0","time_base":"1/48000","start_pts":0,"start_time":"0.000000","duration_ts":32718720,"duration":"681.640000","bit_rate":"1152000","bits_per_raw_sample":"24","nb_frames":"","channels":1,"channel_layout":"","disposition":{"default":0,"dub":0,"original":0,"comment":0,"lyrics":0,"karaoke":0,"forced":0,"hearing_impaired":0,"visual_impaired":0,"clean_effects":0,"attached_pic":0,"timed_thumbnails":0,"captions":0,"descriptions":0,"metadata":0,"dependent":0,"still_image":0},"tags":{"creation_time":"0001-01-01T00:00:00Z","language":"","handler_name":"","vendor_id":"","encoder":"","timecode":"","DURATION":""}},{"index":7,"codec_name":"pcm_s24le","codec_long_name":"PCM signed 24-bit little-endian","profile":"","codec_type":"audio","codec_tag_string":"[0][0][0][0]","codec_tag":"0x0000","width":0,"height":0,"coded_width":0,"coded_height":0,"closed_captions":0,"film_grain":0,"has_b_frames":0,"sample_aspect_ratio":"","display_aspect_ratio":"","pix_fmt":"","level":0,"color_space":"","color_transfer":"","color_primaries":"","field_order":"","refs":0,"id":"","r_frame_rate":"0/0","avg_frame_rate":"0/0","time_base":"1/48000","start_pts":0,"start_time":"0.000000","duration_ts":32718720,"duration":"681.640000","bit_rate":"1152000","bits_per_raw_sample":"24","nb_frames":"","channels":1,"channel_layout":"","disposition":{"default":0,"dub":0,"original":0,"comment":0,"lyrics":0,"karaoke":0,"forced":0,"hearing_impaired":0,"visual_impaired":0,"clean_effects":0,"attached_pic":0,"timed_thumbnails":0,"captions":0,"descriptions":0,"metadata":0,"dependent":0,"still_image":0},"tags":{"creation_time":"0001-01-01T00:00:00Z","language":"","handler_name":"","vendor_id":"","encoder":"","timecode":"","DURATION":""}},{"index":8,"codec_name":"pcm_s24le","codec_long_name":"PCM signed 24-bit little-endian","profile":"","codec_type":"audio","codec_tag_string":"[0][0][0][0]","codec_tag":"0x0000","width":0,"height":0,"coded_width":0,"coded_height":0,"closed_captions":0,"film_grain":0,"has_b_frames":0,"sample_aspect_ratio":"","display_aspect_ratio":"","pix_fmt":"","level":0,"color_space":"","color_transfer":"","color_primaries":"","field_order":"","refs":0,"id":"","r_frame_rate":"0/0","avg_frame_rate":"0/0","time_base":"1/48000","start_pts":0,"start_time":"0.000000","duration_ts":32718720,"duration":"681.640000","bit_rate":"1152000","bits_per_raw_sample":"24","nb_frames":"","channels":1,"channel_layout":"","disposition":{"default":0,"dub":0,"original":0,"comment":0,"lyrics":0,"karaoke":0,"forced":0,"hearing_impaired":0,"visual_impaired":0,"clean_effects":0,"attached_pic":0,"timed_thumbnails":0,"captions":0,"descriptions":0,"metadata":0,"dependent":0,"still_image":0},"tags":{"creation_time":"0001-01-01T00:00:00Z","language":"","handler_name":"","vendor_id":"","encoder":"","timecode":"","DURATION":""}},{"index":9,"codec_name":"pcm_s24le","codec_long_name":"PCM signed 24-bit little-endian","profile":"","codec_type":"audio","codec_tag_string":"[0][0][0][0]","codec_tag":"0x0000","width":0,"height":0,"coded_width":0,"coded_height":0,"closed_captions":0,"film_grain":0,"has_b_frames":0,"sample_aspect_ratio":"","display_aspect_ratio":"","pix_fmt":"","level":0,"color_space":"","color_transfer":"","color_primaries":"","field_order":"","refs":0,"id":"","r_frame_rate":"0/0","avg_frame_rate":"0/0","time_base":"1/48000","start_pts":0,"start_time":"0.000000","duration_ts":32718720,"duration":"681.640000","bit_rate":"1152000","bits_per_raw_sample":"24","nb_frames":"","channels":1,"channel_layout":"","disposition":{"default":0,"dub":0,"original":0,"comment":0,"lyrics":0,"karaoke":0,"forced":0,"hearing_impaired":0,"visual_impaired":0,"clean_effects":0,"attached_pic":0,"timed_thumbnails":0,"captions":0,"descriptions":0,"metadata":0,"dependent":0,"still_image":0},"tags":{"creation_time":"0001-01-01T00:00:00Z","language":"","handler_name":"","vendor_id":"","encoder":"","timecode":"","DURATION":""}},{"index":10,"codec_name":"pcm_s24le","codec_long_name":"PCM signed 24-bit little-endian","profile":"","codec_type":"audio","codec_tag_string":"[0][0][0][0]","codec_tag":"0x0000","width":0,"height":0,"coded_width":0,"coded_height":0,"closed_captions":0,"film_grain":0,"has_b_frames":0,"sample_aspect_ratio":"","display_aspect_ratio":"","pix_fmt":"","level":0,"color_space":"","color_transfer":"","color_primaries":"","field_order":"","refs":0,"id":"","r_frame_rate":"0/0","avg_frame_rate":"0/0","time_base":"1/48000","start_pts":0,"start_time":"0.000000","duration_ts":32718720,"duration":"681.640000","bit_rate":"1152000","bits_per_raw_sample":"24","nb_frames":"","channels":1,"channel_layout":"","disposition":{"default":0,"dub":0,"original":0,"comment":0,"lyrics":0,"karaoke":0,"forced":0,"hearing_impaired":0,"visual_impaired":0,"clean_effects":0,"attached_pic":0,"timed_thumbnails":0,"captions":0,"descriptions":0,"metadata":0,"dependent":0,"still_image":0},"tags":{"creation_time":"0001-01-01T00:00:00Z","language":"","handler_name":"","vendor_id":"","encoder":"","timecode":"","DURATION":""}},{"index":11,"codec_name":"pcm_s24le","codec_long_name":"PCM signed 24-bit little-endian","profile":"","codec_type":"audio","codec_tag_string":"[0][0][0][0]","codec_tag":"0x0000","width":0,"height":0,"coded_width":0,"coded_height":0,"closed_captions":0,"film_grain":0,"has_b_frames":0,"sample_aspect_ratio":"","display_aspect_ratio":"","pix_fmt":"","level":0,"color_space":"","color_transfer":"","color_primaries":"","field_order":"","refs":0,"id":"","r_frame_rate":"0/0","avg_frame_rate":"0/0","time_base":"1/48000","start_pts":0,"start_time":"0.000000","duration_ts":32718720,"duration":"681.640000","bit_rate":"1152000","bits_per_raw_sample":"24","nb_frames":"","channels":1,"channel_layout":"","disposition":{"default":0,"dub":0,"original":0,"comment":0,"lyrics":0,"karaoke":0,"forced":0,"hearing_impaired":0,"visual_impaired":0,"clean_effects":0,"attached_pic":0,"timed_thumbnails":0,"captions":0,"descriptions":0,"metadata":0,"dependent":0,"still_image":0},"tags":{"creation_time":"0001-01-01T00:00:00Z","language":"","handler_name":"","vendor_id":"","encoder":"","timecode":"","DURATION":""}},{"index":12,"codec_name":"pcm_s24le","codec_long_name":"PCM signed 24-bit little-endian","profile":"","codec_type":"audio","codec_tag_string":"[0][0][0][0]","codec_tag":"0x0000","width":0,"height":0,"coded_width":0,"coded_height":0,"closed_captions":0,"film_grain":0,"has_b_frames":0,"sample_aspect_ratio":"","display_aspect_ratio":"","pix_fmt":"","level":0,"color_space":"","color_transfer":"","color_primaries":"","field_order":"","refs":0,"id":"","r_frame_rate":"0/0","avg_frame_rate":"0/0","time_base":"1/48000","start_pts":0,"start_time":"0.000000","duration_ts":32718720,"duration":"681.640000","bit_rate":"1152000","bits_per_raw_sample":"24","nb_frames":"","channels":1,"channel_layout":"","disposition":{"default":0,"dub":0,"original":0,"comment":0,"lyrics":0,"karaoke":0,"forced":0,"hearing_impaired":0,"visual_impaired":0,"clean_effects":0,"attached_pic":0,"timed_thumbnails":0,"captions":0,"descriptions":0,"metadata":0,"dependent":0,"still_image":0},"tags":{"creation_time":"0001-01-01T00:00:00Z","language":"","handler_name":"","vendor_id":"","encoder":"","timecode":"","DURATION":""}},{"index":13,"codec_name":"pcm_s24le","codec_long_name":"PCM signed 24-bit little-endian","profile":"","codec_type":"audio","codec_tag_string":"[0][0][0][0]","codec_tag":"0x0000","width":0,"height":0,"coded_width":0,"coded_height":0,"closed_captions":0,"film_grain":0,"has_b_frames":0,"sample_aspect_ratio":"","display_aspect_ratio":"","pix_fmt":"","level":0,"color_space":"","color_transfer":"","color_primaries":"","field_order":"","refs":0,"id":"","r_frame_rate":"0/0","avg_frame_rate":"0/0","time_base":"1/48000","start_pts":0,"start_time":"0.000000","duration_ts":32718720,"duration":"681.640000","bit_rate":"1152000","bits_per_raw_sample":"24","nb_frames":"","channels":1,"channel_layout":"","disposition":{"default":0,"dub":0,"original":0,"comment":0,"lyrics":0,"karaoke":0,"forced":0,"hearing_impaired":0,"visual_impaired":0,"clean_effects":0,"attached_pic":0,"timed_thumbnails":0,"captions":0,"descriptions":0,"metadata":0,"dependent":0,"still_image":0},"tags":{"creation_time":"0001-01-01T00:00:00Z","language":"","handler_name":"","vendor_id":"","encoder":"","timecode":"","DURATION":""}},{"index":14,"codec_name":"pcm_s24le","codec_long_name":"PCM signed 24-bit little-endian","profile":"","codec_type":"audio","codec_tag_string":"[0][0][0][0]","codec_tag":"0x0000","width":0,"height":0,"coded_width":0,"coded_height":0,"closed_captions":0,"film_grain":0,"has_b_frames":0,"sample_aspect_ratio":"","display_aspect_ratio":"","pix_fmt":"","level":0,"color_space":"","color_transfer":"","color_primaries":"","field_order":"","refs":0,"id":"","r_frame_rate":"0/0","avg_frame_rate":"0/0","time_base":"1/48000","start_pts":0,"start_time":"0.000000","duration_ts":32718720,"duration":"681.640000","bit_rate":"1152000","bits_per_raw_sample":"24","nb_frames":"","channels":1,"channel_layout":"","disposition":{"default":0,"dub":0,"original":0,"comment":0,"lyrics":0,"karaoke":0,"forced":0,"hearing_impaired":0,"visual_impaired":0,"clean_effects":0,"attached_pic":0,"timed_thumbnails":0,"captions":0,"descriptions":0,"metadata":0,"dependent":0,"still_image":0},"tags":{"creation_time":"0001-01-01T00:00:00Z","language":"","handler_name":"","vendor_id":"","encoder":"","timecode":"","DURATION":""}},{"index":15,"codec_name":"pcm_s24le","codec_long_name":"PCM signed 24-bit little-endian","profile":"","codec_type":"audio","codec_tag_string":"[0][0][0][0]","codec_tag":"0x0000","width":0,"height":0,"coded_width":0,"coded_height":0,"closed_captions":0,"film_grain":0,"has_b_frames":0,"sample_aspect_ratio":"","display_aspect_ratio":"","pix_fmt":"","level":0,"color_space":"","color_transfer":"","color_primaries":"","field_order":"","refs":0,"id":"","r_frame_rate":"0/0","avg_frame_rate":"0/0","time_base":"1/48000","start_pts":0,"start_time":"0.000000","duration_ts":32718720,"duration":"681.640000","bit_rate":"1152000","bits_per_raw_sample":"24","nb_frames":"","channels":1,"channel_layout":"","disposition":{"default":0,"dub":0,"original":0,"comment":0,"lyrics":0,"karaoke":0,"forced":0,"hearing_impaired":0,"visual_impaired":0,"clean_effects":0,"attached_pic":0,"timed_thumbnails":0,"captions":0,"descriptions":0,"metadata":0,"dependent":0,"still_image":0},"tags":{"creation_time":"0001-01-01T00:00:00Z","language":"","handler_name":"","vendor_id":"","encoder":"","timecode":"","DURATION":""}},{"index":16,"codec_name":"pcm_s24le","codec_long_name":"PCM signed 24-bit little-endian","profile":"","codec_type":"audio","codec_tag_string":"[0][0][0][0]","codec_tag":"0x0000","width":0,"height":0,"coded_width":0,"coded_height":0,"closed_captions":0,"film_grain":0,"has_b_frames":0,"sample_aspect_ratio":"","display_aspect_ratio":"","pix_fmt":"","level":0,"color_space":"","color_transfer":"","color_primaries":"","field_order":"","refs":0,"id":"","r_frame_rate":"0/0","avg_frame_rate":"0/0","time_base":"1/48000","start_pts":0,"start_time":"0.000000","duration_ts":32718720,"duration":"681.640000","bit_rate":"1152000","bits_per_raw_sample":"24","nb_frames":"","channels":1,"channel_layout":"","disposition":{"default":0,"dub":0,"original":0,"comment":0,"lyrics":0,"karaoke":0,"forced":0,"hearing_impaired":0,"visual_impaired":0,"clean_effects":0,"attached_pic":0,"timed_thumbnails":0,"captions":0,"descriptions":0,"metadata":0,"dependent":0,"still_image":0},"tags":{"creation_time":"0001-01-01T00:00:00Z","language":"","handler_name":"","vendor_id":"","encoder":"","timecode":"","DURATION":""}}],"format":{"filename":"/path/filename.mxf","nb_streams":17,"nb_programs":0,"format_name":"mxf","format_long_name":"MXF (Material eXchange Format)","start_time":"0.000000","duration":"681.640000","size":"5950135135","bit_rate":"69833168","probe_score":100,"tags":{"major_brand":"","minor_version":"","compatible_brands":"","creation_time":""}}}` + +func Test_AudioAdioPreviewGenerator(t *testing.T) { + log.ConfigureGlobalLogger(zerolog.DebugLevel) + fileInfo := &ffmpeg.FFProbeResult{} + err := json.Unmarshal([]byte(jData), fileInfo) + assert.NoError(t, err) + + out, err := prepareAudioPreview(true, false, fileInfo, fileInfo.Format.Filename, "./temp/") + assert.NoError(t, err) + + assert.ElementsMatch(t, + []string{ + "-i", "/path/filename.mxf", + "-c:a", "aac", "-b:a", "64k", "-ar", "44100", "-ac", "2", "-profile:a", "aac_low", + "-filter_complex", "[0:10]acopy[a10];[0:11]acopy[a11];[0:12]acopy[a12];[0:13]acopy[a13];[0:14]acopy[a14];[0:15]acopy[a15];[0:16]acopy[a16];[0:1][0:2]amerge=inputs=2[a1];[0:3][0:4]amerge=inputs=2[a3];[0:5][0:6]amerge=inputs=2[a5];[0:7][0:8]amerge=inputs=2[a7];[0:9]acopy[a9]", + "-map", "[a7]", "temp/7.eng.aac", + "-map", "[a9]", "temp/9.fra.aac", + "-map", "[a10]", "temp/10.spa.aac", + "-map", "[a14]", "temp/14.ron.aac", + "-map", "[a12]", "temp/12.rus.aac", + "-map", "[a15]", "temp/15.tur.aac", + "-map", "[a16]", "temp/16.pol.aac", + "-map", "[a5]", "temp/5.nld.aac", + "-map", "[a3]", "temp/3.deu.aac", + "-map", "[a1]", "temp/1.nor.aac", + "-map", "[a11]", "temp/11.fin.aac", + "-map", "[a13]", "temp/13.por.aac", + "-y", + }, out.FFMPEGParams) + assert.Equal(t, map[string]string{ + "ron": "temp/14.ron.aac", + "nor": "temp/1.nor.aac", + "nld": "temp/5.nld.aac", + "rus": "temp/12.rus.aac", + "tur": "temp/15.tur.aac", + "pol": "temp/16.pol.aac", + "fin": "temp/11.fin.aac", + "fra": "temp/9.fra.aac", + "spa": "temp/10.spa.aac", + "deu": "temp/3.deu.aac", + "por": "temp/13.por.aac", + "eng": "temp/7.eng.aac", + }, out.LanguageMap) + +}