summaryrefslogtreecommitdiffstats
path: root/video/out/vo_lavc.c
diff options
context:
space:
mode:
Diffstat (limited to 'video/out/vo_lavc.c')
-rw-r--r--video/out/vo_lavc.c27
1 files changed, 18 insertions, 9 deletions
diff --git a/video/out/vo_lavc.c b/video/out/vo_lavc.c
index e817b530e0..2842335d13 100644
--- a/video/out/vo_lavc.c
+++ b/video/out/vo_lavc.c
@@ -23,7 +23,8 @@
#include <stdio.h>
#include <stdlib.h>
-#include "config.h"
+#include <libplacebo/utils/libav.h>
+
#include "common/common.h"
#include "options/options.h"
#include "video/fmt-conversion.h"
@@ -113,8 +114,8 @@ static int reconfig2(struct vo *vo, struct mp_image *img)
encoder->width = width;
encoder->height = height;
encoder->pix_fmt = pix_fmt;
- encoder->colorspace = mp_csp_to_avcol_spc(params->color.space);
- encoder->color_range = mp_csp_levels_to_avcol_range(params->color.levels);
+ encoder->colorspace = pl_system_to_av(params->repr.sys);
+ encoder->color_range = pl_levels_to_av(params->repr.levels);
AVRational tb;
@@ -134,6 +135,17 @@ static int reconfig2(struct vo *vo, struct mp_image *img)
encoder->time_base = av_inv_q(tb);
+ // Used for rate control, level selection, etc.
+ // Usually it's not too catastrophic if this isn't exactly correct,
+ // as long as it's not off by orders of magnitude.
+ // If we don't set anything, encoders will use the time base,
+ // and 24000 is so high that the output can end up extremely screwy (see #11215),
+ // so we default to 240 if we don't have a real value.
+ if (img->nominal_fps > 0)
+ encoder->framerate = av_d2q(img->nominal_fps, img->nominal_fps * 1001 + 2); // Hopefully give exact results for NTSC rates
+ else
+ encoder->framerate = (AVRational){ 240, 1 };
+
if (!encoder_init_codec_and_muxer(vc->enc, on_ready, vo))
goto error;
@@ -182,7 +194,7 @@ static void draw_frame(struct vo *vo, struct vo_frame *voframe)
return;
// Lock for shared timestamp fields.
- pthread_mutex_lock(&ectx->lock);
+ mp_mutex_lock(&ectx->lock);
double pts = mpi->pts;
double outpts = pts;
@@ -202,8 +214,6 @@ static void draw_frame(struct vo *vo, struct vo_frame *voframe)
outpts = pts + ectx->discontinuity_pts_offset;
}
- outpts += encoder_get_offset(enc);
-
if (!enc->options->rawts) {
// calculate expected pts of next video frame
double timeunit = av_q2d(avc->time_base);
@@ -214,11 +224,10 @@ static void draw_frame(struct vo *vo, struct vo_frame *voframe)
ectx->next_in_pts = nextpts;
}
- pthread_mutex_unlock(&ectx->lock);
+ mp_mutex_unlock(&ectx->lock);
AVFrame *frame = mp_image_to_av_frame(mpi);
- if (!frame)
- abort();
+ MP_HANDLE_OOM(frame);
frame->pts = rint(outpts * av_q2d(av_inv_q(avc->time_base)));
frame->pict_type = 0; // keep this at unknown/undefined