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

Function oh_encode_set_format

libavcodec/ohenc.c:113–213  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

111}
112
113static int oh_encode_set_format(OHCodecEncContext *s, AVCodecContext *avctx)
114{
115 int ret;
116
117 OH_AVFormat *format = OH_AVFormat_Create();
118 if (!format)
119 return AVERROR(ENOMEM);
120
121 bool b = OH_AVFormat_SetIntValue(format, OH_MD_KEY_WIDTH, avctx->width);
122 b = b && OH_AVFormat_SetIntValue(format, OH_MD_KEY_HEIGHT, avctx->height);
123 if (!b) {
124 av_log(avctx, AV_LOG_ERROR, "Set width/height (%dx%d) failed\n",
125 avctx->width, avctx->height);
126 ret = AVERROR_EXTERNAL;
127 goto out;
128 }
129 if (avctx->framerate.num && avctx->framerate.den)
130 OH_AVFormat_SetDoubleValue(format, OH_MD_KEY_FRAME_RATE,
131 av_q2d(avctx->framerate));
132 int pix = ff_oh_pix_from_ff_pix(avctx->pix_fmt);
133 if (!pix) {
134 ret = AVERROR_BUG;
135 goto out;
136 }
137 b = OH_AVFormat_SetIntValue(format, OH_MD_KEY_PIXEL_FORMAT, pix);
138 if (!b) {
139 av_log(avctx, AV_LOG_ERROR, "Set pixel format to %d failed\n", pix);
140 ret = AVERROR_EXTERNAL;
141 goto out;
142 }
143
144 if (s->bitrate_mode != -1) {
145 b = OH_AVFormat_SetIntValue(format, OH_MD_KEY_VIDEO_ENCODE_BITRATE_MODE, s->bitrate_mode);
146 if (!b) {
147 av_log(avctx, AV_LOG_ERROR, "Set bitrate mode to %d failed\n",
148 s->bitrate_mode);
149 ret = AVERROR_EXTERNAL;
150 goto out;
151 }
152 }
153 OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, avctx->bit_rate);
154
155 if (avctx->gop_size > 0) {
156 if (avctx->framerate.num > 0 && avctx->framerate.den > 0) {
157 // In milliseconds
158 int gop = av_rescale_q(avctx->gop_size,
159 av_make_q(avctx->framerate.den,
160 avctx->framerate.num),
161 av_make_q(1, 1000));
162 OH_AVFormat_SetIntValue(format, OH_MD_KEY_I_FRAME_INTERVAL, gop);
163 } else {
164 av_log(avctx, AV_LOG_WARNING, "Skip setting gop without framerate\n");
165 }
166 } else if (!avctx->gop_size) {
167 // All frames are key frame
168 OH_AVFormat_SetIntValue(format, OH_MD_KEY_I_FRAME_INTERVAL, 0);
169 } else if (avctx->gop_size == -1) {
170 // Infinite gop

Callers 1

oh_encode_initFunction · 0.85

Calls 7

av_logFunction · 0.85
av_q2dFunction · 0.85
ff_oh_pix_from_ff_pixFunction · 0.85
av_rescale_qFunction · 0.85
av_make_qFunction · 0.85
ff_oh_err_to_ff_errFunction · 0.85
av_hwdevice_ctx_createFunction · 0.85

Tested by

no test coverage detected