예제 #1
0
        public VideoEncoder(int width, int height, int fps)
        {
            _converter = new VideoConverter(CODEC_PIXEL_FORMAT);

            AVCodec* codec = FFmpegInvoke.avcodec_find_encoder(CODEC_ID);
            if (codec == null) throw new Exception("Codec not found");

            _codec_context = FFmpegInvoke.avcodec_alloc_context3(codec);
            if (_codec_context == null) throw new Exception("Could not allocate video codec context");

            _codec_context->bit_rate = 50000;
            _codec_context->width = width;
            _codec_context->height = height;
            _codec_context->time_base = new AVRational() { num = 1, den = fps };
            _codec_context->gop_size = 10; // emit one intra frame every ten frames
            _codec_context->max_b_frames = 1;
            _codec_context->pix_fmt = CODEC_PIXEL_FORMAT;
            FFmpegInvoke.av_opt_set(_codec_context->priv_data, "preset", "fast", 0);
            if (FFmpegInvoke.avcodec_open2(_codec_context, codec, null) < 0) throw new Exception("Could not open codec");

            _avFrameYUV = FFmpegInvoke.avcodec_alloc_frame();
            if (_avFrameYUV == null) throw new Exception("Could not allocate video frame");
            _avFrameYUV->format = (int)CODEC_PIXEL_FORMAT;
            _avFrameYUV->width = width;
            _avFrameYUV->height = height;

            var ret1 = FFmpegInvoke.av_image_alloc(&_avFrameYUV->data_0, _avFrameYUV->linesize, width, height, CODEC_PIXEL_FORMAT, 32);
            if (ret1 < 0) throw new Exception("Could not allocate raw picture buffer");

            _avFrameBGR = FFmpegInvoke.avcodec_alloc_frame();
            if (_avFrameBGR == null) throw new Exception("Could not allocate video frame");
            _avFrameBGR->format = (int)INPUT_PIXEL_FORMAT;
            _avFrameBGR->width = width;
            _avFrameBGR->height = height;

            var ret2 = FFmpegInvoke.av_image_alloc(&_avFrameBGR->data_0, _avFrameBGR->linesize, width, height, INPUT_PIXEL_FORMAT, 32);
            if (ret2 < 0) throw new Exception("Could not allocate raw picture buffer");
        }
예제 #2
0
 public static extern int av_compare_ts(long ts_a, AVRational tb_a, long ts_b, AVRational tb_b);
예제 #3
0
 public static extern long av_rescale_q_rnd(long a, AVRational bq, AVRational cq, AVRounding p3);
예제 #4
0
파일: Rational.cs 프로젝트: inrg/FFSharp
        /// <summary>
        /// Initialize a <see cref="Rational"/>.
        /// </summary>
        /// <param name="AValue">The <see cref="Unsafe.AVRational"/>.</param>
        internal Rational(Unsafe.AVRational AValue)
        {
            Value = AValue;

            Reduce(ref this);
        }
예제 #5
0
 public static extern void av_stream_set_r_frame_rate(AVStream* s, AVRational r);
예제 #6
0
 public static extern int av_opt_set_video_rate(void* obj, String name, AVRational val, int search_flags);
예제 #7
0
 public static extern AVOption* av_set_q(void* obj, String name, AVRational n);
예제 #8
0
 public static extern void av_codec_set_pkt_timebase(AVCodecContext* avctx, AVRational val);
예제 #9
0
 public static extern AVRational av_div_q(AVRational b, AVRational c);
예제 #10
0
 public static extern AVRational av_mul_q(AVRational b, AVRational c);
예제 #11
0
 private static string ToDescString(AVRational value)
 {
     double dVal = Math.Floor(ToDouble(value) * 10.0) / 10;
     return dVal.ToString();
 }
예제 #12
0
 private static double ToDouble(AVRational value)
 {
     return Convert.ToDouble(value.num) / Convert.ToDouble(value.den);
 }
예제 #13
0
 /// <summary>
 /// Converts seconds to a timestamp value.
 /// </summary>
 /// <param name="seconds">The seconds.</param>
 /// <param name="streamTimeBase">The stream time base.</param>
 /// <returns></returns>
 public static long SecondsToTimestamp(decimal seconds, AVRational streamTimeBase)
 {
     return Convert.ToInt64(Convert.ToDouble(seconds) * Convert.ToDouble(streamTimeBase.den) / Convert.ToDouble(streamTimeBase.num));
 }
예제 #14
0
 /// <summary>
 /// Converts a Timestamp to seconds.
 /// </summary>
 /// <param name="ts">The ts.</param>
 /// <param name="streamTimeBase">The stream time base.</param>
 /// <returns></returns>
 public static decimal TimestampToSeconds(long ts, AVRational streamTimeBase)
 {
     return Convert.ToDecimal(Convert.ToDouble(ts) * Convert.ToDouble(streamTimeBase.num) / Convert.ToDouble(streamTimeBase.den));
 }
예제 #15
0
 private double q2d(AVRational r)
 {
     return (double)r.num / (double)r.den;
 }
예제 #16
0
 public static extern long av_rescale_delta(AVRational in_tb, long in_ts, AVRational fs_tb, int duration, long* last, AVRational out_tb);
예제 #17
0
 public static extern long av_add_stable(AVRational ts_tb, long ts, AVRational inc_tb, long inc);
예제 #18
0
 public static extern AVRational av_add_q(AVRational b, AVRational c);
예제 #19
0
 public static extern void av_packet_rescale_ts(AVPacket* pkt, AVRational tb_src, AVRational tb_dst);
예제 #20
0
 public static extern AVRational av_sub_q(AVRational b, AVRational c);
예제 #21
0
 public static extern int av_opt_eval_q(void* obj, AVOption* o, String val, AVRational* q_out);
예제 #22
0
 public static extern int av_nearer_q(AVRational q, AVRational q1, AVRational q2);
예제 #23
0
 public static extern int av_opt_get_video_rate(void* obj, String name, int search_flags, AVRational* out_val);
예제 #24
0
 public static extern int av_find_nearest_q_idx(AVRational q, AVRational* q_list);
예제 #25
0
 public static extern int av_image_check_sar(int w, int h, AVRational sar);
예제 #26
0
 public static extern long av_rescale_q(long a, AVRational bq, AVRational cq);