internal override IntPtr DoDecode() { int size = 0; IntPtr rawData = AV.avcodec_alloc_frame(); int ret = AV.avcodec_decode_audio4(Codec, rawData, out size, Packet); if (ret <= 0 || size == 0) { AV.av_free(rawData); return(IntPtr.Zero); } return(rawData); }
internal override IntPtr DoDecode() { IntPtr rawData = AV.avcodec_alloc_frame(); int finish = 0;; int ret = AV.avcodec_decode_video2(Codec, rawData, out finish, Packet); if (ret < 0) { AV.av_free(rawData); return(IntPtr.Zero); } return(rawData); }
private void ConvertToBitmap(ref VideoFrameType t) { var frame = avFrame; //FFmpeg.AVFrame final = gcnew AvFrame(PIX_FMT_BGR24, this->size); IntPtr final = AV.avcodec_alloc_frame(); AV.AVFrame finalFrame = new NativeGetter <AV.AVFrame>(final).Get(); var dst_fmt = AV.AVPixelFormat.AV_PIX_FMT_BGR24; int count = AV.avpicture_get_size(dst_fmt, codecCtx.width, codecCtx.height); IntPtr bufferArr = Marshal.AllocHGlobal(count); AV.avpicture_fill(final, bufferArr, dst_fmt, codecCtx.width, codecCtx.height); IntPtr swsContext = AV.sws_getContext(codecCtx.width, codecCtx.height, codecCtx.pix_fmt, codecCtx.width, codecCtx.height, dst_fmt, AV.SWS_BICUBIC, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero); if (swsContext == IntPtr.Zero) { throw new Exception(); } finalFrame = new NativeGetter <AV.AVFrame>(final).Get(); AV.sws_scale(swsContext, frame.data, frame.linesize, 0, codecCtx.height, finalFrame.data, finalFrame.linesize); new NativeSetter <AV.AVFrame>(final).Set(finalFrame); // Array::Reverse(bufferArr); byte[] buffer = new byte[count]; Marshal.Copy(bufferArr, buffer, 0, count); AV.av_free(final); Marshal.FreeHGlobal(bufferArr); t.width = codecCtx.width; t.height = codecCtx.height; t.SourceFormat = codecCtx.pix_fmt; t.DestFormat = dst_fmt; t.managedData = buffer; t.linesize = finalFrame.linesize[0]; }