1 ///////////////////////////////////////////////////////////////////////////// 2 // Name: mediaenc_ffmpeg.h 3 // Purpose: FFMPEG Media Encoder 4 // Author: Alex Thuering 5 // Created: 04.08.2007 6 // RCS-ID: $Id: mediaenc_ffmpeg.h,v 1.15 2016/10/05 19:51:30 ntalex Exp $ 7 // Copyright: (c) Alex Thuering 8 // Licence: GPL 9 ///////////////////////////////////////////////////////////////////////////// 10 11 #ifndef WX_FFMPEG_MEDIA_ENCODER_H 12 #define WX_FFMPEG_MEDIA_ENCODER_H 13 14 #include "mediaenc.h" 15 #include <stdint.h> 16 17 struct AVFormatContext; 18 struct AVStream; 19 struct AVFrame; 20 struct SwsContext; 21 22 class wxFfmpegMediaEncoder { 23 public: 24 wxFfmpegMediaEncoder(int threadCount = 1); 25 ~wxFfmpegMediaEncoder(); 26 27 bool BeginEncode(const wxString& fileName, VideoFormat videoFormat, AudioFormat audioFormat, 28 AspectRatio aspectRatio = ar4_3, int videoBitrate = 6000, bool cbr = false); 29 bool EncodeImage(wxImage image, int frames, AbstractProgressDialog* progressDialog); 30 bool EncodeAudio(double duration, AbstractProgressDialog* progressDialog); 31 void EndEncode(); 32 SetGopSize(int gopSize)33 void SetGopSize(int gopSize) { m_gopSize = gopSize; } 34 35 static wxString GetBackendVersion(); 36 37 private: 38 int m_threadCount; 39 int m_gopSize; 40 AVFormatContext* m_outputCtx; 41 AVStream* m_videoStm; 42 AVStream* m_audioStm; 43 int64_t m_nextVideoPts; 44 int64_t m_nextAudioPts; 45 bool addVideoStream(int codecId, VideoFormat videoFormat, AspectRatio aspectRatio, int videoBitrate, bool cbr); 46 bool addAudioStream(int codecId); 47 48 int16_t* m_samples; 49 AVFrame* m_audioFrame; 50 bool OpenAudioEncoder(); 51 void CloseAudioEncoder(); 52 53 AVFrame* m_picture; 54 SwsContext* m_imgConvertCtx; 55 uint8_t* m_videoOutbuf; 56 bool OpenVideoEncoder(); 57 void CloseVideoEncoder(); 58 59 void getAudioFrame(int nbChannels); 60 bool writeAudioFrame(); 61 /** writes m_picture */ 62 bool writeVideoFrame(); 63 64 void CloseEncoder(); 65 }; 66 67 #endif // WX_FFMPEG_MEDIA_ENCODER_H 68