1
0
mirror of https://github.com/mpv-player/mpv synced 2024-12-28 10:02:17 +00:00

vo_lavc: explicitly skip redraw and repeated frames

The user won't want to have those in the video (I think). The core can
sporadically issue redraws, which is what you want for actual playback,
but not in encode mode. vo_lavc can explicitly detect those and skip
them. It only requires switching to a more advanced internal VO API.

The comments in vo.h are because vo_lavc draws to one of the images in
order to render OSD. This is OK, but might come as a surprise to whoever
calls draw_frame, so document it. (Current callers are OK with it.)
This commit is contained in:
wm4 2018-04-29 16:07:21 +02:00 committed by Jan Ekström
parent 1a339fa09d
commit 958053ff56
2 changed files with 11 additions and 8 deletions

View File

@ -354,6 +354,9 @@ struct vo_driver {
/* Render the given frame. Note that this is also called when repeating
* or redrawing frames.
*
* frame is freed by the caller, but the callee can still modify the
* contained data and references.
*/
void (*draw_frame)(struct vo *vo, struct vo_frame *frame);

View File

@ -41,8 +41,6 @@ struct priv {
bool shutdown;
};
static void draw_image(struct vo *vo, mp_image_t *mpi);
static int preinit(struct vo *vo)
{
struct priv *vc = vo->priv;
@ -158,18 +156,23 @@ static int query_format(struct vo *vo, int format)
return 0;
}
static void draw_image(struct vo *vo, mp_image_t *mpi)
static void draw_frame(struct vo *vo, struct vo_frame *voframe)
{
struct priv *vc = vo->priv;
struct encoder_context *enc = vc->enc;
struct encode_lavc_context *ectx = enc->encode_lavc_ctx;
AVCodecContext *avc = enc->encoder;
if (voframe->redraw || voframe->repeat || voframe->num_frames < 1)
return;
struct mp_image *mpi = voframe->frames[0];
struct mp_osd_res dim = osd_res_from_image_params(vo->params);
osd_draw_on_image(vo->osd, dim, mpi->pts, OSD_DRAW_SUB_ONLY, mpi);
if (vc->shutdown)
goto done;
return;
// Lock for shared timestamp fields.
pthread_mutex_lock(&ectx->lock);
@ -215,9 +218,6 @@ static void draw_image(struct vo *vo, mp_image_t *mpi)
frame->quality = avc->global_quality;
encoder_encode(enc, frame);
av_frame_free(&frame);
done:
talloc_free(mpi);
}
static void flip_page(struct vo *vo)
@ -240,7 +240,7 @@ const struct vo_driver video_out_lavc = {
.reconfig2 = reconfig2,
.control = control,
.uninit = uninit,
.draw_image = draw_image,
.draw_frame = draw_frame,
.flip_page = flip_page,
};