示例#1
0
        public VideoEncoder(AVCodecID codecID, VideoFormat format, VideoEncoderParameters encoderParams = null) : base(codecID)
        {
            encoderParams = encoderParams ?? VideoEncoderParameters.Default;
            if (codec->Type != AVMediaType.Video)
            {
                throw new ArgumentException($"{codecID}不是视频格式", nameof(codecID));
            }

            codecContext = FF.avcodec_alloc_context3(codec);
            if (codecContext == null)
            {
                throw new Exception("无法分配编码器上下文");
            }

            InFormat = format;
            Init(encoderParams);
        }
示例#2
0
        public AudioEncoder(AVCodecID codecID, AudioFormat inFormat, BitRate bitRate) : base(codecID)
        {
            try {
                if (codec->Type != AVMediaType.Audio)
                {
                    throw new ArgumentException($"{codecID}不是音频格式", nameof(codecID));
                }

                codecContext = FF.avcodec_alloc_context3(codec);
                if (codecContext == null)
                {
                    throw new Exception("无法分配编码器上下文");
                }

                InFormat = inFormat;
                Init(codecID, bitRate);
            } catch {
                Dispose();
                throw;
            }
        }