static public ffmpeg.net.AVFormatContext OpenInput(System.IO.Stream cStream, string sFormat) { net.AVFormatContext cRetVal = new net.AVFormatContext(); int nError = 0; cRetVal._cStream = cStream; //lock (helper._oSyncRootGlobal) { cRetVal._p = avformat_alloc_context(); cRetVal._st = (AVFormatContextInternal)Marshal.PtrToStructure(cRetVal._p, typeof(AVFormatContextInternal)); int nBufferSize = 32768; cRetVal._pAVIOBuffer = av_malloc(nBufferSize + Constants.FF_INPUT_BUFFER_PADDING_SIZE); cRetVal.fAVIOBufferRead = cRetVal.StreamRead; cRetVal.fAVIOBufferSeek = cRetVal.StreamSeek; cRetVal._st.pb = cRetVal._pAVIOContext = avio_alloc_context(cRetVal._pAVIOBuffer, nBufferSize, 0, NULL, Marshal.GetFunctionPointerForDelegate(cRetVal.fAVIOBufferRead), Marshal.GetFunctionPointerForDelegate(cRetVal.fAVIOBufferSeek), Marshal.GetFunctionPointerForDelegate(cRetVal.fAVIOBufferSeek)); Marshal.StructureToPtr(cRetVal._st, cRetVal._p, true); IntPtr pFormat = NULL; if (null != sFormat) { pFormat = av_find_input_format(sFormat); } if (0 != (nError = avformat_open_input(ref cRetVal._p, "buffer" + cStream.GetHashCode() + ".ts", pFormat, NULL))) { throw new Exception(helper.ErrorDescriptionGet(nError)); // Couldn't open file } } cRetVal._bMarshalOutNeeds = true; return(cRetVal); }