VideoStream.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #ifndef VIDEO_STREAM_H_
  2. #define VIDEO_STREAM_H_
  3. #define FFMPEG_ENABLED
  4. #ifdef FFMPEG_ENABLED
  5. #include <stdexcept>
  6. #include <string>
  7. #include "Bitmap.h"
  8. extern "C" {
  9. # include <libavformat/avformat.h>
  10. # include <libavformat/avio.h>
  11. # include <libavcodec/avcodec.h>
  12. # include <libavformat/avformat.h>
  13. # include <libavutil/imgutils.h>
  14. # include <libavutil/opt.h>
  15. # include <libswscale/swscale.h>
  16. }
  17. namespace alm
  18. {
  19. struct VideoExportException;
  20. }
  21. struct alm::VideoExportException :
  22. public std::runtime_error
  23. {
  24. VideoExportException(const std::string& err);
  25. };
  26. class VideoStream
  27. {
  28. const AVCodec* codec;
  29. AVCodecContext* codecContext;
  30. AVFormatContext* formatContext;
  31. AVCodecParameters* params;
  32. //FILE* file;
  33. AVFrame* picture;
  34. AVPacket* pkt;
  35. AVStream* stream;
  36. SwsContext* swsContext;
  37. int width;
  38. int height;
  39. int fps;
  40. int64_t frameIndex = 0;
  41. public:
  42. VideoStream(int width, int height, const std::string& filename, int bitrate, int fps, const char* preset);
  43. ~VideoStream(void);
  44. void addFrame(const Bitmap<RGBColor>& frame);
  45. private:
  46. void encode(AVFrame* frame);
  47. };
  48. #endif // FFMPEG_ENABLED
  49. #endif // VIDEO_STREAM_H_