all repos — mgba @ 8708a0db52de758753a675bc646fb7b6cdafb874

mGBA Game Boy Advance Emulator

src/feature/ffmpeg/ffmpeg-encoder.h (view raw)

  1/* Copyright (c) 2013-2015 Jeffrey Pfau
  2 *
  3 * This Source Code Form is subject to the terms of the Mozilla Public
  4 * License, v. 2.0. If a copy of the MPL was not distributed with this
  5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  6#ifndef FFMPEG_ENCODER
  7#define FFMPEG_ENCODER
  8
  9#include <mgba-util/common.h>
 10
 11CXX_GUARD_START
 12
 13#include <mgba/internal/gba/gba.h>
 14
 15#include <libavformat/avformat.h>
 16#include <libavcodec/version.h>
 17
 18// Version 57.16 in FFmpeg
 19#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(57, 37, 100)
 20#define FFMPEG_USE_PACKETS
 21#endif
 22
 23// Version 57.15 in libav
 24#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(57, 35, 0)
 25#define FFMPEG_USE_NEW_BSF
 26#endif
 27
 28// Version 57.14 in libav
 29#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(57, 48, 0)
 30#define FFMPEG_USE_CODECPAR
 31#endif
 32
 33#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(57, 8, 0)
 34#define FFMPEG_USE_PACKET_UNREF
 35#endif
 36
 37#define FFMPEG_FILTERS_MAX 4
 38
 39struct FFmpegEncoder {
 40	struct mAVStream d;
 41	struct AVFormatContext* context;
 42
 43	unsigned audioBitrate;
 44	const char* audioCodec;
 45
 46	unsigned videoBitrate;
 47	const char* videoCodec;
 48
 49	const char* containerFormat;
 50
 51	struct AVCodecContext* audio;
 52	enum AVSampleFormat sampleFormat;
 53	int sampleRate;
 54	uint16_t* audioBuffer;
 55	size_t audioBufferSize;
 56	uint16_t* postaudioBuffer;
 57	size_t postaudioBufferSize;
 58	AVFrame* audioFrame;
 59	size_t currentAudioSample;
 60	int64_t currentAudioFrame;
 61#ifdef USE_LIBAVRESAMPLE
 62	struct AVAudioResampleContext* resampleContext;
 63#else
 64	struct SwrContext* resampleContext;
 65#endif
 66#ifdef FFMPEG_USE_NEW_BSF
 67	struct AVBSFContext* absf; // Needed for AAC in MP4
 68#else
 69	struct AVBitStreamFilterContext* absf; // Needed for AAC in MP4
 70#endif
 71	struct AVStream* audioStream;
 72
 73	struct AVCodecContext* video;
 74	enum AVPixelFormat pixFormat;
 75	enum AVPixelFormat ipixFormat;
 76	struct AVFrame* videoFrame;
 77	int width;
 78	int height;
 79	int iwidth;
 80	int iheight;
 81	int frameskip;
 82	int skipResidue;
 83	int64_t currentVideoFrame;
 84	struct SwsContext* scaleContext;
 85	struct AVStream* videoStream;
 86
 87	struct AVFilterGraph* graph;
 88	struct AVFilterContext* source;
 89	struct AVFilterContext* sink;
 90	struct AVFilterContext* filters[FFMPEG_FILTERS_MAX];
 91	struct AVFrame* sinkFrame;
 92};
 93
 94void FFmpegEncoderInit(struct FFmpegEncoder*);
 95bool FFmpegEncoderSetAudio(struct FFmpegEncoder*, const char* acodec, unsigned abr);
 96bool FFmpegEncoderSetVideo(struct FFmpegEncoder*, const char* vcodec, unsigned vbr, int frameskip);
 97bool FFmpegEncoderSetContainer(struct FFmpegEncoder*, const char* container);
 98void FFmpegEncoderSetDimensions(struct FFmpegEncoder*, int width, int height);
 99bool FFmpegEncoderVerifyContainer(struct FFmpegEncoder*);
100bool FFmpegEncoderOpen(struct FFmpegEncoder*, const char* outfile);
101void FFmpegEncoderClose(struct FFmpegEncoder*);
102bool FFmpegEncoderIsOpen(struct FFmpegEncoder*);
103
104CXX_GUARD_END
105
106#endif