Exemplo n.º 1
0
        public static MediaDecoder CreateDecoder(string codecName, Action <MediaCodec> setBeforeOpen = null, MediaDictionary opts = null)
        {
            MediaDecoder encode = new MediaDecoder(codecName);

            encode.Initialize(setBeforeOpen, 0, opts);
            return(encode);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Load stream with buffersize
        /// </summary>
        /// <param name="stream"></param>
        /// <param name="buffersize"></param>
        /// <param name="iformat"></param>
        /// <param name="options"></param>
        public MediaReader(Stream stream, int buffersize, InFormat iformat = null, MediaDictionary options = null)
        {
            baseStream   = stream;
            bufferLength = buffersize;
            buffer       = new byte[bufferLength];
            avio_Alloc_Context_Read_Packet = ReadFunc;
            avio_Alloc_Context_Seek        = SeekFunc;
            pFormatContext     = ffmpeg.avformat_alloc_context();
            pFormatContext->pb = ffmpeg.avio_alloc_context((byte *)ffmpeg.av_malloc((ulong)bufferLength), bufferLength, 0, null,
                                                           avio_Alloc_Context_Read_Packet, null, avio_Alloc_Context_Seek);
            fixed(AVFormatContext **ppFormatContext = &pFormatContext)
            {
                ffmpeg.avformat_open_input(ppFormatContext, null, iformat, options).ThrowIfError();
            }

            ffmpeg.avformat_find_stream_info(pFormatContext, null).ThrowIfError();
            base.Format = iformat ?? new InFormat(pFormatContext->iformat);

            for (int i = 0; i < pFormatContext->nb_streams; i++)
            {
                AVStream *   pStream = pFormatContext->streams[i];
                MediaDecoder codec   = MediaDecoder.CreateDecoder(pStream->codecpar->codec_id, _ =>
                {
                    ffmpeg.avcodec_parameters_to_context(_, pStream->codecpar);
                });
                streams.Add(new MediaStream(pStream)
                {
                    Codec = codec
                });
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Load path
        /// </summary>
        /// <param name="url"></param>
        /// <param name="iformat"></param>
        /// <param name="options"></param>
        public MediaReader(string url, InFormat iformat = null, MediaDictionary options = null)
        {
            fixed(AVFormatContext **ppFormatContext = &pFormatContext)
            {
                ffmpeg.avformat_open_input(ppFormatContext, url, iformat, options).ThrowIfError();
            }

            ffmpeg.avformat_find_stream_info(pFormatContext, null).ThrowIfError();
            base.Format = iformat ?? new InFormat(pFormatContext->iformat);

            for (int i = 0; i < pFormatContext->nb_streams; i++)
            {
                AVStream *   pStream = pFormatContext->streams[i];
                MediaDecoder codec   = MediaDecoder.CreateDecoder(pStream->codecpar->codec_id, _ =>
                {
                    ffmpeg.avcodec_parameters_to_context(_, pStream->codecpar);
                });
                streams.Add(new MediaStream(pStream)
                {
                    Codec = codec
                });
            }
        }