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

Function hw_device_setup_for_encode

fftools/ffmpeg_enc.c:133–182  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

131}
132
133static int hw_device_setup_for_encode(Encoder *e, AVCodecContext *enc_ctx,
134 AVBufferRef *frames_ref)
135{
136 const AVCodecHWConfig *config;
137 HWDevice *dev = NULL;
138
139 if (frames_ref &&
140 ((AVHWFramesContext*)frames_ref->data)->format ==
141 enc_ctx->pix_fmt) {
142 // Matching format, will try to use hw_frames_ctx.
143 } else {
144 frames_ref = NULL;
145 }
146
147 for (int i = 0;; i++) {
148 config = avcodec_get_hw_config(enc_ctx->codec, i);
149 if (!config)
150 break;
151
152 if (frames_ref &&
153 config->methods & AV_CODEC_HW_CONFIG_METHOD_HW_FRAMES_CTX &&
154 (config->pix_fmt == AV_PIX_FMT_NONE ||
155 config->pix_fmt == enc_ctx->pix_fmt)) {
156 av_log(e, AV_LOG_VERBOSE, "Using input "
157 "frames context (format %s) with %s encoder.\n",
158 av_get_pix_fmt_name(enc_ctx->pix_fmt),
159 enc_ctx->codec->name);
160 enc_ctx->hw_frames_ctx = av_buffer_ref(frames_ref);
161 if (!enc_ctx->hw_frames_ctx)
162 return AVERROR(ENOMEM);
163 return 0;
164 }
165
166 if (!dev &&
167 config->methods & AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX)
168 dev = hw_device_get_by_type(config->device_type);
169 }
170
171 if (dev) {
172 av_log(e, AV_LOG_VERBOSE, "Using device %s "
173 "(type %s) with %s encoder.\n", dev->name,
174 av_hwdevice_get_type_name(dev->type), enc_ctx->codec->name);
175 enc_ctx->hw_device_ctx = av_buffer_ref(dev->device_ref);
176 if (!enc_ctx->hw_device_ctx)
177 return AVERROR(ENOMEM);
178 } else {
179 // No device required, or no device available.
180 }
181 return 0;
182}
183
184int enc_open(void *opaque, const AVFrame *frame)
185{

Callers 1

enc_openFunction · 0.85

Calls 6

avcodec_get_hw_configFunction · 0.85
av_logFunction · 0.85
av_get_pix_fmt_nameFunction · 0.85
av_buffer_refFunction · 0.85
hw_device_get_by_typeFunction · 0.85

Tested by

no test coverage detected