summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2018-04-29 16:07:21 +0200
committerJan Ekström <jeebjp@gmail.com>2018-05-03 01:08:44 +0300
commit958053ff56109a38e9f8e0a0aa8786a5f47adb7c (patch)
tree057ea45af11ad3f7cc26e3f42d9e2be426525336
parent1a339fa09d25e94833153f299af03e9c44b19a43 (diff)
downloadmpv-958053ff56109a38e9f8e0a0aa8786a5f47adb7c.tar.bz2
mpv-958053ff56109a38e9f8e0a0aa8786a5f47adb7c.tar.xz
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.)
-rw-r--r--video/out/vo.h3
-rw-r--r--video/out/vo_lavc.c16
2 files changed, 11 insertions, 8 deletions
diff --git a/video/out/vo.h b/video/out/vo.h
index 851dd16159..17cb692356 100644
--- a/video/out/vo.h
+++ b/video/out/vo.h
@@ -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);
diff --git a/video/out/vo_lavc.c b/video/out/vo_lavc.c
index 848985edc0..2f48e3f750 100644
--- a/video/out/vo_lavc.c
+++ b/video/out/vo_lavc.c
@@ -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,
};