Пример #1
0
        /// <summary>
        /// Opens a media container and stream codecs from given stream.
        /// </summary>
        /// <param name="stream">A stream of the multimedia file.</param>
        /// <param name="options">The media settings.</param>
        /// <returns>A new instance of the <see cref="InputContainer"/> class.</returns>
        public static InputContainer LoadStream(Stream stream, MediaOptions options)
        {
            return(MakeContainer(null, options, context =>
            {
                var avioStream = new AvioStream(stream);

                // Prevents garbage collection
                readCallback = avioStream.Read;
                seekCallback = avioStream.Seek;

                int bufferLength = 4096;
                var avioBuffer = (byte *)ffmpeg.av_malloc((ulong)bufferLength);

                context->pb = ffmpeg.avio_alloc_context(avioBuffer, bufferLength, 0, null, readCallback, null, seekCallback);
                if (context->pb == null)
                {
                    throw new FFmpegException("Cannot allocate AVIOContext.");
                }
            }));
        }
Пример #2
0
        private static InputContainer MakeContainer(Stream input, MediaOptions options)
        {
            var avioStream = new AvioStream(input);
            var read       = (avio_alloc_context_read_packet)avioStream.Read;
            var seek       = (avio_alloc_context_seek)avioStream.Seek;

            var context = MakeContext(null, options, ctx =>
            {
                int bufferLength = 4096;
                var avioBuffer   = (byte *)ffmpeg.av_malloc((ulong)bufferLength);

                ctx->pb = ffmpeg.avio_alloc_context(avioBuffer, bufferLength, 0, null, read, null, seek);
                if (ctx->pb == null)
                {
                    throw new FFmpegException("Cannot allocate AVIOContext.");
                }
            });

            var container = new InputContainer(context, read, seek, options.PacketBufferSizeLimit);

            container.OpenStreams(options);
            return(container);
        }