public bool TryDecode(ref byte[] data, out FFmpegNative.AVFrame frame) { int gotPicture; frame = new FFmpegNative.AVFrame(); fixed (byte* pData = &data[0]) fixed (FFmpegNative.AVFrame* pFrame = &frame) { var packet = new FFmpegNative.AVPacket {data = pData, size = data.Length}; int decodedSize = FFmpegNative.avcodec_decode_video2(_pDecodingContext, pFrame, &gotPicture, &packet); if (decodedSize < 0) Trace.TraceWarning("Error while decoding frame."); } return gotPicture == 1; }
public byte[,,] ConvertFrame(FFmpegNative.AVFrame frame) { if (_initialized == false) Initialize(frame.width, frame.height, (FFmpegNative.AVPixelFormat) frame.format); fixed (byte* pOutputData = &_outputData[0, 0, 0]) { byte** pSrcData = &(frame).data_0; byte** pDstData = &(_pCurrentFrame)->data_0; _pCurrentFrame->data_0 = pOutputData; FFmpegNative.sws_scale(_pContext, pSrcData, frame.linesize, 0, frame.height, pDstData, _pCurrentFrame->linesize); } return _outputData; }
private void Initialize(int width, int height, FFmpegNative.AVPixelFormat inFormat) { _initialized = true; _pContext = FFmpegNative.sws_getContext(width, height, inFormat, width, height, _pixelFormat, FFmpegNative.SWS_FAST_BILINEAR, null, null, null); if (_pContext == null) throw new VideoConverterException("Could not initialize the conversion context."); _pCurrentFrame = FFmpegNative.avcodec_alloc_frame(); int outputDataSize = FFmpegNative.avpicture_get_size(_pixelFormat, width, height); int depth = outputDataSize/(height*width); _outputData = new byte[height,width,depth]; fixed (byte* pOutputData = &_outputData[0, 0, 0]) { FFmpegNative.avpicture_fill((FFmpegNative.AVPicture*) _pCurrentFrame, pOutputData, _pixelFormat, width, height); } }
public VideoConverter(FFmpegNative.AVPixelFormat pixelFormat) { _pixelFormat = pixelFormat; }