Пример #1
0
        public EncodingInfo GetCodecInfo()
        {
            EncodingInfo icodecInfo = new EncodingInfo();

            icodecInfo.Width  = iCodecContext->width;
            icodecInfo.Height = iCodecContext->height;
            icodecInfo.Sample_aspect_ratio = iCodecContext->sample_aspect_ratio;
            icodecInfo.Timebase            = iCodecContext->time_base;
            icodecInfo.Framerate           = iCodecContext->framerate;

            return(icodecInfo);
        }
Пример #2
0
        public void OpenOutputURL(string fileName, EncodingInfo enCodecInfo)
        {
            AVStream *out_stream;
            AVCodec * encoder;

            int ret;

            //output file
            var _oFormatContext = oFormatContext;

            ffmpeg.avformat_alloc_output_context2(&_oFormatContext, null, null, fileName);

            encoder = ffmpeg.avcodec_find_encoder(AVCodecID.AV_CODEC_ID_H264);

            out_stream = ffmpeg.avformat_new_stream(_oFormatContext, encoder);

            oCodecContext = ffmpeg.avcodec_alloc_context3(encoder);
            oCodecContext = out_stream->codec;

            oCodecContext->height = enCodecInfo.Height;
            oCodecContext->width  = enCodecInfo.Width;
            oCodecContext->sample_aspect_ratio = enCodecInfo.Sample_aspect_ratio;
            oCodecContext->pix_fmt             = encoder->pix_fmts[0];
            oCodecContext->time_base           = enCodecInfo.Timebase;
            oCodecContext->framerate           = ffmpeg.av_inv_q(enCodecInfo.Framerate);

            if ((_oFormatContext->oformat->flags & ffmpeg.AVFMT_GLOBALHEADER) != 0)
            {
                oCodecContext->flags |= ffmpeg.AV_CODEC_FLAG_GLOBAL_HEADER;
            }

            //open codecd
            ret = ffmpeg.avcodec_open2(oCodecContext, encoder, null).ThrowExceptionIfError();

            ret = ffmpeg.avcodec_parameters_from_context(out_stream->codecpar, oCodecContext);
            out_stream->time_base = oCodecContext->time_base;

            //Show some Information
            ffmpeg.av_dump_format(_oFormatContext, 0, fileName, 1);

            if (ffmpeg.avio_open(&_oFormatContext->pb, fileName, ffmpeg.AVIO_FLAG_WRITE) < 0)
            {
                Console.WriteLine("Failed to open output file! \n");
            }

            //Write File Header
            int error = ffmpeg.avformat_write_header(_oFormatContext, null);

            error.ThrowExceptionIfError();

            oFormatContext = _oFormatContext;
        }