mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-04-14 00:58:38 +02:00
lavc/videotoolboxenc: Support for forced I-frames
Setting AVFrame.pic_type to AV_PICTURE_TYPE_I will force an I-frame. Signed-off-by: Rick Kern <kernrj@gmail.com>
This commit is contained in:
parent
4b806081b2
commit
9d8a38d20b
@ -1414,27 +1414,51 @@ static int create_cv_pixel_buffer(AVCodecContext *avctx,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int create_encoder_dict_h264(const AVFrame *frame,
|
||||||
|
CFDictionaryRef* dict_out)
|
||||||
|
{
|
||||||
|
CFDictionaryRef dict = NULL;
|
||||||
|
if (frame->pict_type == AV_PICTURE_TYPE_I) {
|
||||||
|
const void *keys[] = { kVTEncodeFrameOptionKey_ForceKeyFrame };
|
||||||
|
const void *vals[] = { kCFBooleanTrue };
|
||||||
|
|
||||||
|
dict = CFDictionaryCreate(NULL, keys, vals, 1, NULL, NULL);
|
||||||
|
if(!dict) return AVERROR(ENOMEM);
|
||||||
|
}
|
||||||
|
|
||||||
|
*dict_out = dict;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int vtenc_send_frame(AVCodecContext *avctx,
|
static int vtenc_send_frame(AVCodecContext *avctx,
|
||||||
VTEncContext *vtctx,
|
VTEncContext *vtctx,
|
||||||
const AVFrame *frame)
|
const AVFrame *frame)
|
||||||
{
|
{
|
||||||
CMTime time;
|
CMTime time;
|
||||||
|
CFDictionaryRef frame_dict;
|
||||||
CVPixelBufferRef cv_img = NULL;
|
CVPixelBufferRef cv_img = NULL;
|
||||||
int status = create_cv_pixel_buffer(avctx, frame, &cv_img);
|
int status = create_cv_pixel_buffer(avctx, frame, &cv_img);
|
||||||
|
|
||||||
if (status) return status;
|
if (status) return status;
|
||||||
|
|
||||||
|
status = create_encoder_dict_h264(frame, &frame_dict);
|
||||||
|
if (status) {
|
||||||
|
CFRelease(cv_img);
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
time = CMTimeMake(frame->pts * avctx->time_base.num, avctx->time_base.den);
|
time = CMTimeMake(frame->pts * avctx->time_base.num, avctx->time_base.den);
|
||||||
status = VTCompressionSessionEncodeFrame(
|
status = VTCompressionSessionEncodeFrame(
|
||||||
vtctx->session,
|
vtctx->session,
|
||||||
cv_img,
|
cv_img,
|
||||||
time,
|
time,
|
||||||
kCMTimeInvalid,
|
kCMTimeInvalid,
|
||||||
NULL,
|
frame_dict,
|
||||||
NULL,
|
NULL,
|
||||||
NULL
|
NULL
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (frame_dict) CFRelease(frame_dict);
|
||||||
CFRelease(cv_img);
|
CFRelease(cv_img);
|
||||||
|
|
||||||
if (status) {
|
if (status) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user