MCPcopy Create free account
hub / github.com/dirkvdb/ffmpegthumbnailer / initializeVideo

Method initializeVideo

libffmpegthumbnailer/moviedecoder.cpp:167–204  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

165}
166
167void MovieDecoder::initializeVideo(bool preferEmbeddedMetadata)
168{
169 m_VideoStream = findPreferredVideoStream(preferEmbeddedMetadata);
170
171 if (m_VideoStream < 0) {
172 destroy();
173 throw logic_error("Could not find video stream");
174 }
175
176 m_pVideoStream = m_pFormatContext->streams[m_VideoStream];
177 m_pVideoCodec = avcodec_find_decoder(m_pVideoStream->codecpar->codec_id);
178
179 if (m_pVideoCodec == nullptr) {
180 // set to nullptr, otherwise avcodec_close(m_pVideoCodecContext) crashes
181 m_pVideoCodecContext = nullptr;
182 destroy();
183 throw logic_error("Video Codec not found");
184 }
185
186 m_pVideoCodecContext = avcodec_alloc_context3(m_pVideoCodec);
187
188 if (m_pVideoCodecContext == nullptr) {
189 destroy();
190 throw logic_error("Could not allocate video codec context");
191 }
192
193 if (avcodec_parameters_to_context(m_pVideoCodecContext, m_pVideoStream->codecpar) < 0) {
194 destroy();
195 throw logic_error("Could not configure video codec context");
196 }
197
198 m_pVideoCodecContext->workaround_bugs = 1;
199
200 if (avcodec_open2(m_pVideoCodecContext, m_pVideoCodec, nullptr) < 0) {
201 destroy();
202 throw logic_error("Could not open video codec");
203 }
204}
205
206std::string MovieDecoder::createScaleString(const std::string& sizeString, bool maintainAspectRatio)
207{

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected