Skip to content

Commit cc2a2fc

Browse files
committed
vcomp/lavc: improve time_base setting
for /1001 formats eg. 29.97, 1/30 was set - improve to set 1001/30000 for AVCodecCtx.framerate just invert the time_base fraction
1 parent 9e5cb70 commit cc2a2fc

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

src/video_compress/libavcodec.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#include <cmath>
4444
#include <cstdint>
4545
#include <cstring> // for strcmp, strlen, strstr, strchr
46+
#include <libavutil/rational.h> // for av_inv_q
4647
#include <list>
4748
#include <map>
4849
#include <regex>
@@ -953,9 +954,9 @@ bool set_codec_ctx_params(struct state_video_compress_libav *s, AVPixelFormat pi
953954
s->codec_ctx->width = desc.width;
954955
s->codec_ctx->height = desc.height;
955956
/* frames per second */
956-
s->codec_ctx->time_base = (AVRational){1,(int) desc.fps};
957-
s->codec_ctx->framerate = (AVRational) { get_framerate_n(desc.fps),
958-
get_framerate_d(desc.fps) };
957+
s->codec_ctx->time_base = (AVRational) { get_framerate_d(desc.fps),
958+
get_framerate_n(desc.fps) };
959+
s->codec_ctx->framerate = av_inv_q(s->codec_ctx->time_base);
959960
s->codec_ctx->gop_size = s->requested_gop;
960961
s->codec_ctx->max_b_frames = 0;
961962

0 commit comments

Comments
 (0)