all repos — mgba @ cdcbedc65b942e006775fb105363a82b6eb2f91e

mGBA Game Boy Advance Emulator

FFmpeg: Backport and improve some API from medusa
Vicki Pfau vi@endrift.com
Thu, 23 Jul 2020 21:55:05 -0700
commit

cdcbedc65b942e006775fb105363a82b6eb2f91e

parent

3f75078174dd7cd7f696b59c3e43bd2842c6359c

2 files changed, 16 insertions(+), 2 deletions(-)

jump to
M src/feature/ffmpeg/ffmpeg-encoder.csrc/feature/ffmpeg/ffmpeg-encoder.c

@@ -7,6 +7,7 @@ #include "ffmpeg-encoder.h"

#include <mgba/core/core.h> #include <mgba/gba/interface.h> +#include <mgba-util/math.h> #include <libavcodec/version.h> #include <libavcodec/avcodec.h>

@@ -92,6 +93,7 @@ encoder->graph = NULL;

encoder->source = NULL; encoder->sink = NULL; encoder->sinkFrame = NULL; + FFmpegEncoderSetInputFrameRate(encoder, VIDEO_TOTAL_LENGTH, GBA_ARM7TDMI_FREQUENCY); int i; for (i = 0; i < FFMPEG_FILTERS_MAX; ++i) {

@@ -363,8 +365,8 @@ #endif

encoder->video->bit_rate = encoder->videoBitrate; encoder->video->width = encoder->width; encoder->video->height = encoder->height; - encoder->video->time_base = (AVRational) { VIDEO_TOTAL_LENGTH * encoder->frameskip, GBA_ARM7TDMI_FREQUENCY }; - encoder->video->framerate = (AVRational) { GBA_ARM7TDMI_FREQUENCY, VIDEO_TOTAL_LENGTH * encoder->frameskip }; + encoder->video->time_base = (AVRational) { encoder->frameCycles * encoder->frameskip, encoder->cycles }; + encoder->video->framerate = (AVRational) { encoder->cycles, encoder->frameCycles * encoder->frameskip }; encoder->videoStream->time_base = encoder->video->time_base; encoder->videoStream->avg_frame_rate = encoder->video->framerate; encoder->video->pix_fmt = encoder->pixFormat;

@@ -821,3 +823,12 @@ encoder->scaleContext = sws_getContext(encoder->iwidth, encoder->iheight, encoder->ipixFormat,

encoder->videoFrame->width, encoder->videoFrame->height, encoder->videoFrame->format, SWS_POINT, 0, 0, 0); } + +void FFmpegEncoderSetInputFrameRate(struct FFmpegEncoder* encoder, int numerator, int denominator) { + reduceFraction(&numerator, &denominator); + encoder->frameCycles = numerator; + encoder->cycles = denominator; + if (encoder->video) { + encoder->video->framerate = (AVRational) { denominator, numerator * encoder->frameskip }; + } +}
M src/feature/ffmpeg/ffmpeg-encoder.hsrc/feature/ffmpeg/ffmpeg-encoder.h

@@ -78,6 +78,8 @@ int width;

int height; int iwidth; int iheight; + int frameCycles; + int cycles; int frameskip; int skipResidue; bool loop;

@@ -97,6 +99,7 @@ bool FFmpegEncoderSetAudio(struct FFmpegEncoder*, const char* acodec, unsigned abr);

bool FFmpegEncoderSetVideo(struct FFmpegEncoder*, const char* vcodec, unsigned vbr, int frameskip); bool FFmpegEncoderSetContainer(struct FFmpegEncoder*, const char* container); void FFmpegEncoderSetDimensions(struct FFmpegEncoder*, int width, int height); +void FFmpegEncoderSetInputFrameRate(struct FFmpegEncoder*, int numerator, int denominator); void FFmpegEncoderSetLooping(struct FFmpegEncoder*, bool loop); bool FFmpegEncoderVerifyContainer(struct FFmpegEncoder*); bool FFmpegEncoderOpen(struct FFmpegEncoder*, const char* outfile);