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

Method prepareInput

Server/Source/ScreenRecorder.cpp:267–386  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

265}
266
267bool ScreenRecorder::prepareInput() {
268 traceScope();
269 AVDictionary* opts = nullptr;
270
271 // check if the plugin window is fully visible
272 if (m_captureRect.getX() < 0 || m_captureRect.getY() < 0) {
273 logError("The plugin window must be fully visible to be captured!");
274 return false;
275 }
276
277#ifdef JUCE_MAC
278 // This works only when building ffmpeg for OSX 10.8+. Thats why there is a separate 10.7 build.
279 // av_dict_set(&opts, "capture_cursor", "0", 0); // the default is 0 anyways, so we don't need to call this.
280 av_dict_set(&opts, "pixel_format", "yuyv422", 0);
281#else
282 av_dict_set(&opts, "draw_mouse", "0", 0);
283 av_dict_set(&opts, "framerate", "30", 0);
284 String vidSize;
285 vidSize << m_captureRect.getWidth() << "x" << m_captureRect.getHeight();
286 av_dict_set(&opts, "video_size", vidSize.getCharPointer(), 0);
287 av_dict_set(&opts, "offset_x", String(m_captureRect.getX()).getCharPointer(), 0);
288 av_dict_set(&opts, "offset_y", String(m_captureRect.getY()).getCharPointer(), 0);
289
290 logln("setting input options:");
291 logln(" video_size=" << vidSize);
292 logln(" offset_x=" << m_captureRect.getX());
293 logln(" offset_y=" << m_captureRect.getY());
294#endif
295
296 int ret;
297 String streamUrl = m_inputStreamUrl;
298#ifdef JUCE_LINUX
299 streamUrl = streamUrl << "+" << m_captureRect.getX() << "," << m_captureRect.getY();
300#endif
301 logln("opening input format " << m_inputFmtName << ": " << streamUrl);
302
303 m_captureFmtCtx = avformat_alloc_context();
304 ret = avformat_open_input(&m_captureFmtCtx, streamUrl.getCharPointer(), m_inputFmt, &opts);
305 if (ret != 0) {
306 logError("prepareInput: avformat_open_input failed: err = " + String(ret));
307 return false;
308 }
309
310 ret = avformat_find_stream_info(m_captureFmtCtx, nullptr);
311 if (ret < 0) {
312 logError("prepareInput: avformat_find_stream_info failed: " + String(ret));
313 return false;
314 }
315
316 logln("looking for video stream (input has " << String(m_captureFmtCtx->nb_streams) << " streams)");
317
318 m_captureStreamIndex = -1;
319 for (uint16 i = 0; i < m_captureFmtCtx->nb_streams; i++) {
320 m_captureStream = m_captureFmtCtx->streams[i];
321 if (m_captureStream->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
322 m_captureStreamIndex = i;
323 break;
324 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected