[MPlayer-cvslog] r36849 - trunk/libmpcodecs/vf_screenshot.c
reimar
subversion at mplayerhq.hu
Sun Feb 16 15:47:32 CET 2014
Author: reimar
Date: Sun Feb 16 15:47:32 2014
New Revision: 36849
Log:
vf_screenshot: Switch to avcodec_encode_video2 API.
Modified:
trunk/libmpcodecs/vf_screenshot.c
Modified: trunk/libmpcodecs/vf_screenshot.c
==============================================================================
--- trunk/libmpcodecs/vf_screenshot.c Sun Feb 16 15:01:23 2014 (r36848)
+++ trunk/libmpcodecs/vf_screenshot.c Sun Feb 16 15:47:32 2014 (r36849)
@@ -50,8 +50,8 @@ struct vf_priv_s {
/// 1: take single screenshot, reset to 0 afterwards
/// 2: take screenshots of each frame
int shot, store_slices;
- int dw, dh, stride;
- uint8_t *buffer;
+ int dw, dh;
+ AVFrame *pic;
struct SwsContext *ctx;
AVCodecContext *avctx;
uint8_t *outbuffer;
@@ -64,11 +64,7 @@ static void draw_slice(struct vf_instanc
int* stride, int w,int h, int x, int y)
{
if (vf->priv->store_slices) {
- uint8_t *dst[MP_MAX_PLANES] = {NULL};
- int dst_stride[MP_MAX_PLANES] = {0};
- dst_stride[0] = vf->priv->stride;
- dst[0] = vf->priv->buffer;
- sws_scale(vf->priv->ctx, src, stride, y, h, dst, dst_stride);
+ sws_scale(vf->priv->ctx, src, stride, y, h, vf->priv->pic->data, vf->priv->pic->linesize);
}
vf_next_draw_slice(vf,src,stride,w,h,x,y);
}
@@ -88,10 +84,9 @@ static int config(struct vf_instance *vf
vf->priv->avctx->compression_level = 0;
vf->priv->dw = d_width;
vf->priv->dh = d_height;
- vf->priv->stride = (3*vf->priv->dw+15)&~15;
+ vf->priv->pic->linesize[0] = (3*vf->priv->dw+15)&~15;
- free(vf->priv->buffer); // probably reconfigured
- vf->priv->buffer = NULL;
+ av_freep(&vf->priv->pic->data[0]); // probably reconfigured
res = vf_next_config(vf,width,height,d_width,d_height,flags,outfmt);
// Our draw_slice only works properly if the
@@ -104,8 +99,8 @@ static void write_png(struct vf_priv_s *
{
char *fname = priv->fname;
FILE * fp;
- AVFrame pic;
- int size;
+ AVPacket pkt;
+ int res, got_pkt;
fp = fopen (fname, "wb");
if (fp == NULL) {
@@ -113,11 +108,12 @@ static void write_png(struct vf_priv_s *
return;
}
- pic.data[0] = priv->buffer;
- pic.linesize[0] = priv->stride;
- size = avcodec_encode_video(priv->avctx, priv->outbuffer, priv->outbuffer_size, &pic);
- if (size > 0)
- fwrite(priv->outbuffer, size, 1, fp);
+ av_init_packet(&pkt);
+ pkt.data = priv->outbuffer;
+ pkt.size = priv->outbuffer_size;
+ res = avcodec_encode_video2(priv->avctx, &pkt, priv->pic, &got_pkt);
+ if (res >= 0 && got_pkt && pkt.size > 0)
+ fwrite(priv->outbuffer, pkt.size, 1, fp);
fclose (fp);
}
@@ -144,15 +140,10 @@ static void gen_fname(struct vf_priv_s*
static void scale_image(struct vf_priv_s* priv, mp_image_t *mpi)
{
- uint8_t *dst[MP_MAX_PLANES] = {NULL};
- int dst_stride[MP_MAX_PLANES] = {0};
-
- dst_stride[0] = priv->stride;
- if (!priv->buffer)
- priv->buffer = av_malloc(dst_stride[0]*priv->dh);
+ if (!priv->pic->data[0])
+ priv->pic->data[0] = av_malloc(priv->pic->linesize[0]*priv->dh);
- dst[0] = priv->buffer;
- sws_scale(priv->ctx, mpi->planes, mpi->stride, 0, priv->dh, dst, dst_stride);
+ sws_scale(priv->ctx, mpi->planes, mpi->stride, 0, priv->dh, priv->pic->data, priv->pic->linesize);
}
static void start_slice(struct vf_instance *vf, mp_image_t *mpi)
@@ -162,8 +153,8 @@ static void start_slice(struct vf_instan
mpi->type, mpi->flags, mpi->width, mpi->height);
if (vf->priv->shot) {
vf->priv->store_slices = 1;
- if (!vf->priv->buffer)
- vf->priv->buffer = av_malloc(vf->priv->stride*vf->priv->dh);
+ if (!vf->priv->pic->data[0])
+ vf->priv->pic->data[0] = av_malloc(vf->priv->pic->linesize[0]*vf->priv->dh);
}
}
@@ -281,7 +272,8 @@ static void uninit(vf_instance_t *vf)
avcodec_close(vf->priv->avctx);
av_freep(&vf->priv->avctx);
if(vf->priv->ctx) sws_freeContext(vf->priv->ctx);
- av_free(vf->priv->buffer);
+ av_freep(&vf->priv->pic->data[0]);
+ av_frame_free(&vf->priv->pic);
free(vf->priv->outbuffer);
free(vf->priv->prefix);
free(vf->priv);
@@ -298,11 +290,11 @@ static int vf_open(vf_instance_t *vf, ch
vf->get_image=get_image;
vf->uninit=uninit;
vf->priv=malloc(sizeof(struct vf_priv_s));
+ vf->priv->pic = av_frame_alloc();
vf->priv->prefix = strdup(args ? args : "shot");
vf->priv->frameno=0;
vf->priv->shot=0;
vf->priv->store_slices=0;
- vf->priv->buffer=0;
vf->priv->outbuffer=0;
vf->priv->ctx=0;
vf->priv->avctx = avcodec_alloc_context3(NULL);
More information about the MPlayer-cvslog
mailing list