使用ffmpeg存为avi和存为mp4在代码上是一样的,ffmpeg可以通过文件名后缀决定视频文件类型,以下是关键代码:
AviWriter.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | #pragma once class AVFormatContext; class AVStream; class AviWriter { public: int createFile(const char* filename); int setVideoTrack(const char* sps, int spslen, const char* pps, int ppslen, int width, int hight, int rate); int writeVideoSample(char* data, int datasize, bool keyframe); void closeFile(); private: AVFormatContext *m_fc; AVStream *m_avStream; int m_isHeaderWritten; }; |