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 "gba/gba.h"
10
11#include <libavformat/avformat.h>
12#include <libavcodec/version.h>
13
14// Version 57.16 in FFmpeg
15#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(57, 37, 100)
16#define FFMPEG_USE_PACKETS
17#endif
18
19// Version 57.15 in libav
20#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(57, 35, 0)
21#define FFMPEG_USE_NEW_BSF
22#endif
23
24// Version 57.14 in libav
25#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(57, 48, 0)
26#define FFMPEG_USE_CODECPAR
27#endif
28
29#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(57, 8, 0)
30#define FFMPEG_USE_PACKET_UNREF
31#endif
32
33struct FFmpegEncoder {
34 struct mAVStream d;
35 struct AVFormatContext* context;
36
37 unsigned audioBitrate;
38 const char* audioCodec;
39
40 unsigned videoBitrate;
41 const char* videoCodec;
42
43 const char* containerFormat;
44
45 struct AVCodecContext* audio;
46 enum AVSampleFormat sampleFormat;
47 int sampleRate;
48 uint16_t* audioBuffer;
49 size_t audioBufferSize;
50 uint16_t* postaudioBuffer;
51 size_t postaudioBufferSize;
52 AVFrame* audioFrame;
53 size_t currentAudioSample;
54 int64_t currentAudioFrame;
55 int64_t nextAudioPts; // TODO (0.6): Remove
56 struct AVAudioResampleContext* resampleContext;
57#ifdef FFMPEG_USE_NEW_BSF
58 struct AVBSFContext* absf; // Needed for AAC in MP4
59#else
60 struct AVBitStreamFilterContext* absf; // Needed for AAC in MP4
61#endif
62 struct AVStream* audioStream;
63
64 struct AVCodecContext* video;
65 enum AVPixelFormat pixFormat;
66 struct AVFrame* videoFrame;
67 int width;
68 int height;
69 int iwidth;
70 int iheight;
71 int64_t currentVideoFrame;
72 struct SwsContext* scaleContext;
73 struct AVStream* videoStream;
74};
75
76void FFmpegEncoderInit(struct FFmpegEncoder*);
77bool FFmpegEncoderSetAudio(struct FFmpegEncoder*, const char* acodec, unsigned abr);
78bool FFmpegEncoderSetVideo(struct FFmpegEncoder*, const char* vcodec, unsigned vbr);
79bool FFmpegEncoderSetContainer(struct FFmpegEncoder*, const char* container);
80void FFmpegEncoderSetDimensions(struct FFmpegEncoder*, int width, int height);
81bool FFmpegEncoderVerifyContainer(struct FFmpegEncoder*);
82bool FFmpegEncoderOpen(struct FFmpegEncoder*, const char* outfile);
83void FFmpegEncoderClose(struct FFmpegEncoder*);
84bool FFmpegEncoderIsOpen(struct FFmpegEncoder*);
85
86#endif