mirror of
https://github.com/pion/mediadevices.git
synced 2026-04-22 15:57:27 +08:00
Apply keyframe interval
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
#include <EbSvtAv1.h>
|
||||
#include <EbSvtAv1Enc.h>
|
||||
#include <EbSvtAv1ErrorCodes.h>
|
||||
#include <stdint.h>
|
||||
@@ -72,3 +73,11 @@ int enc_close(Encoder *e) {
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int enc_is_force_keyframe_supported() {
|
||||
#if SVT_AV1_CHECK_VERSION(1, 8, 0)
|
||||
return 1;
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -57,6 +57,7 @@ func newEncoder(r video.Reader, p prop.Media, params Params) (codec.ReadCloser,
|
||||
enc.param.max_qp_allowed = 63
|
||||
enc.param.min_qp_allowed = 0
|
||||
enc.param.intra_refresh_type = C.SVT_AV1_KF_REFRESH
|
||||
enc.param.intra_period_length = C.int32_t(params.KeyFrameInterval)
|
||||
|
||||
if err := errFromC(C.enc_init(enc)); err != nil {
|
||||
_ = C.enc_close(enc)
|
||||
@@ -112,6 +113,13 @@ func (e *encoder) Read() ([]byte, func(), error) {
|
||||
return nil, func() {}, err
|
||||
}
|
||||
|
||||
if e.engine.param.force_key_frames == 1 {
|
||||
e.engine.param.force_key_frames = 0
|
||||
if err := errFromC(C.enc_apply_param(e.engine)); err != nil {
|
||||
return nil, func() {}, err
|
||||
}
|
||||
}
|
||||
|
||||
encoded := C.GoBytes(unsafe.Pointer(buf.data), buf.len)
|
||||
return encoded, func() {}, err
|
||||
}
|
||||
@@ -120,6 +128,11 @@ func (e *encoder) Read() ([]byte, func(), error) {
|
||||
//var _ codec.BitRateController = (*encoder)(nil)
|
||||
|
||||
func (e *encoder) ForceKeyFrame() error {
|
||||
if C.enc_is_force_keyframe_supported() == 0 {
|
||||
// Force keyframe on this mode is supported since SVT-AV1 v1.8.0
|
||||
return nil
|
||||
}
|
||||
|
||||
e.mu.Lock()
|
||||
defer e.mu.Unlock()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user