Skip to content

Commit

Permalink
Merge pull request #64 from bcc-code/feat/xdcam-interlace
Browse files Browse the repository at this point in the history
feat: xdcam interlace option
  • Loading branch information
andreasgangso authored Sep 28, 2023
2 parents 46fd850 + 74c53c4 commit b416111
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 7 deletions.
4 changes: 3 additions & 1 deletion services/transcode/h264.go
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -14,6 +15,7 @@ type EncodeInput struct {
Resolution string
FrameRate int
Bitrate string
Interlace bool
}

type EncodeResult struct {
Expand Down
26 changes: 20 additions & 6 deletions services/transcode/xdcam.go
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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
Expand Down
25 changes: 25 additions & 0 deletions services/transcode/xdcam_test.go
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit b416111

Please sign in to comment.