public static extern int av_picture_pad(AVPicture* dst, AVPicture* src, int height, int width, AVPixelFormat pix_fmt, int padtop, int padbottom, int padleft, int padright, int* color);
 public static extern void av_picture_copy(AVPicture* dst, AVPicture* src, AVPixelFormat pix_fmt, int width, int height);
 public static extern int av_picture_crop(AVPicture* dst, AVPicture* src, AVPixelFormat pix_fmt, int top_band, int left_band);
 public static extern int avpicture_layout(AVPicture* src, AVPixelFormat pix_fmt, int width, int height, sbyte* dest, int dest_size);
 public static extern int avpicture_deinterlace(AVPicture* dst, AVPicture* src, AVPixelFormat pix_fmt, int width, int height);
 public static extern void avpicture_free(AVPicture* picture);
 public static extern int avpicture_fill(AVPicture* picture, byte* ptr, AVPixelFormat pix_fmt, int width, int height);
Esempio n. 8
0
        private unsafe static Bitmap ExtractNextImage(AVFormatContext* pFormatContext, AVCodecContext* pCodecContext, AVPacket* pPacket, AVStream* vidStream, SwsContext* pConvertContext, AVFrame* pDecodedFrame, AVPicture* pConvertedFrame, int width, int height, bool createCopy, double timeBase, out TimeSpan pos)
        {
            pos = new TimeSpan();
            Bitmap result = null;

            int gotPicture = 0;

            while (gotPicture != 1)
            {
                if (ffmpeg.av_read_frame(pFormatContext, pPacket) < 0)
                {
                    result = null;
                    break;
                }

                if (pPacket->stream_index != vidStream->index)
                    continue;

                gotPicture = 0;
                int size = ffmpeg.avcodec_decode_video2(pCodecContext, pDecodedFrame, &gotPicture, pPacket);
                if (size < 0)
                    throw new Exception("Error while decoding frame!");

                if (gotPicture == 1)
                {
                    // Get current position from frame
                    pos = ToTimeSpan(ffmpeg.av_frame_get_best_effort_timestamp(pDecodedFrame), timeBase);

                    // Extract image
                    sbyte** src = &pDecodedFrame->data0;
                    sbyte** dst = &pConvertedFrame->data0;
                    ffmpeg.sws_scale(pConvertContext, src, pDecodedFrame->linesize, 0, height, dst, pConvertedFrame->linesize);
                    var imageBufferPtr = new IntPtr(pConvertedFrame->data0);
                    int linesize = pConvertedFrame->linesize[0];
                    Bitmap img = new Bitmap(width, height, linesize, PixelFormat.Format24bppRgb, imageBufferPtr);

                    result = createCopy ? new Bitmap(img) : img;
                }

            }

            return result;
        }
 public static extern int avpicture_alloc(AVPicture* picture, AVPixelFormat pix_fmt, int width, int height);
Esempio n. 10
0
 public static extern int av_picture_crop(AVPicture* @dst, AVPicture* @src, AVPixelFormat @pix_fmt, int @top_band, int @left_band);
Esempio n. 11
0
 public static extern int av_picture_pad(AVPicture* @dst, AVPicture* @src, int @height, int @width, AVPixelFormat @pix_fmt, int @padtop, int @padbottom, int @padleft, int @padright, int* @color);
Esempio n. 12
0
 public static extern void av_picture_copy(AVPicture* @dst, AVPicture* @src, AVPixelFormat @pix_fmt, int @width, int @height);
Esempio n. 13
0
 public static extern int avpicture_layout(AVPicture* @src, AVPixelFormat @pix_fmt, int @width, int @height, sbyte* @dest, int @dest_size);
Esempio n. 14
0
 public static extern int avpicture_fill(AVPicture* @picture, sbyte* @ptr, AVPixelFormat @pix_fmt, int @width, int @height);
Esempio n. 15
0
        private unsafe Bitmap ExtractNextImage2(AVCodecContext* pCodecContext, AVPacket* pPacket, AVStream* vidStream, SwsContext* pConvertContext, AVFrame* pDecodedFrame, AVPicture* pConvertedFrame, int width, int height, bool createCopy, double timeBase, int? delay, TimeSpan prev, out TimeSpan pos, out bool end)
        {
            pos = new TimeSpan();
            end = false;
            Bitmap result = null;

            int gotPicture = 0;

            while (gotPicture != 1)
            {
                if (ffmpeg.av_read_frame(this.AVFormatContext, pPacket) < 0)
                {
                    end = true;
                    result = null;
                    break;
                }

                if (pPacket->stream_index != vidStream->index)
                    continue;

                gotPicture = 0;
                int size = ffmpeg.avcodec_decode_video2(pCodecContext, pDecodedFrame, &gotPicture, pPacket);
                if (size < 0)
                    throw new Exception("Error while decoding frame!");

                if (gotPicture == 1)
                {
                    // Get current position from frame
                    pos = ToTimeSpan(ffmpeg.av_frame_get_best_effort_timestamp(pDecodedFrame), timeBase);

                    if (delay.HasValue && prev != TimeSpan.Zero && (pos - prev).TotalMilliseconds < delay)
                    {
                        return null;
                    }

                    // Extract image
                    sbyte** src = &pDecodedFrame->data0;
                    sbyte** dst = &pConvertedFrame->data0;
                    int src_height = pCodecContext->height;
                    ffmpeg.sws_scale(pConvertContext, src, pDecodedFrame->linesize, 0, src_height, dst, pConvertedFrame->linesize);
                    var imageBufferPtr = new IntPtr(pConvertedFrame->data0);
                    int linesize = pConvertedFrame->linesize[0];
                    result = new Bitmap(width, height, linesize, PixelFormat.Format24bppRgb, imageBufferPtr);
                }

            }

            return result;
        }
 public static extern int avpicture_deinterlace(AVPicture* @dst, AVPicture* @src, AVPixelFormat @pix_fmt, int @width, int @height);