Skip to content

Commit 293213b

Browse files
committed
✨ Add CRF argument
1 parent 49820df commit 293213b

File tree

4 files changed

+22
-1
lines changed

4 files changed

+22
-1
lines changed

args.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ type outputArgs struct {
3030
audioChannels int
3131
keyframeInterval int
3232
audioCodec string
33+
constantRateFactor int
3334
videoBitRate int
3435
videoBitRateTolerance int
3536
videoMaxBitrate int

command.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ func NewCommand(ffmpegPath string) *Command {
2525
}
2626
return &Command{
2727
FFmpegPath: ffmpegPath,
28-
Args: &Args{},
28+
Args: &Args{
29+
output: outputArgs{
30+
constantRateFactor: -1, // Initialize to -1 because zero value is a valid parameter
31+
},
32+
},
2933
}
3034
}
3135

output_getters.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@ func (a *Args) GetAspectRatio() []string {
2222
return nil
2323
}
2424

25+
// GetConstantRateFactor gets the constant rate factor (CRF) for video encoding
26+
func (a *Args) GetConstantRateFactor() []string {
27+
if a.output.constantRateFactor != -1 {
28+
return []string{"-crf", fmt.Sprintf("%d", a.output.constantRateFactor)}
29+
}
30+
31+
return nil
32+
}
33+
2534
// GetVideoBitRate returns returns the arguments for video bit rate
2635
func (a *Args) GetVideoBitRate() []string {
2736
if a.output.videoBitRate != 0 {

output_setters.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ func (c *Command) Resolution(v string) *Command {
1717
return c
1818
}
1919

20+
// ConstantRateFactor sets the constant rate factor (CRF) for video encoding
21+
func (c *Command) ConstantRateFactor(v int) *Command {
22+
c.Args.output.constantRateFactor = v
23+
24+
return c
25+
}
26+
2027
// VideoBitRate gets the video bit rate.
2128
func (c *Command) VideoBitRate(v int) *Command {
2229
c.Args.output.videoBitRate = v

0 commit comments

Comments
 (0)