Exemplo n.º 1
0
        public static AVCodecCfg CreateAudio(int channels, int sample_rate, int codec_id = (int)AVCode.CODEC_ID_H264, int bit_rate = 64000)
        {
            var r = new AVCodecCfg();

            r.codec_id      = codec_id;
            r.codec_type    = (int)AVCode.CODEC_TYPE_AUDIO;
            r.bit_rate      = bit_rate;
            r.time_base_den = 0;
            r.time_base_num = 0;
            r.gop_size      = 0;
            r.pix_fmt       = 0;
            r.max_b_frames  = 0;
            r.sample_rate   = sample_rate;
            r.channels      = channels;
            return(r);
        }
Exemplo n.º 2
0
        public static AVCodecCfg CreateVideo(int width, int height, int codec_id = (int)AVCode.CODEC_ID_H264, int bit_rate = 98000)
        {
            var r = new AVCodecCfg
            {
                codec_id      = codec_id,
                width         = width,
                height        = height,
                codec_type    = (int)AVCode.CODEC_TYPE_VIDEO,
                bit_rate      = bit_rate,
                time_base_den = 15,
                time_base_num = 2,
                gop_size      = 15,
                pix_fmt       = (int)AVCode.PIX_FMT_YUV420P
            };

            return(r);
        }
Exemplo n.º 3
0
        public FFImp(AVCodecCfg cfg, bool isDec, bool isvideo = true)
        {
            this.isDec = isDec;
            this.cfg   = cfg;
            var pcfg = FunctionEx.StructToIntPtr(cfg);

            pAVObj = FunctionEx.StructToIntPtr(new AVModel());
            lock (_lock) {
                if (!ffimp_init())
                {
                    throw new Exception("ffimp init error");
                }
            }
            if (isvideo)
            {
                int pOutBufSize = cfg.width * cfg.height * 3;
                if (pOutBufSize == 0)
                {
                    pOutBufSize = 1920 * 1080 * 4;
                }
                pOutBuf = Marshal.AllocHGlobal(pOutBufSize);
                int init_r = 0;
                lock (_lock)
                {
                    if (this.isDec)
                    {
                        init_r = ffimp_video_decode_init(ref pAVObj, pcfg, pOutBuf, pOutBufSize);
                    }
                    else
                    {
                        init_r = ffimp_video_encode_init(ref pAVObj, pcfg, pOutBuf, pOutBufSize);
                    }

                    _ffscale = new FFScale(cfg.width, cfg.height, 0, 12, cfg.width, cfg.height, 0, 12);
                }
            }
            else
            {
                int pOutBufSize = cfg.width * cfg.height * 3;
                if (pOutBufSize == 0)
                {
                    pOutBufSize = 2048 * 2;
                }
                pOutBuf = Marshal.AllocHGlobal(pOutBufSize);
                int init_r = 0;
                lock (_lock)
                {
                    if (this.isDec)
                    {
                        init_r = ffimp_audio_decode_init(ref pAVObj, pcfg, pOutBuf, pOutBufSize);
                    }
                    else
                    {
                        init_r = ffimp_audio_decode_init(ref pAVObj, pcfg, pOutBuf, pOutBufSize);
                    }

                    //  _ffscale = new FFScale(cfg.width, cfg.height, 0, 12, cfg.width, cfg.height, 0, 12);
                }
            }
            Marshal.FreeHGlobal(pcfg);
        }