FFmpegWriter.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // FFmpegWriter.h: interface for the FFmpegWriter class.
  2. #pragma once
  3. #ifndef INT64_C
  4. #define INT64_C(c) (c##LL)
  5. #define UINT64_C(c) (c##UL)
  6. #endif
  7. #ifdef __cplusplus
  8. extern "C"
  9. {
  10. //#define __STDC_CONSTANT_MACROS
  11. #define __STDC_FORMAT_MACROS
  12. #endif // __cplusplus
  13. #include <libavutil/avassert.h>
  14. #include <libavutil/channel_layout.h>
  15. #include <libavutil/opt.h>
  16. #include <libavutil/mathematics.h>
  17. #include <libavutil/timestamp.h>
  18. #include <libavformat/avformat.h>
  19. #include <libswscale/swscale.h>
  20. #include <libswresample/swresample.h>
  21. #include <libavutil/pixdesc.h>
  22. #ifdef __cplusplus
  23. }
  24. #endif // __cplusplus
  25. #include "ByteBuffer.h"
  26. typedef struct OutputStream_t OutputStream;
  27. class LogApi
  28. {
  29. public:
  30. virtual void Debug(const char* fmt, ...) = 0;
  31. virtual void vDebug(const char* str, va_list list) = 0;
  32. };
  33. class FFmpegWriter
  34. {
  35. public:
  36. FFmpegWriter(LogApi* pLogAPI) {m_pLogApi = pLogAPI; m_video_st = NULL; m_audio_st = NULL; m_outfmt = NULL; m_formatctx = NULL;
  37. m_audio_codec = NULL; m_video_codec = NULL; m_bhave_video = false; m_bhave_audio = false; m_audio_input_buffer = NULL; m_bstart = false;}
  38. ~FFmpegWriter() {}
  39. private://内部成员变量
  40. OutputStream *m_video_st;
  41. OutputStream *m_audio_st;
  42. AVOutputFormat* m_outfmt;
  43. AVFormatContext* m_formatctx;
  44. AVCodec* m_audio_codec;
  45. AVCodec* m_video_codec;
  46. int m_bhave_video;
  47. int m_bhave_audio;
  48. AVPixelFormat m_input_pix_fmt;
  49. LogApi* m_pLogApi;
  50. ByteBuffer* m_audio_input_buffer;
  51. void Close();
  52. bool m_bstart;
  53. public:
  54. bool InitWriter(char* filename, int width, int height, int colorbit, int nfps,
  55. int nSamplePsec, int nchannels, int nBitPerSample, int nmaxspacing, int nquality, int nOutBitRate, int iAudioType);
  56. bool StartWrite();
  57. bool StopWrite();
  58. bool ReceiveAudioData(unsigned char* pData, unsigned long ulen);
  59. bool ReceiveVideoData(unsigned char* pData, unsigned long ulen);
  60. };