ffconv/include/ffcpp/MediaFile.h

60 lines
1.2 KiB
C++

#ifndef FFCONV_MEDIAFILE_H
#define FFCONV_MEDIAFILE_H
#include "Stream.h"
#include "Packet.h"
#include <memory>
extern "C" {
#include <libavformat/avformat.h>
}
#include <string>
#include <vector>
#ifndef _MSC_VER
#include <bits/shared_ptr.h>
#endif
namespace ffcpp {
enum class Mode {
Read,
Write
};
class MediaFile {
private:
AVFormatContext* _formatCtx;
Mode _mode;
std::vector<StreamPtr> _streams;
public:
MediaFile(const std::string& src, Mode mode);
operator AVFormatContext*() const;
bool hasVideo() const;
bool hasAudio() const;
StreamPtr videoStream(size_t index = 0);
StreamPtr audioStream(size_t index = 0);
StreamPtr addVideoStream(AVCodecID codecID, int width, int height, AVRational timeBase, AVPixelFormat pixelFormat = AV_PIX_FMT_NONE);
StreamPtr 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;
StreamPtr getStream(AVMediaType type, size_t index);
};
}
#endif //FFCONV_MEDIAFILE_H