vo_image: render subs

This makes it behave like vo_lavc.

Unfortunately, the code for setting up the OSD dimensions (mp_osd_res)
is copied from vo_lavc, but it doesn't look like something that should
be factored out.
This commit is contained in:
wm4 2012-12-22 19:11:53 +01:00
parent 5e8b3e74ec
commit ded932dbd4
1 changed files with 40 additions and 19 deletions

View File

@ -36,12 +36,16 @@
#include "video/mp_image.h"
#include "video/fmt-conversion.h"
#include "video/image_writer.h"
#include "video/sws_utils.h"
#include "sub/sub.h"
#include "core/m_option.h"
struct priv {
struct image_writer_opts *opts;
char *outdir;
struct mp_image *current;
int frame;
uint32_t d_width;
@ -74,6 +78,8 @@ static int config(struct vo *vo, uint32_t width, uint32_t height,
{
struct priv *p = vo->priv;
mp_image_unrefp(&p->current);
p->d_width = d_width;
p->d_height = d_height;
@ -88,21 +94,37 @@ static void check_events(struct vo *vo)
{
}
static void draw_osd(struct vo *vo, struct osd_state *osd)
{
}
static void flip_page(struct vo *vo)
{
}
static void draw_image(struct vo *vo, mp_image_t *mpi)
{
struct priv *p = vo->priv;
mp_image_t img = *mpi;
mp_image_set_display_size(&img, p->d_width, p->d_height);
mp_image_set_colorspace_details(&img, &p->colorspace);
mp_image_setrefp(&p->current, mpi);
mp_image_set_display_size(p->current, p->d_width, p->d_height);
mp_image_set_colorspace_details(p->current, &p->colorspace);
}
static void draw_osd(struct vo *vo, struct osd_state *osd)
{
struct priv *p = vo->priv;
struct aspect_data asp = vo->aspdat;
double sar = (double)asp.orgw / asp.orgh;
double dar = (double)asp.prew / asp.preh;
struct mp_osd_res dim = {
.w = asp.orgw,
.h = asp.orgh,
.display_par = sar / dar,
.video_par = dar / sar,
};
osd_draw_on_image(osd, dim, osd->vo_pts, OSD_DRAW_SUB_ONLY, p->current);
}
static void flip_page(struct vo *vo)
{
struct priv *p = vo->priv;
void *t = talloc_new(NULL);
char *filename = talloc_asprintf(t, "%08d.%s", p->frame,
@ -112,27 +134,26 @@ static void draw_image(struct vo *vo, mp_image_t *mpi)
filename = mp_path_join(t, bstr0(p->outdir), bstr0(filename));
mp_msg(MSGT_VO, MSGL_STATUS, "\nSaving %s\n", filename);
write_image(&img, p->opts, filename);
write_image(p->current, p->opts, filename);
talloc_free(t);
mp_image_unrefp(&p->current);
(p->frame)++;
}
static int query_format(struct vo *vo, uint32_t fmt)
{
enum PixelFormat av_format = imgfmt2pixfmt(fmt);
// NOTE: accept everything that can be converted by swscale. screenshot.c
// always wants RGB (at least for now), but it probably doesn't matter
// whether we or screenshot.c do the conversion.
if (av_format != PIX_FMT_NONE && sws_isSupportedInput(av_format))
return VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW;
if (mp_sws_supported_format(fmt))
return VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW | VFCAP_OSD;
return 0;
}
static void uninit(struct vo *vo)
{
struct priv *p = vo->priv;
mp_image_unrefp(&p->current);
}
static int preinit(struct vo *vo, const char *arg)