Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef PANGOLIN_FFMPEG_H
00029 #define PANGOLIN_FFMPEG_H
00030
00031 #include <pangolin/pangolin.h>
00032 #include <pangolin/video.h>
00033
00034 extern "C"
00035 {
00036
00037
00038 #ifndef INT64_C
00039 #define INT64_C(c) (c ## LL)
00040 #define UINT64_C(c) (c ## ULL)
00041 #endif
00042
00043 #include <avformat.h>
00044 #include <swscale.h>
00045 #include <pixdesc.h>
00046 }
00047
00048 namespace pangolin
00049 {
00050
00051 class FfmpegVideo : public VideoInterface
00052 {
00053 public:
00054 FfmpegVideo(const std::string filename, const std::string fmtout = "RGB24", const std::string codec_hint = "", bool dump_info = false, int user_video_stream = -1);
00055 ~FfmpegVideo();
00056
00058 void Start();
00059
00061 void Stop();
00062
00063 unsigned Width() const;
00064
00065 unsigned Height() const;
00066
00067 size_t SizeBytes() const;
00068
00069 std::string PixFormat() const;
00070
00071 bool GrabNext( unsigned char* image, bool wait = true );
00072
00073 bool GrabNewest( unsigned char* image, bool wait = true );
00074
00075 protected:
00076 void InitUrl(const std::string filename, const std::string fmtout = "RGB24", const std::string codec_hint = "", bool dump_info = false , int user_video_stream = -1);
00077
00078 SwsContext *img_convert_ctx;
00079 AVFormatContext *pFormatCtx;
00080 int videoStream;
00081 int audioStream;
00082 AVCodecContext *pVidCodecCtx;
00083 AVCodecContext *pAudCodecCtx;
00084 AVCodec *pVidCodec;
00085 AVCodec *pAudCodec;
00086 AVFrame *pFrame;
00087 AVFrame *pFrameOut;
00088 AVPacket packet;
00089 int numBytesOut;
00090 uint8_t *buffer;
00091 PixelFormat fmtout;
00092 };
00093
00094 enum FfmpegMethod
00095 {
00096 FFMPEG_FAST_BILINEAR = 1,
00097 FFMPEG_BILINEAR = 2,
00098 FFMPEG_BICUBIC = 4,
00099 FFMPEG_X = 8,
00100 FFMPEG_POINT = 0x10,
00101 FFMPEG_AREA = 0x20,
00102 FFMPEG_BICUBLIN = 0x40,
00103 FFMPEG_GAUSS = 0x80,
00104 FFMPEG_SINC =0x100,
00105 FFMPEG_LANCZOS =0x200,
00106 FFMPEG_SPLINE =0x400
00107 };
00108
00109 class FfmpegConverter : public VideoInterface
00110 {
00111 public:
00112 FfmpegConverter(VideoInterface* videoin, const std::string pixelfmtout = "RGB24", FfmpegMethod method = FFMPEG_POINT);
00113 ~FfmpegConverter();
00114
00115 void Start();
00116 void Stop();
00117 unsigned Width() const;
00118 unsigned Height() const;
00119 size_t SizeBytes() const;
00120 std::string PixFormat() const;
00121
00122 bool GrabNext( unsigned char* image, bool wait = true );
00123 bool GrabNewest( unsigned char* image, bool wait = true );
00124
00125 protected:
00126 VideoInterface* videoin;
00127 SwsContext *img_convert_ctx;
00128
00129 PixelFormat fmtsrc;
00130 PixelFormat fmtdst;
00131 AVFrame* avsrc;
00132 AVFrame* avdst;
00133 uint8_t* bufsrc;
00134 uint8_t* bufdst;
00135 int numbytessrc;
00136 int numbytesdst;
00137 unsigned w,h;
00138 };
00139
00140 }
00141
00142 #endif //PANGOLIN_FFMPEG_H