MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / roq_encode_frame

Function roq_encode_frame

libavcodec/roqvideoenc.c:1054–1103  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1052}
1053
1054static int roq_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
1055 const AVFrame *frame, int *got_packet)
1056{
1057 RoqEncContext *const enc = avctx->priv_data;
1058 RoqContext *const roq = &enc->common;
1059 int size, ret;
1060
1061 enc->frame_to_enc = frame;
1062
1063 if (frame->quality)
1064 enc->lambda = frame->quality - 1;
1065 else
1066 enc->lambda = 2*ROQ_LAMBDA_SCALE;
1067
1068 /* 138 bits max per 8x8 block +
1069 * 256 codebooks*(6 bytes 2x2 + 4 bytes 4x4) + 8 bytes frame header */
1070 size = ((roq->width * roq->height / 64) * 138 + 7) / 8 + 256 * (6 + 4) + 8;
1071 if ((ret = ff_alloc_packet(avctx, pkt, size)) < 0)
1072 return ret;
1073 enc->out_buf = pkt->data;
1074
1075 /* Check for I-frame */
1076 if (enc->framesSinceKeyframe == avctx->gop_size)
1077 enc->framesSinceKeyframe = 0;
1078
1079 if (enc->first_frame) {
1080 /* Alloc memory for the reconstruction data (we must know the stride
1081 for that) */
1082 if ((ret = ff_encode_alloc_frame(avctx, roq->current_frame)) < 0 ||
1083 (ret = ff_encode_alloc_frame(avctx, roq->last_frame )) < 0)
1084 return ret;
1085
1086 /* Before the first video frame, write a "video info" chunk */
1087 roq_write_video_info_chunk(enc);
1088
1089 enc->first_frame = 0;
1090 }
1091
1092 /* Encode the actual frame */
1093 ret = roq_encode_video(enc);
1094 if (ret < 0)
1095 return ret;
1096
1097 pkt->size = enc->out_buf - pkt->data;
1098 if (enc->framesSinceKeyframe == 1)
1099 pkt->flags |= AV_PKT_FLAG_KEY;
1100 *got_packet = 1;
1101
1102 return 0;
1103}
1104
1105#define OFFSET(x) offsetof(RoqEncContext, x)
1106#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM

Callers

nothing calls this directly

Calls 4

ff_alloc_packetFunction · 0.85
ff_encode_alloc_frameFunction · 0.85
roq_encode_videoFunction · 0.85

Tested by

no test coverage detected