src/platform/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 "gba/supervisor/thread.h"
10
11#include <libavformat/avformat.h>
12
13struct FFmpegEncoder {
14 struct GBAAVStream d;
15 struct AVFormatContext* context;
16
17 unsigned audioBitrate;
18 const char* audioCodec;
19
20 unsigned videoBitrate;
21 const char* videoCodec;
22
23 const char* containerFormat;
24
25 struct AVCodecContext* audio;
26 enum AVSampleFormat sampleFormat;
27 int sampleRate;
28 uint16_t* audioBuffer;
29 size_t audioBufferSize;
30 uint16_t* postaudioBuffer;
31 size_t postaudioBufferSize;
32 AVFrame* audioFrame;
33 size_t currentAudioSample;
34 int64_t currentAudioFrame;
35 int64_t nextAudioPts;
36 struct AVAudioResampleContext* resampleContext;
37 struct AVBitStreamFilterContext* absf; // Needed for AAC in MP4
38 struct AVStream* audioStream;
39
40 struct AVCodecContext* video;
41 enum AVPixelFormat pixFormat;
42 struct AVFrame* videoFrame;
43 int width;
44 int height;
45 int64_t currentVideoFrame;
46 struct SwsContext* scaleContext;
47 struct AVStream* videoStream;
48};
49
50void FFmpegEncoderInit(struct FFmpegEncoder*);
51bool FFmpegEncoderSetAudio(struct FFmpegEncoder*, const char* acodec, unsigned abr);
52bool FFmpegEncoderSetVideo(struct FFmpegEncoder*, const char* vcodec, unsigned vbr);
53bool FFmpegEncoderSetContainer(struct FFmpegEncoder*, const char* container);
54void FFmpegEncoderSetDimensions(struct FFmpegEncoder*, int width, int height);
55bool FFmpegEncoderVerifyContainer(struct FFmpegEncoder*);
56bool FFmpegEncoderOpen(struct FFmpegEncoder*, const char* outfile);
57void FFmpegEncoderClose(struct FFmpegEncoder*);
58bool FFmpegEncoderIsOpen(struct FFmpegEncoder*);
59
60#endif