コード例 #1
0
ファイル: MediaWriter.cs プロジェクト: sdcb/EmguFFmpeg
 /// <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());
     }
 }
コード例 #2
0
ファイル: MediaFilterContext.cs プロジェクト: sdcb/EmguFFmpeg
 public void Init(MediaDictionary options)
 {
     unsafe
     {
         ffmpeg.avfilter_init_dict(pFilterContext, options).ThrowExceptionIfError();
     }
 }
コード例 #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)
        {
            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
                    });
                }
            }
        }
コード例 #4
0
ファイル: MediaReader.cs プロジェクト: stephan27/EmguFFmpeg
        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
                });
            }
        }
コード例 #5
0
        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));
        }
コード例 #6
0
        /// <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();
            }
        }
コード例 #7
0
ファイル: MediaWriter.cs プロジェクト: stephan27/EmguFFmpeg
 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);
     }
 }
コード例 #8
0
ファイル: MediaDevice.cs プロジェクト: geedrius/EmguFFmpeg
        /// <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);
        }
コード例 #9
0
ファイル: MediaEncoder.cs プロジェクト: geedrius/EmguFFmpeg
 /// <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"/> &amp; <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());
 }
コード例 #10
0
ファイル: MediaDecoder.cs プロジェクト: geedrius/EmguFFmpeg
        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);
        }
コード例 #11
0
ファイル: MediaDictionary.cs プロジェクト: IOL0ol1/EmguFFmpeg
 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));
 }
コード例 #12
0
ファイル: MediaReader.cs プロジェクト: geedrius/EmguFFmpeg
 /// <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)
 {
 }
コード例 #13
0
ファイル: MediaDevice.cs プロジェクト: stephan27/EmguFFmpeg
        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> >());
        }
コード例 #14
0
ファイル: MediaEncoder.cs プロジェクト: geedrius/EmguFFmpeg
        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);
        }
コード例 #15
0
ファイル: MediaWriter.cs プロジェクト: stephan27/EmguFFmpeg
 /// <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();
 }
コード例 #16
0
 /// <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();
     }
 }
コード例 #17
0
        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);
        }
コード例 #18
0
ファイル: MediaEncode.cs プロジェクト: sdcb/EmguFFmpeg
 /// <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"/> &amp; <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();
         }
     }
 }
コード例 #19
0
ファイル: MediaEncode.cs プロジェクト: sdcb/EmguFFmpeg
        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);
        }
コード例 #20
0
 public abstract int Initialize(Action <MediaCodec> setBeforeOpen = null, int flags = 0, MediaDictionary opts = null);
コード例 #21
0
 /// <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)
 {
 }