VideoEncoder* Muxer::AddVideoEncoder(const QString& codec_name, const std::vector<std::pair<QString, QString> >& codec_options, unsigned int bit_rate, unsigned int width, unsigned int height, unsigned int frame_rate) { AVCodec *codec = FindCodec(codec_name); AVStream *stream = AddStream(codec); VideoEncoder *encoder; AVDictionary *options = NULL; try { VideoEncoder::PrepareStream(stream, codec, &options, codec_options, bit_rate, width, height, frame_rate); m_encoders[stream->index] = encoder = new VideoEncoder(this, stream, codec, &options); av_dict_free(&options); } catch(...) { av_dict_free(&options); throw; } return encoder; }
AudioEncoder* Muxer::AddAudioEncoder(const QString& codec_name, const std::vector<std::pair<QString, QString> >& codec_options, unsigned int bit_rate, unsigned int channels, unsigned int sample_rate) { AVCodec *codec = FindCodec(codec_name); AVStream *stream = AddStream(codec); AudioEncoder *encoder; AVDictionary *options = NULL; try { AudioEncoder::PrepareStream(stream, codec, &options, codec_options, bit_rate, channels, sample_rate); m_encoders[stream->index] = encoder = new AudioEncoder(this, stream, codec, &options); av_dict_free(&options); } catch(...) { av_dict_free(&options); throw; } return encoder; }
VideoEncoder* Muxer::AddVideoEncoder(const QString& codec_name, const std::vector<std::pair<QString, QString> >& codec_options, unsigned int bit_rate, unsigned int width, unsigned int height, unsigned int frame_rate) { AVCodec *codec = FindCodec(codec_name); AVCodecContext *codec_context = NULL; AVStream *stream = AddStream(codec, &codec_context); VideoEncoder *encoder; AVDictionary *options = NULL; try { VideoEncoder::PrepareStream(stream, codec_context, codec, &options, codec_options, bit_rate, width, height, frame_rate); m_encoders[stream->index] = encoder = new VideoEncoder(this, stream, codec_context, codec, &options); #if SSR_USE_AVSTREAM_CODECPAR if(avcodec_parameters_from_context(stream->codecpar, codec_context) < 0) { Logger::LogError("[Muxer::AddVideoEncoder] " + Logger::tr("Error: Can't copy parameters to stream!")); throw LibavException(); } #endif av_dict_free(&options); } catch(...) { av_dict_free(&options); throw; } return encoder; }
static HRESULT WINAPI QTVDecoder_SetMediaType(TransformFilter *tf, PIN_DIRECTION dir, const AM_MEDIA_TYPE * pmt) { QTVDecoderImpl* This = impl_from_TransformFilter(tf); HRESULT hr = VFW_E_TYPE_NOT_ACCEPTED; OSErr err = noErr; AM_MEDIA_TYPE *outpmt = &This->tf.pmt; CFNumberRef n = NULL; TRACE("(%p)->(%p)\n", This, pmt); if (dir != PINDIR_INPUT) return S_OK; FreeMediaType(outpmt); CopyMediaType(outpmt, pmt); if (This->hImageDescription) DisposeHandle((Handle)This->hImageDescription); This->hImageDescription = (ImageDescriptionHandle) NewHandleClear(sizeof(ImageDescription)); if (This->hImageDescription != NULL) { (**This->hImageDescription).idSize = sizeof(ImageDescription); (**This->hImageDescription).spatialQuality = codecNormalQuality; (**This->hImageDescription).frameCount = 1; (**This->hImageDescription).clutID = -1; } else { ERR("Failed to create ImageDescription\n"); goto failed; } /* Check root (GUID w/o FOURCC) */ if ((IsEqualIID(&pmt->majortype, &MEDIATYPE_Video)) && (!memcmp(((const char *)&pmt->subtype)+4, ((const char *)&MEDIATYPE_Video)+4, sizeof(GUID)-4))) { VIDEOINFOHEADER *format1 = (VIDEOINFOHEADER *)outpmt->pbFormat; VIDEOINFOHEADER2 *format2 = (VIDEOINFOHEADER2 *)outpmt->pbFormat; BITMAPINFOHEADER *bmi; OSType fourCC; DecompressorComponent dc; OSType format; DWORD outputWidth, outputHeight, outputDepth; if (IsEqualIID(&pmt->formattype, &FORMAT_VideoInfo)) bmi = &format1->bmiHeader; else if (IsEqualIID(&pmt->formattype, &FORMAT_VideoInfo2)) bmi = &format2->bmiHeader; else goto failed; TRACE("Fourcc: %s\n", debugstr_an((const char *)&pmt->subtype.Data1, 4)); fourCC = ((const char *)&pmt->subtype.Data1)[3] | (((const char *)&pmt->subtype.Data1)[2]<<8) | (((const char *)&pmt->subtype.Data1)[1]<<16) | (((const char *)&pmt->subtype.Data1)[0]<<24); err = FindCodec(fourCC,NULL,NULL,&dc); if (err != noErr || dc == 0x0) { TRACE("Codec not found\n"); goto failed; } outputWidth = bmi->biWidth; outputHeight = bmi->biHeight; (**This->hImageDescription).cType = fourCC; (**This->hImageDescription).width = outputWidth; (**This->hImageDescription).height = outputHeight; (**This->hImageDescription).depth = bmi->biBitCount; (**This->hImageDescription).hRes = 72<<16; (**This->hImageDescription).vRes = 72<<16; if (This->outputBufferAttributes) CFRelease(This->outputBufferAttributes); This->outputBufferAttributes = CFDictionaryCreateMutable(NULL, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); if (!This->outputBufferAttributes) { ERR("Failed to create outputBufferAttributes\n"); goto failed; } n = CFNumberCreate(NULL, kCFNumberIntType, &outputWidth); CFDictionaryAddValue(This->outputBufferAttributes, kCVPixelBufferWidthKey, n); CFRelease(n); n = CFNumberCreate(NULL, kCFNumberIntType, &outputHeight); CFDictionaryAddValue(This->outputBufferAttributes, kCVPixelBufferHeightKey, n); CFRelease(n); /* yes this looks wrong. but 32ARGB is 24 RGB with an alpha channel */ format = k32ARGBPixelFormat; n = CFNumberCreate(NULL, kCFNumberIntType, &format); CFDictionaryAddValue(This->outputBufferAttributes, kCVPixelBufferPixelFormatTypeKey, n); CFRelease(n); CFDictionaryAddValue(This->outputBufferAttributes, kCVPixelBufferCGBitmapContextCompatibilityKey, kCFBooleanTrue); CFDictionaryAddValue(This->outputBufferAttributes, kCVPixelBufferCGImageCompatibilityKey, kCFBooleanTrue); outputDepth = 3; This->outputSize = outputWidth * outputHeight * outputDepth; bmi->biCompression = BI_RGB; bmi->biBitCount = 24; outpmt->subtype = MEDIASUBTYPE_RGB24; return S_OK; } failed: if (This->hImageDescription) { DisposeHandle((Handle)This->hImageDescription); This->hImageDescription = NULL; } if (This->outputBufferAttributes) { CFRelease(This->outputBufferAttributes); This->outputBufferAttributes = NULL; } TRACE("Connection refused\n"); return hr; }