コード例 #1
0
        /// <summary>
        /// Constructs a new VideoDecoderStream over a specific filename.
        /// </summary>
        /// <param name="Filename">File to decode</param>
        internal VideoDecoderStream(MediaFileReader file, ref AVStream stream)
            : base(file, ref stream)
        {
            // allocate video frame
            m_avFrame = FFmpeg.avcodec_alloc_frame();
            if (FFmpeg.avpicture_alloc(out m_avPicture, m_avCodecCtx.pix_fmt, m_avCodecCtx.width, m_avCodecCtx.height) != 0)
                throw new DecoderException("Error allocating AVPicture");
            m_avPicture_allocated = true;

            int buffersize = FFmpeg.avpicture_get_size(m_avCodecCtx.pix_fmt, m_avCodecCtx.width, m_avCodecCtx.height);
            if (buffersize <= 0)
                throw new DecoderException("Invalid size returned by avpicture_get_size");

            m_buffer = new byte[buffersize];
        }
コード例 #2
0
        public DecoderStream(MediaFile file, ref AVStream stream)
        {
            // Initialize instance variables
            m_disposed = false;
            m_position = m_bufferUsedSize = 0;
            m_file = file;
            m_avStream = stream;

            m_avCodecCtx = *m_avStream.codec;

            // Open the decoding codec
            AVCodec* avCodec = FFmpeg.avcodec_find_decoder(m_avCodecCtx.codec_id);
            if (avCodec == null)
                throw new DecoderException("No decoder found");

            if (FFmpeg.avcodec_open(ref m_avCodecCtx, avCodec) < 0)
                throw new DecoderException("Error opening codec");

            m_codecOpen = true;
        }
コード例 #3
0
ファイル: AVFormat.cs プロジェクト: nasojlsu/CasparCGPlayout
 public static extern void av_update_cur_dts(ref AVFormatContext pAVFormatContext, ref AVStream pAVStream, long timestamp);
コード例 #4
0
ファイル: AVFormat.cs プロジェクト: nasojlsu/CasparCGPlayout
 public static extern void av_set_pts_info(ref AVStream pAVStream, int pts_wrap_bits, int pts_num, int pts_den);
コード例 #5
0
ファイル: AVFormat.cs プロジェクト: nasojlsu/CasparCGPlayout
 public static extern AVError av_index_search_timestamp(ref AVStream pAVStream, long timestamp, AVSEEK_FLAG flags);
コード例 #6
0
ファイル: AVFormat.cs プロジェクト: nasojlsu/CasparCGPlayout
 public static extern AVError av_add_index_entry(ref AVStream pAVStream, long pos, long timestamp, int size, int distance, AVSEEK_FLAG flags);
コード例 #7
0
ファイル: AVFormat.cs プロジェクト: NichUK/ffmpeg-shard
 public static extern void av_pkt_dump2(IntPtr pFile, ref AVPacket pAVPacket, [MarshalAs(UnmanagedType.Bool)] bool dump_payload, ref AVStream stream);
コード例 #8
0
 internal AudioDecoderStream(MediaFile file, ref AVStream stream)
     : base(file, ref stream)
 {
     m_buffer = new byte[FFmpeg.AVCODEC_MAX_AUDIO_FRAME_SIZE];
 }
コード例 #9
0
        public AudioEncoderStream(string Filename, EncoderInformation EncoderInfo)
        {
            // Initialize instance variables
            m_filename = Filename;
            m_disposed = m_fileOpen = false;
            m_buffer = new FifoMemoryStream();

            // Open FFmpeg
            FFmpeg.av_register_all();

            // Initialize the output format context
            m_avFormatCtx = FFmpeg.av_alloc_format_context();

            // Get output format
            m_avFormatCtx.oformat = FFmpeg.guess_format(EncoderInfo.Codec.ShortName, null, null);
            if (m_avFormatCtx.oformat != null)
                throw new EncoderException("Could not find output format.");

            FFmpeg.av_set_parameters(ref m_avFormatCtx, null);

            // Initialize the new output stream
            AVStream* stream = FFmpeg.av_new_stream(ref m_avFormatCtx, 1);
            if (stream == null)
                throw new EncoderException("Could not alloc output audio stream");

            m_avStream = *stream;

            // Initialize output codec context
            m_avCodecCtx = *m_avStream.codec;

            m_avCodecCtx.codec_id = EncoderInfo.Codec.CodecID;
            m_avCodecCtx.codec_type = CodecType.CODEC_TYPE_AUDIO;
            m_avCodecCtx.sample_rate = EncoderInfo.SampleRate;
            m_avCodecCtx.channels = EncoderInfo.Channels;
            m_avCodecCtx.bits_per_sample = EncoderInfo.SampleSize;
            m_avCodecCtx.bit_rate = EncoderInfo.Bitrate;

            if (EncoderInfo.VBR)
            {
                m_avCodecCtx.flags |= FFmpeg.CODEC_FLAG_QSCALE;
                m_avCodecCtx.global_quality = EncoderInfo.FFmpegQualityScale;
            }

            // Open codec
            AVCodec* outCodec = FFmpeg.avcodec_find_encoder(m_avCodecCtx.codec_id);
            if (outCodec == null)
                throw new EncoderException("Could not find encoder");

            if (FFmpeg.avcodec_open(ref m_avCodecCtx, outCodec) < 0)
                throw new EncoderException("Could not open codec.");

            // Open and prep file
            if (FFmpeg.url_fopen(ref m_avFormatCtx.pb, m_filename, FFmpeg.URL_WRONLY) < 0)
                throw new EncoderException("Could not open output file.");

            m_fileOpen = true;

            FFmpeg.av_write_header(ref m_avFormatCtx);
        }