MCPcopy Create free account
hub / github.com/apohl79/audiogridder / initCodec

Method initCodec

Plugin/Source/ImageReader.cpp:97–164  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

95}
96
97bool ImageReader::initCodec() {
98 traceScope();
99
100 av_log_set_level(AV_LOG_QUIET);
101
102 m_inputCodec = avcodec_find_decoder_by_name("webp");
103 if (nullptr == m_inputCodec) {
104 logln("unable to find webp codec");
105 return false;
106 }
107
108 m_inputPacket = av_packet_alloc();
109 if (nullptr == m_inputPacket) {
110 logln("unable to allocate AVPacket");
111 return false;
112 }
113
114 m_inputFrame = av_frame_alloc();
115 if (nullptr == m_inputFrame) {
116 logln("unable to allocate AVFrame");
117 return false;
118 }
119
120 m_inputCodecCtx = avcodec_alloc_context3(m_inputCodec);
121 if (nullptr == m_inputCodecCtx) {
122 logln("unable to allocate codec context");
123 return false;
124 }
125
126 m_inputCodecCtx->pix_fmt = AV_PIX_FMT_YUV420P;
127 m_inputCodecCtx->time_base.num = 1;
128 m_inputCodecCtx->time_base.den = 20;
129 m_inputCodecCtx->width = m_widthPadded;
130 m_inputCodecCtx->height = m_heightPadded;
131
132 logln("setting input codec context dimensions to " << m_inputCodecCtx->width << "x" << m_inputCodecCtx->height);
133
134 int ret = avcodec_open2(m_inputCodecCtx, m_inputCodec, nullptr);
135 if (ret < 0) {
136 logln("avcodec_open2 failed: " << ret);
137 return false;
138 }
139
140 m_outputFrame = av_frame_alloc();
141 if (nullptr == m_outputFrame) {
142 logln("unable to allocate AVFrame");
143 return false;
144 }
145
146 auto fmt = AV_PIX_FMT_RGB32;
147 m_outputFrame->width = m_width;
148 m_outputFrame->height = m_height;
149 m_outputFrame->format = fmt;
150
151 m_outputFrameBuf =
152 (uint8_t*)av_malloc((size_t)av_image_get_buffer_size(fmt, m_outputFrame->width, m_outputFrame->height, 1) +
153 AV_INPUT_BUFFER_PADDING_SIZE);
154

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected