| 386 | } |
| 387 | |
| 388 | bool ScreenRecorder::prepareOutput() { |
| 389 | traceScope(); |
| 390 | |
| 391 | if (nullptr == m_captureCodecCtx) { |
| 392 | logError("prepareOutput: input not ready"); |
| 393 | return false; |
| 394 | } |
| 395 | |
| 396 | m_capturePacket = av_packet_alloc(); |
| 397 | if (nullptr == m_capturePacket) { |
| 398 | logError("prepareOutput: unable to allocate AVPacket"); |
| 399 | return false; |
| 400 | } |
| 401 | |
| 402 | m_captureFrame = av_frame_alloc(); |
| 403 | if (nullptr == m_captureFrame) { |
| 404 | logError("prepareOutput: unable to allocate AVFrame"); |
| 405 | return false; |
| 406 | } |
| 407 | |
| 408 | m_outputPacket = av_packet_alloc(); |
| 409 | if (nullptr == m_outputPacket) { |
| 410 | logError("prepareOutput: unable to allocate AVPacket"); |
| 411 | return false; |
| 412 | } |
| 413 | |
| 414 | if (nullptr != m_outputCodecCtx && avcodec_is_open(m_outputCodecCtx)) { |
| 415 | avcodec_close(m_outputCodecCtx); |
| 416 | } else { |
| 417 | m_outputCodecCtx = avcodec_alloc_context3(m_outputCodec); |
| 418 | if (nullptr == m_outputCodecCtx) { |
| 419 | logError("prepareOutput: unable to allocate codec context"); |
| 420 | return false; |
| 421 | } |
| 422 | } |
| 423 | |
| 424 | m_scaledWith = m_downScale ? (int)(m_captureRect.getWidth() / m_scale) : m_captureRect.getWidth(); |
| 425 | m_scaledHeight = m_downScale ? (int)(m_captureRect.getHeight() / m_scale) : m_captureRect.getHeight(); |
| 426 | |
| 427 | m_outputCodecCtx->pix_fmt = m_encMode == MJPEG ? AV_PIX_FMT_YUVJ420P : AV_PIX_FMT_YUV420P; |
| 428 | m_outputCodecCtx->time_base.num = 1; |
| 429 | m_outputCodecCtx->time_base.den = 30; |
| 430 | m_outputCodecCtx->width = m_scaledWith; |
| 431 | m_outputCodecCtx->height = m_scaledHeight; |
| 432 | |
| 433 | // avcodec_align_dimensions(m_outputCodecCtx, &m_outputCodecCtx->width, &m_outputCodecCtx->height); |
| 434 | |
| 435 | logln("prepareOutput: setting output codec context dimensions to " |
| 436 | << m_outputCodecCtx->width << "x" << m_outputCodecCtx->height << " (unalligned " << m_scaledWith << "x" |
| 437 | << m_scaledHeight << ")"); |
| 438 | |
| 439 | AVDictionary* opts = nullptr; |
| 440 | switch (m_encMode) { |
| 441 | case WEBP: |
| 442 | av_dict_set(&opts, "preset", "none", 0); |
| 443 | av_dict_set(&opts, "compression_level", "1", 0); |
| 444 | av_dict_set(&opts, "global_quality", String(m_quality).getCharPointer(), 0); |
| 445 | break; |
nothing calls this directly
no outgoing calls
no test coverage detected