all repos — mgba @ 4999315510f4058170657524f38fae76c143b977

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/core/interface.h>
14
15#include "feature/ffmpeg/ffmpeg-common.h"
16
17#define FFMPEG_FILTERS_MAX 4
18
19struct FFmpegEncoder {
20	struct mAVStream d;
21	struct AVFormatContext* context;
22
23	unsigned audioBitrate;
24	const char* audioCodec;
25
26	unsigned videoBitrate;
27	const char* videoCodec;
28
29	const char* containerFormat;
30
31	struct AVCodecContext* audio;
32	enum AVSampleFormat sampleFormat;
33	int sampleRate;
34	uint16_t* audioBuffer;
35	size_t audioBufferSize;
36	uint16_t* postaudioBuffer;
37	size_t postaudioBufferSize;
38	AVFrame* audioFrame;
39	size_t currentAudioSample;
40	int64_t currentAudioFrame;
41#ifdef USE_LIBAVRESAMPLE
42	struct AVAudioResampleContext* resampleContext;
43#else
44	struct SwrContext* resampleContext;
45#endif
46#ifdef FFMPEG_USE_NEW_BSF
47	struct AVBSFContext* absf; // Needed for AAC in MP4
48#else
49	struct AVBitStreamFilterContext* absf; // Needed for AAC in MP4
50#endif
51	struct AVStream* audioStream;
52
53	struct AVCodecContext* video;
54	enum AVPixelFormat pixFormat;
55	enum AVPixelFormat ipixFormat;
56	AVFrame* videoFrame;
57	int width;
58	int height;
59	int iwidth;
60	int iheight;
61	int frameCycles;
62	int cycles;
63	int frameskip;
64	int skipResidue;
65	bool loop;
66	int64_t currentVideoFrame;
67	struct SwsContext* scaleContext;
68	struct AVStream* videoStream;
69
70	struct AVFilterGraph* graph;
71	struct AVFilterContext* source;
72	struct AVFilterContext* sink;
73	struct AVFilterContext* filters[FFMPEG_FILTERS_MAX];
74	struct AVFrame* sinkFrame;
75};
76
77void FFmpegEncoderInit(struct FFmpegEncoder*);
78bool FFmpegEncoderSetAudio(struct FFmpegEncoder*, const char* acodec, unsigned abr);
79bool FFmpegEncoderSetVideo(struct FFmpegEncoder*, const char* vcodec, unsigned vbr, int frameskip);
80bool FFmpegEncoderSetContainer(struct FFmpegEncoder*, const char* container);
81void FFmpegEncoderSetDimensions(struct FFmpegEncoder*, int width, int height);
82void FFmpegEncoderSetInputFrameRate(struct FFmpegEncoder*, int numerator, int denominator);
83void FFmpegEncoderSetLooping(struct FFmpegEncoder*, bool loop);
84bool FFmpegEncoderVerifyContainer(struct FFmpegEncoder*);
85bool FFmpegEncoderOpen(struct FFmpegEncoder*, const char* outfile);
86void FFmpegEncoderClose(struct FFmpegEncoder*);
87bool FFmpegEncoderIsOpen(struct FFmpegEncoder*);
88
89CXX_GUARD_END
90
91#endif