コード例 #1
0
        private static InputContainer MakeContainer(string url, MediaOptions options, AVFormatContextDelegate contextDelegate)
        {
            var context = MakeContext(url, options, contextDelegate);

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

            container.OpenStreams(options);
            return(container);
        }
コード例 #2
0
        private static InputContainer MakeContainer(string url, MediaOptions options, AVFormatContextDelegate contextDelegate)
        {
            FFmpegLoader.LoadFFmpeg();

            var context = ffmpeg.avformat_alloc_context();

            options.DemuxerOptions.ApplyFlags(context);
            var dict = new FFDictionary(options.DemuxerOptions.PrivateOptions, false).Pointer;

            contextDelegate(context);

            ffmpeg.avformat_open_input(&context, url, null, &dict)
            .ThrowIfError("An error occurred while opening the file");

            ffmpeg.avformat_find_stream_info(context, null)
            .ThrowIfError("Cannot find stream info");

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

            container.OpenStreams(options);
            return(container);
        }
コード例 #3
0
        /// <summary>
        /// Opens a media container and stream codecs from given path.
        /// </summary>
        /// <param name="path">A path to 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 LoadFile(string path, MediaOptions options)
        {
            MediaToolkit.LoadFFmpeg();

            var context = ffmpeg.avformat_alloc_context();

            options.DemuxerOptions.ApplyFlags(context);
            var dict = new FFDictionary(options.DemuxerOptions.PrivateOptions);
            var ptr  = dict.Pointer;

            ffmpeg.avformat_open_input(&context, path, null, &ptr)
            .ThrowIfError("An error ocurred while opening the file");

            ffmpeg.avformat_find_stream_info(context, null)
            .ThrowIfError("Cannot find stream info");

            dict.Update(ptr);

            var container = new InputContainer(context);

            container.OpenStreams(options);
            return(container);
        }
コード例 #4
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);
        }