avvidenc: Set timebase in the ffmpeg context to nanoseconds and set framerate

As we now actually use the timestamps from ffmpeg for timestamping the
output we would lose a lot of accuracy if the framerate is used.

Fixes https://gitlab.freedesktop.org/gstreamer/gstreamer/-/issues/1544

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3634>
This commit is contained in:
Sebastian Dröge 2022-12-23 18:01:03 +02:00 committed by GStreamer Marge Bot
parent 11520403a5
commit 50db59449e
2 changed files with 7 additions and 10 deletions

View file

@ -2956,14 +2956,13 @@ gst_ffmpeg_videoinfo_to_context (GstVideoInfo * info, AVCodecContext * context)
bpp += GST_VIDEO_INFO_COMP_DEPTH (info, i);
context->bits_per_coded_sample = bpp;
context->time_base.den = 1000000000;
context->time_base.num = 1;
context->ticks_per_frame = 1;
if (GST_VIDEO_INFO_FPS_N (info) == 0) {
GST_DEBUG ("Using 25/1 framerate");
context->time_base.den = 25;
context->time_base.num = 1;
} else {
context->time_base.den = GST_VIDEO_INFO_FPS_N (info);
context->time_base.num = GST_VIDEO_INFO_FPS_D (info);
if (GST_VIDEO_INFO_FPS_N (info) != 0) {
context->framerate.num = GST_VIDEO_INFO_FPS_N (info);
context->framerate.den = GST_VIDEO_INFO_FPS_D (info);
}
context->sample_aspect_ratio.num = GST_VIDEO_INFO_PAR_N (info);

View file

@ -308,9 +308,7 @@ gst_ffmpegvidenc_set_format (GstVideoEncoder * encoder,
* (1<<16) - 1 . We therefore scale them down.
* Agreed, it will not be the exact framerate... but the difference
* shouldn't be that noticeable */
ffmpegenc->context->time_base.num =
(gint) gst_util_uint64_scale_int (ffmpegenc->context->time_base.num,
65535, ffmpegenc->context->time_base.den);
ffmpegenc->context->time_base.num = 1;
ffmpegenc->context->time_base.den = 65535;
GST_LOG_OBJECT (ffmpegenc, "MPEG4 : scaled down framerate to %d / %d",
ffmpegenc->context->time_base.den, ffmpegenc->context->time_base.num);