/// <summary> /// <see cref="ffmpeg.avformat_write_header(AVFormatContext*, AVDictionary**)"/> /// </summary> /// <param name="options"></param> public int Initialize(MediaDictionary options = null) { unsafe { return(ffmpeg.avformat_write_header(pFormatContext, options).ThrowExceptionIfError()); } }
public void Init(MediaDictionary options) { unsafe { ffmpeg.avfilter_init_dict(pFilterContext, options).ThrowExceptionIfError(); } }
/// <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 }); } } }
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 }); } }
public MediaFilterContext AddFilter(MediaFilter filter, MediaDictionary options, string contextName = null) { AVFilterContext *p = ffmpeg.avfilter_graph_alloc_filter(pFilterGraph, filter, contextName); ffmpeg.avfilter_init_dict(p, options).ThrowExceptionIfError(); return(CreateAndUpdate(p)); }
/// <summary> /// write to file. /// <para><see cref="ffmpeg.avformat_alloc_output_context2(AVFormatContext**, AVOutputFormat*, string, string)"/></para> /// <para><see cref="ffmpeg.avio_open(AVIOContext**, string, int)"/></para> /// </summary> /// <param name="file"></param> /// <param name="oformat"></param> /// <param name="options"></param> public MediaWriter(string file, OutFormat oformat = null, MediaDictionary options = null) { fixed(AVFormatContext **ppFormatContext = &pFormatContext) { ffmpeg.avformat_alloc_output_context2(ppFormatContext, oformat, null, file).ThrowIfError(); } base.Format = oformat ?? new OutFormat(pFormatContext->oformat); if ((pFormatContext->oformat->flags & ffmpeg.AVFMT_NOFILE) == 0) { ffmpeg.avio_open2(&pFormatContext->pb, file, ffmpeg.AVIO_FLAG_WRITE, null, options).ThrowIfError(); } }
public MediaWriter(Stream stream, OutFormat oformat, MediaDictionary options = null) { baseStream = stream; avio_Alloc_Context_Read_Packet = ReadFunc; avio_Alloc_Context_Write_Packet = WriteFunc; avio_Alloc_Context_Seek = SeekFunc; pFormatContext = ffmpeg.avformat_alloc_context(); pFormatContext->oformat = oformat; base.Format = oformat; if ((pFormatContext->oformat->flags & ffmpeg.AVFMT_NOFILE) == 0) { pFormatContext->pb = ffmpeg.avio_alloc_context((byte *)ffmpeg.av_malloc(bufferLength), bufferLength, 1, null, avio_Alloc_Context_Read_Packet, avio_Alloc_Context_Write_Packet, avio_Alloc_Context_Seek); } }
/// <summary> /// NOTE: ffmpeg cannot get device information through code, only print the display. /// </summary> /// <param name="device"></param> /// <param name="parame"></param> /// <param name="options">options for <see cref=" ffmpeg.avformat_open_input"/></param> /// <returns></returns> public static void PrintDeviceInfos(MediaFormat device, string parame, MediaDictionary options = null) { AVFormatContext *pFmtCtx = ffmpeg.avformat_alloc_context(); ffmpeg.av_log(null, (int)LogLevel.Verbose, $"--------------------------{Environment.NewLine}"); if (device is InFormat iformat) { ffmpeg.avformat_open_input(&pFmtCtx, parame, iformat, options); } else if (device is OutFormat oformat) { ffmpeg.avformat_alloc_output_context2(&pFmtCtx, oformat, null, parame); } ffmpeg.av_log(null, (int)LogLevel.Verbose, $"--------------------------{Environment.NewLine}"); ffmpeg.avformat_free_context(pFmtCtx); }
/// <summary> /// alloc <see cref="AVCodecContext"/> and <see cref="ffmpeg.avcodec_open2(AVCodecContext*, AVCodec*, AVDictionary**)"/> /// </summary> /// <param name="setBeforeOpen"> /// set <see cref="AVCodecContext"/> after <see cref="ffmpeg.avcodec_alloc_context3(AVCodec*)"/> and before <see cref="ffmpeg.avcodec_open2(AVCodecContext*, AVCodec*, AVDictionary**)"/> /// </param> /// <param name="flags"> /// check <see cref="MediaFormat.Flags"/> & <see cref="ffmpeg.AVFMT_GLOBALHEADER"/> set <see cref="ffmpeg.AV_CODEC_FLAG_GLOBAL_HEADER"/> /// </param> /// <param name="opts">options for "avcodec_open2"</param> public override int Initialize(Action <MediaCodec> setBeforeOpen = null, int flags = 0, MediaDictionary opts = null) { pCodecContext = ffmpeg.avcodec_alloc_context3(pCodec); if (pCodecContext == null) { throw new FFmpegException(FFmpegException.NullReference); } setBeforeOpen?.Invoke(this); if ((flags & ffmpeg.AVFMT_GLOBALHEADER) != 0) { pCodecContext->flags |= ffmpeg.AV_CODEC_FLAG_GLOBAL_HEADER; } if (pCodec == null) { throw new FFmpegException(FFmpegException.NullReference); } return(ffmpeg.avcodec_open2(pCodecContext, pCodec, opts).ThrowIfError()); }
public static MediaDecoder CreateDecoder(AVCodecID codecId, Action <MediaCodec> setBeforeOpen = null, MediaDictionary opts = null) { MediaDecoder encode = new MediaDecoder(codecId); encode.Initialize(setBeforeOpen, 0, opts); return(encode); }
private static IntPtr av_dict_get_safe(MediaDictionary dict, string key, IntPtr prev, AVDictReadFlags flags) { return((IntPtr)ffmpeg.av_dict_get(dict.pDictionary, key, (AVDictionaryEntry *)prev, (int)flags)); }
/// <summary> /// Load stream, default buffer size is 4096 /// </summary> /// <param name="stream"></param> /// <param name="iformat"></param> /// <param name="options"></param> public MediaReader(Stream stream, InFormat iformat = null, MediaDictionary options = null) : this(stream, 4096, iformat, options) { }
public unsafe static IReadOnlyList <IReadOnlyList <MediaDevice> > GetDeviceInfos(MediaFormat device, MediaDictionary options = null) { string parame = "list"; AVFormatContext *pFmtCtx = ffmpeg.avformat_alloc_context(); Trace.TraceInformation("--------------------------"); if (device is InFormat iformat) { ffmpeg.avformat_open_input(&pFmtCtx, parame, iformat, options); } else if (device is OutFormat oformat) { ffmpeg.avformat_alloc_output_context2(&pFmtCtx, oformat, null, parame); } Trace.TraceInformation("--------------------------"); ffmpeg.avformat_free_context(pFmtCtx); return(new List <List <MediaDevice> >()); }
public static MediaEncoder CreateEncode(string codecName, int flags, Action <MediaCodec> setBeforeOpen = null, MediaDictionary opts = null) { MediaEncoder encode = new MediaEncoder(codecName); encode.Initialize(setBeforeOpen, flags, opts); return(encode); }
/// <summary> /// <see cref="ffmpeg.avformat_write_header(AVFormatContext*, AVDictionary**)"/> /// </summary> /// <param name="options"></param> public void Initialize(MediaDictionary options = null) { ffmpeg.avformat_write_header(pFormatContext, options).ThrowExceptionIfError(); }
/// <summary> /// alloc <see cref="AVCodecContext"/> and <see cref="ffmpeg.avcodec_open2(AVCodecContext*, AVCodec*, AVDictionary**)"/> /// </summary> /// <param name="setBeforeOpen"> /// set <see cref="AVCodecContext"/> after <see cref="ffmpeg.avcodec_alloc_context3(AVCodec*)"/> and before <see cref="ffmpeg.avcodec_open2(AVCodecContext*, AVCodec*, AVDictionary**)"/> /// </param> /// <param name="flags">no used</param> /// <param name="opts">options for "avcodec_open2"</param> public override void Initialize(Action <MediaCodec> setBeforeOpen = null, int flags = 0, MediaDictionary opts = null) { pCodecContext = ffmpeg.avcodec_alloc_context3(pCodec); setBeforeOpen?.Invoke(this); if (pCodec != null) { ffmpeg.avcodec_open2(pCodecContext, pCodec, opts).ThrowExceptionIfError(); } }
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); }
/// <summary> /// alloc <see cref="AVCodecContext"/> and <see cref="ffmpeg.avcodec_open2(AVCodecContext*, AVCodec*, AVDictionary**)"/> /// </summary> /// <param name="setBeforeOpen"> /// set <see cref="AVCodecContext"/> after <see cref="ffmpeg.avcodec_alloc_context3(AVCodec*)"/> and before <see cref="ffmpeg.avcodec_open2(AVCodecContext*, AVCodec*, AVDictionary**)"/> /// </param> /// <param name="flags"> /// check <see cref="MediaFormat.Flags"/> & <see cref="ffmpeg.AVFMT_GLOBALHEADER"/> set <see cref="ffmpeg.AV_CODEC_FLAG_GLOBAL_HEADER"/> /// </param> /// <param name="opts">options for "avcodec_open2"</param> public override void Initialize(Action <MediaCodec> setBeforeOpen = null, int flags = 0, MediaDictionary opts = null) { unsafe { pCodecContext = ffmpeg.avcodec_alloc_context3(pCodec); setBeforeOpen?.Invoke(this); if ((flags & ffmpeg.AVFMT_GLOBALHEADER) != 0) { pCodecContext->flags |= ffmpeg.AV_CODEC_FLAG_GLOBAL_HEADER; } if (pCodec != null) { ffmpeg.avcodec_open2(pCodecContext, pCodec, opts).ThrowExceptionIfError(); } } }
public static MediaEncode CreateEncode(AVCodecID codecId, int flags, Action <MediaCodec> setBeforeOpen = null, MediaDictionary opts = null) { MediaEncode encode = new MediaEncode(codecId); encode.Initialize(setBeforeOpen, flags, opts); return(encode); }
public abstract int Initialize(Action <MediaCodec> setBeforeOpen = null, int flags = 0, MediaDictionary opts = null);
/// <summary> /// write to stream,default buffersize 4096 /// </summary> /// <param name="stream"></param> /// <param name="oformat"></param> /// <param name="options"></param> public MediaWriter(Stream stream, OutFormat oformat, MediaDictionary options = null) : this(stream, 4096, oformat, options) { }