mirror of
https://github.com/flavioribeiro/donut.git
synced 2025-09-27 03:15:54 +08:00
move filters and add codec context setters
This commit is contained in:
@@ -114,14 +114,20 @@ func (d *donutEngine) RecipeFor(server, client *entities.StreamInfo) (*entities.
|
|||||||
r := &entities.DonutRecipe{
|
r := &entities.DonutRecipe{
|
||||||
Input: appetizer,
|
Input: appetizer,
|
||||||
Video: entities.DonutMediaTask{
|
Video: entities.DonutMediaTask{
|
||||||
|
// Action: entities.DonutTranscode,
|
||||||
Action: entities.DonutBypass,
|
Action: entities.DonutBypass,
|
||||||
Codec: entities.H264,
|
Codec: entities.H264,
|
||||||
DonutBitStreamFilter: &entities.DonutH264AnnexB,
|
DonutBitStreamFilter: &entities.DonutH264AnnexB,
|
||||||
|
// CodecContextOptions: []entities.LibAVOptionsCodecContext{
|
||||||
|
// entities.SetBitRate(100_000),
|
||||||
|
// entities.SetBaselineProfile(),
|
||||||
|
// entities.SetGopSize(30),
|
||||||
|
// },
|
||||||
},
|
},
|
||||||
Audio: entities.DonutMediaTask{
|
Audio: entities.DonutMediaTask{
|
||||||
Action: entities.DonutTranscode,
|
Action: entities.DonutTranscode,
|
||||||
Codec: entities.Opus,
|
Codec: entities.Opus,
|
||||||
// TODO: create method list options per Codec
|
DonutStreamFilter: entities.AudioResamplerFilter(48000),
|
||||||
CodecContextOptions: []entities.LibAVOptionsCodecContext{
|
CodecContextOptions: []entities.LibAVOptionsCodecContext{
|
||||||
entities.SetSampleRate(48000),
|
entities.SetSampleRate(48000),
|
||||||
entities.SetSampleFormat("fltp"),
|
entities.SetSampleFormat("fltp"),
|
||||||
|
@@ -391,10 +391,11 @@ func (c *LibAVFFmpegStreamer) prepareFilters(p *libAVParams, closer *astikit.Clo
|
|||||||
}
|
}
|
||||||
buffersrc = astiav.FindFilterByName("abuffer")
|
buffersrc = astiav.FindFilterByName("abuffer")
|
||||||
buffersink = astiav.FindFilterByName("abuffersink")
|
buffersink = astiav.FindFilterByName("abuffersink")
|
||||||
content = fmt.Sprintf(
|
if donut.Recipe.Audio.DonutStreamFilter != nil {
|
||||||
"aresample=%s", // necessary for opus
|
content = string(*donut.Recipe.Audio.DonutStreamFilter)
|
||||||
strconv.Itoa(s.encCodecContext.SampleRate()),
|
} else {
|
||||||
)
|
content = "anull" /* passthrough (dummy) filter for audio */
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if isVideo {
|
if isVideo {
|
||||||
@@ -406,7 +407,11 @@ func (c *LibAVFFmpegStreamer) prepareFilters(p *libAVParams, closer *astikit.Clo
|
|||||||
}
|
}
|
||||||
buffersrc = astiav.FindFilterByName("buffer")
|
buffersrc = astiav.FindFilterByName("buffer")
|
||||||
buffersink = astiav.FindFilterByName("buffersink")
|
buffersink = astiav.FindFilterByName("buffersink")
|
||||||
content = fmt.Sprintf("format=pix_fmts=%s", s.encCodecContext.PixelFormat().Name())
|
if donut.Recipe.Video.DonutStreamFilter != nil {
|
||||||
|
content = string(*donut.Recipe.Video.DonutStreamFilter)
|
||||||
|
} else {
|
||||||
|
content = "null" /* passthrough (dummy) filter for video */
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if buffersrc == nil {
|
if buffersrc == nil {
|
||||||
|
@@ -156,6 +156,13 @@ type DonutBitStreamFilter string
|
|||||||
|
|
||||||
var DonutH264AnnexB DonutBitStreamFilter = "h264_mp4toannexb"
|
var DonutH264AnnexB DonutBitStreamFilter = "h264_mp4toannexb"
|
||||||
|
|
||||||
|
type DonutStreamFilter string
|
||||||
|
|
||||||
|
func AudioResamplerFilter(sampleRate int) *DonutStreamFilter {
|
||||||
|
filter := DonutStreamFilter(fmt.Sprintf("aresample=%d", sampleRate))
|
||||||
|
return &filter
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: split entities per domain or files avoiding name collision.
|
// TODO: split entities per domain or files avoiding name collision.
|
||||||
|
|
||||||
// DonutMediaTask is a transformation template to apply over a media.
|
// DonutMediaTask is a transformation template to apply over a media.
|
||||||
@@ -171,6 +178,9 @@ type DonutMediaTask struct {
|
|||||||
|
|
||||||
// DonutBitStreamFilter is the bitstream filter
|
// DonutBitStreamFilter is the bitstream filter
|
||||||
DonutBitStreamFilter *DonutBitStreamFilter
|
DonutBitStreamFilter *DonutBitStreamFilter
|
||||||
|
|
||||||
|
// DonutStreamFilter is a regular filter
|
||||||
|
DonutStreamFilter *DonutStreamFilter
|
||||||
}
|
}
|
||||||
|
|
||||||
type DonutInputOptionKey string
|
type DonutInputOptionKey string
|
||||||
@@ -220,6 +230,24 @@ func SetTimeBase(num, den int) LibAVOptionsCodecContext {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func SetBitRate(bitRate int64) LibAVOptionsCodecContext {
|
||||||
|
return func(c *astiav.CodecContext) {
|
||||||
|
c.SetBitRate(bitRate)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func SetBaselineProfile() LibAVOptionsCodecContext {
|
||||||
|
return func(c *astiav.CodecContext) {
|
||||||
|
c.SetProfile(astiav.ProfileH264Baseline)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func SetGopSize(gopSize int) LibAVOptionsCodecContext {
|
||||||
|
return func(c *astiav.CodecContext) {
|
||||||
|
c.SetGopSize(gopSize)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// SetSampleFormat sets sample format,
|
// SetSampleFormat sets sample format,
|
||||||
// CAUTION it only contains partial list of fmt
|
// CAUTION it only contains partial list of fmt
|
||||||
// TODO: move it to mappers
|
// TODO: move it to mappers
|
||||||
|
Reference in New Issue
Block a user