public static MediaDecode CreateDecode(string codecName, Action <MediaCodec> setBeforeOpen = null, MediaDictionary opts = null) { MediaDecode encode = new MediaDecode(codecName); encode.Initialize(setBeforeOpen, 0, opts); return(encode); }
public MediaReader(Stream stream, InFormat iformat = null, MediaDictionary options = null) { baseStream = stream; 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(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).ThrowExceptionIfError(); } ffmpeg.avformat_find_stream_info(pFormatContext, null).ThrowExceptionIfError(); base.Format = iformat ?? new InFormat(pFormatContext->iformat); for (int i = 0; i < pFormatContext->nb_streams; i++) { AVStream * pStream = pFormatContext->streams[i]; MediaDecode codec = MediaDecode.CreateDecode(pStream->codecpar->codec_id, _ => { ffmpeg.avcodec_parameters_to_context(_, pStream->codecpar); }); streams.Add(new MediaStream(pStream) { Codec = codec }); } }
/// <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) { unsafe { fixed(AVFormatContext **ppFormatContext = &pFormatContext) { ffmpeg.avformat_open_input(ppFormatContext, url, iformat, options).ThrowExceptionIfError(); } ffmpeg.avformat_find_stream_info(pFormatContext, null).ThrowExceptionIfError(); base.Format = iformat ?? new InFormat(pFormatContext->iformat); for (int i = 0; i < pFormatContext->nb_streams; i++) { AVStream * pStream = pFormatContext->streams[i]; MediaDecode codec = MediaDecode.CreateDecode(pStream->codecpar->codec_id, _ => { ffmpeg.avcodec_parameters_to_context(_, pStream->codecpar); }); streams.Add(new MediaStream(pStream) { Codec = codec }); } } }