ffconv/ffcpp/MediaFile.h

55 lines
1.1 KiB
C++

#ifndef FFCONV_MEDIAFILE_H
#define FFCONV_MEDIAFILE_H
#include "Stream.h"
#include "Packet.h"
extern "C" {
#include <libavformat/avformat.h>
}
#include <string>
#include <vector>
namespace ffcpp {
enum class Mode {
Read,
Write
};
class MediaFile {
private:
AVFormatContext* _formatCtx;
Mode _mode;
std::vector<Stream> _streams;
public:
MediaFile(const std::string& src, Mode mode);
operator AVFormatContext*() const;
bool hasVideo() const;
bool hasAudio() const;
Stream& videoStream(size_t index = 0);
Stream& audioStream(size_t index = 0);
Stream& addVideoStream(AVCodecID codecID, int width, int height, AVPixelFormat pixelFormat = AV_PIX_FMT_NONE);
Stream& addAudioStream(AVCodecID codecID, int channels, int sampleRate, AVSampleFormat sampleFormat = AV_SAMPLE_FMT_NONE);
Packet readPacket();
AVMediaType packetType(const Packet& packet);
void writeHeader();
void writeTrailer();
void writePacket(Packet& packet);
~MediaFile();
private:
bool hasStream(AVMediaType type) const;
Stream& getStream(AVMediaType type, size_t index);
};
}
#endif //FFCONV_MEDIAFILE_H