public DecoderStream(MediaFile file, 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;
        }
Exemple #2
0
 public static extern int av_parser_change(ref AVCodecParserContext pAVCodecParserContext,
     ref AVCodecContext pAVCodecContext,
     ref byte[] poutbuf, ref int poutbuf_size,
     byte[] buf, int buf_size, int keyframe);
Exemple #3
0
 public static extern int avcodec_thread_execute(ref AVCodecContext pAVCodecContext,
     [MarshalAs(UnmanagedType.FunctionPtr)]FuncCallback func,
     void** arg, ref int ret, int count);
Exemple #4
0
 public static extern int avcodec_thread_init(ref AVCodecContext pAVCodecContext, int thread_count);
Exemple #5
0
 public static extern int avcodec_open(ref AVCodecContext pAVCodecContext, AVCodec* pAVCodec);
Exemple #6
0
 public static extern void avcodec_set_dimensions(ref AVCodecContext pAVCodecContext, int width, int height);
Exemple #7
0
 public static extern int avcodec_decode_subtitle(ref AVCodecContext pAVCodecContext, ref AVSubtitle pAVSubtitle,
     [MarshalAs(UnmanagedType.Bool)]out bool got_sub_ptr, byte[] buf, int buf_size);
Exemple #8
0
 public static extern void avcodec_flush_buffers(ref AVCodecContext pAVCodecContext);
Exemple #9
0
 public static extern int avcodec_decode_audio2(ref AVCodecContext avctx, [In, Out]short[] samples,
     ref int frame_size_ptr, byte[] buf, int buf_size);
Exemple #10
0
 public static unsafe extern int avcodec_decode_audio2(ref AVCodecContext avctx, short* samples,
     ref int frame_size_ptr, byte* buf, int buf_size);
Exemple #11
0
 public static extern int avcodec_close(ref AVCodecContext pAVCodecContext);
Exemple #12
0
 public static extern void avcodec_align_dimensions(ref AVCodecContext pAVCodecContext, ref int width, ref int height);
Exemple #13
0
 public static extern int avcodec_decode_video(ref AVCodecContext pAVCodecContext, AVFrame* pAVFrame,
                                               [MarshalAs(UnmanagedType.Bool)]out bool got_picture_ptr,
                                               byte* buf, int buf_size);
Exemple #14
0
 public static extern int avcodec_encode_subtitle(ref AVCodecContext pAVCodecContext, [In, Out]byte[] buf, int buf_size,
     ref AVSubtitle pAVSubtitle);
Exemple #15
0
 public static extern int avcodec_decode_video2(ref AVCodecContext pAVCodecContext, AVFrame* pAVFrame,
     [MarshalAs(UnmanagedType.Bool)]out bool got_picture_ptr,
     ref AVPacket packet);
Exemple #16
0
 public static extern int avcodec_encode_video(ref AVCodecContext pAVCodecContext, [In, Out]byte[] buf, int buf_size,
     ref AVFrame pAVFrame);
Exemple #17
0
 public static extern void avcodec_default_free_buffers(ref AVCodecContext pAVCodecContext);
Exemple #18
0
 public static extern void avcodec_get_context_defaults(ref AVCodecContext pAVCodecContext);
Exemple #19
0
 public static extern int avcodec_default_get_buffer(ref AVCodecContext pAVCodecContext, ref AVFrame pAVFrame);
Exemple #20
0
 public static extern int avcodec_parse_frame(ref AVCodecContext pAVCodecContext,
     ref byte[] pdata,
     ref int data_size_ptr, byte[] buf, int buf_size);
Exemple #21
0
 public static extern PixelFormat avcodec_default_get_format(ref AVCodecContext pAVCodecContext, ref PixelFormat fmt);
Exemple #22
0
 public static extern void avcodec_string(string name, int buf_size,
     ref AVCodecContext pAVCodeContext, int encode);
Exemple #23
0
 public static extern void avcodec_default_release_buffer(ref AVCodecContext pAVCodecContext, ref AVFrame pAVFrame);
Exemple #24
0
 public static extern void avcodec_thread_free(ref AVCodecContext pAVCodecContext);
Exemple #25
0
 public static extern int avcodec_encode_audio(ref AVCodecContext pAVCodecContext, [In, Out]byte[] buf, int buf_size,
     short[] samples);
Exemple #26
0
 public static extern int av_bitstream_filter_filter(ref AVBitStreamFilterContext pAVBitStreamFilterContext,
     ref AVCodecContext pAVCodecContext,
     string args,
     ref byte[] poutbuf,
     ref int poutbuf_size, byte[] buf, int buf_size, int keyframe);
Exemple #27
0
 public static extern int avcodec_encode_audio(ref AVCodecContext pAVCodecContext, byte* buf, int buf_size, short* samples);
Exemple #28
0
 public static extern int av_parser_parse(ref AVCodecParserContext pAVCodecParserContext,
     ref AVCodecContext pAVCodecContext,
     ref byte[] poutbuf, ref int poutbuf_size,
     byte[] buf, int buf_size, long pts, long dts);
        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);
        }