diff --git a/services/transcode/h264.go b/services/transcode/h264.go index 8f78e32a..8aa031fe 100644 --- a/services/transcode/h264.go +++ b/services/transcode/h264.go @@ -1,11 +1,12 @@ package transcode import ( - "github.com/bcc-code/bccm-flows/services/ffmpeg" "os" "path/filepath" "strconv" "strings" + + "github.com/bcc-code/bccm-flows/services/ffmpeg" ) type EncodeInput struct { @@ -14,6 +15,7 @@ type EncodeInput struct { Resolution string FrameRate int Bitrate string + Interlace bool } type EncodeResult struct { diff --git a/services/transcode/xdcam.go b/services/transcode/xdcam.go index f88acaf0..70acb9e1 100644 --- a/services/transcode/xdcam.go +++ b/services/transcode/xdcam.go @@ -1,17 +1,15 @@ package transcode import ( - "github.com/bcc-code/bccm-flows/services/ffmpeg" "os" "path/filepath" "strconv" "strings" -) -func XDCAM(input EncodeInput, progressCallback ffmpeg.ProgressCallback) (*EncodeResult, error) { - filename := filepath.Base(strings.TrimSuffix(input.FilePath, filepath.Ext(input.FilePath))) + ".mxf" - outputPath := filepath.Join(input.OutputDir, filename) + "github.com/bcc-code/bccm-flows/services/ffmpeg" +) +func generateFfmpegParamsForXDCAM(input EncodeInput, output string) []string { params := []string{ "-progress", "pipe:1", "-hide_banner", @@ -45,11 +43,27 @@ func XDCAM(input EncodeInput, progressCallback ffmpeg.ProgressCallback) (*Encode ) } + if input.Interlace { + params = append( + params, + "-flags", "+ilme+ildct", + "-vf", "setfield=tff,fieldorder=tff", + ) + } + params = append( params, - outputPath, + output, ) + return params +} + +func XDCAM(input EncodeInput, progressCallback ffmpeg.ProgressCallback) (*EncodeResult, error) { + filename := filepath.Base(strings.TrimSuffix(input.FilePath, filepath.Ext(input.FilePath))) + ".mxf" + outputPath := filepath.Join(input.OutputDir, filename) + params := generateFfmpegParamsForXDCAM(input, outputPath) + info, err := ffmpeg.GetStreamInfo(input.FilePath) if err != nil { return nil, err diff --git a/services/transcode/xdcam_test.go b/services/transcode/xdcam_test.go new file mode 100644 index 00000000..b439a564 --- /dev/null +++ b/services/transcode/xdcam_test.go @@ -0,0 +1,25 @@ +package transcode + +import ( + "strings" + "testing" + + "github.com/stretchr/testify/assert" +) + +func Test_GenerateFFmpegParamsForXDCAM(t *testing.T) { + const golden = `-progress pipe:1 -hide_banner -i something.mxf -c:v mpeg2video -pix_fmt yuv422p -color_primaries bt709 -color_trc bt709 -colorspace bt709 -y -b:v 50M -s 1920x1080 -r 25 -flags +ilme+ildct -vf setfield=tff,fieldorder=tff something/something.mxf` + + const root = "root/" + const outputPath = "something/something.mxf" + cmd := generateFfmpegParamsForXDCAM(EncodeInput{ + FilePath: "something.mxf", + OutputDir: "out/", + Resolution: "1920x1080", + FrameRate: 25, + Bitrate: "50M", + Interlace: true, + }, outputPath) + + assert.Equal(t, strings.Join(cmd, " "), golden) +}