Beispiel #1
0
        /// <summary>Builds the transcoder configuration from stream.</summary>
        /// <param name="inStream">The in stream.</param>
        /// <param name="inputCodecId">The input codec identifier.</param>
        /// <param name="outputCodecId">The output codec identifier.</param>
        /// <param name="implementation">The implementation.</param>
        /// <param name="useOpaqueSurfaces">if set to <c>true</c> [use opaque surfaces].</param>
        /// <returns></returns>
        public static TranscoderConfiguration BuildTranscoderConfigurationFromStream(Stream inStream, CodecId inputCodecId, CodecId outputCodecId, mfxIMPL implementation = mfxIMPL.MFX_IMPL_AUTO, bool useOpaqueSurfaces = true)
        {
            TranscoderConfiguration config = new TranscoderConfiguration();

            long oldposition = inStream.Position;

            config.decParams  = QuickSyncStatic.DecodeHeader(inStream, inputCodecId, implementation);
            inStream.Position = oldposition;

            //config.decParams.mfx.CodecId  was set in last function
            //config.encParams.mfx.CodecId  will get set below in a func

            int width  = config.decParams.mfx.FrameInfo.CropW;
            int height = config.decParams.mfx.FrameInfo.CropH;

            config.vppParams = TranscoderSetupVPPParameters(width, height);
            config.encParams = TranscoderSetupEncoderParameters(width, height, outputCodecId);


            config.decParams.IOPattern = IOPattern.MFX_IOPATTERN_OUT_SYSTEM_MEMORY;
            config.vppParams.IOPattern = IOPattern.MFX_IOPATTERN_IN_SYSTEM_MEMORY | IOPattern.MFX_IOPATTERN_OUT_SYSTEM_MEMORY;
            config.encParams.IOPattern = IOPattern.MFX_IOPATTERN_IN_SYSTEM_MEMORY;

            // Configure Media SDK to keep more operations in flight
            // - AsyncDepth represents the number of tasks that can be submitted, before synchronizing is required
            ushort asyncdepth = 4;

            config.decParams.AsyncDepth = asyncdepth;
            config.encParams.AsyncDepth = asyncdepth;
            config.vppParams.AsyncDepth = asyncdepth;

            return(config);
        }
Beispiel #2
0
        /// <summary>Reads the file header information.</summary>
        /// <param name="codecId">The codec identifier.</param>
        /// <param name="impl">The implementation.</param>
        /// <param name="infs">The infs.</param>
        /// <param name="outIOPattern">The out io pattern.</param>
        /// <returns></returns>
        public static unsafe mfxVideoParam ReadFileHeaderInfo(CodecId codecId, mfxIMPL impl, Stream infs, IOPattern outIOPattern)
        {
            long oldposition = infs.Position;

            var buf = new byte[65536]; //avail after init
            int n   = infs.Read(buf, 0, buf.Length);

            if (n < buf.Length)
            {
                Array.Resize(ref buf, n);
            }

            infs.Position = oldposition;
            var decoderParameters = QuickSyncStatic.DecodeHeader(buf, codecId, impl);

            decoderParameters.IOPattern = outIOPattern;
            return(decoderParameters);
        }
Beispiel #3
0
        //static public IEnumerable<byte[]> DecodeStream(Stream s, FourCC fourcc = FourCC.NV12, AccelerationLevel acceleration = AccelerationLevel.BestAvailableAccelerationUseGPUorCPU)
        //{
        //    return null;
        //}


        /// <summary>
        /// Construct the decoder.
        /// </summary>
        /// <param name="stream">Stream be read from</param>
        /// <param name="codecId">What format the bitstream is in: AVC, HEVC, MJPEG, ...</param>
        /// <param name="impl">implementation to use</param>
        /// <param name="outIOPattern">memory type for decoding</param>
        public StreamDecoder(Stream stream, CodecId codecId, mfxIMPL impl = mfxIMPL.MFX_IMPL_AUTO, IOPattern outIOPattern = IOPattern.MFX_IOPATTERN_OUT_SYSTEM_MEMORY)
        {
            long oldposition = stream.Position;

            var buf = new byte[65536]; //avail after init
            int n   = stream.Read(buf, 0, buf.Length);

            if (n < buf.Length)
            {
                Array.Resize(ref buf, n);
            }

            stream.Position                  = oldposition;
            this.decoderParameters           = QuickSyncStatic.DecodeHeader(buf, codecId, impl);
            this.decoderParameters.IOPattern = outIOPattern;

            lowLevelDecoder = new LowLevelDecoder(decoderParameters, null, impl);
            Init(stream);
        }