[FFmpeg-devel] [PATCH 1/3] lavd/xv: speed up yuv420p write packet

Lukasz M lukasz.m.luki at gmail.com
Fri Nov 15 00:32:21 CET 2013


On 14 November 2013 12:15, Stefano Sabatini <stefasab at gmail.com> wrote:

> On date Wednesday 2013-11-13 23:40:45 +0100, Lukasz Marek encoded:
> > xv_write_packet do operations like multiplication that are not required.
> > Small optimizations allows to make function up to 10% faster.
> >
> > Signed-off-by: Lukasz Marek <lukasz.m.luki at gmail.com>
> > ---
> >  libavdevice/xv.c |   31 +++++++++++++++++--------------
> >  1 file changed, 17 insertions(+), 14 deletions(-)
> >
> > diff --git a/libavdevice/xv.c b/libavdevice/xv.c
> > index 50d72a5..fdc96c9 100644
> > --- a/libavdevice/xv.c
> > +++ b/libavdevice/xv.c
> > @@ -141,6 +141,17 @@ static int xv_write_header(AVFormatContext *s)
> >      return 0;
> >  }
> >
>
> > +static av_always_inline void xv_copy_line(int h, const char *src, char
> *dst,
> > +                                          int src_linesize, int
> dst_linesize)
> > +{
> > +    int y, len = FFMIN(src_linesize, dst_linesize);
> > +    for (y = 0; y < h; ++y) {
> > +        memcpy(dst, src, len);
> > +        src += src_linesize;
> > +        dst += dst_linesize;
> > +    }
> > +}
>
> av_image_copy_plane()?
>
> > +
> >  static int xv_write_packet(AVFormatContext *s, AVPacket *pkt)
> >  {
> >      XVContext *xv = s->priv_data;
> > @@ -148,22 +159,14 @@ static int xv_write_packet(AVFormatContext *s,
> AVPacket *pkt)
> >      XWindowAttributes window_attrs;
> >      AVPicture pict;
> >      AVCodecContext *ctx = s->streams[0]->codec;
> > -    int y, h;
> > -
> > -    h = img->height / 2;
> >
> >      avpicture_fill(&pict, pkt->data, ctx->pix_fmt, ctx->width,
> ctx->height);
> > -    for (y = 0; y < img->height; y++) {
> > -        memcpy(&img->data[img->offsets[0] + (y * img->pitches[0])],
> > -               &pict.data[0][y * pict.linesize[0]], img->pitches[0]);
> > -    }
> > -
> > -    for (y = 0; y < h; ++y) {
> > -        memcpy(&img->data[img->offsets[1] + (y * img->pitches[1])],
> > -               &pict.data[1][y * pict.linesize[1]], img->pitches[1]);
> > -        memcpy(&img->data[img->offsets[2] + (y * img->pitches[2])],
> > -               &pict.data[2][y * pict.linesize[2]], img->pitches[2]);
> > -    }
> > +    xv_copy_line(img->height, pict.data[0], &img->data[img->offsets[0]],
> > +                 pict.linesize[0], img->pitches[0]);
> > +    xv_copy_line(img->height / 2, pict.data[1],
> &img->data[img->offsets[1]],
> > +                 pict.linesize[1], img->pitches[1]);
> > +    xv_copy_line(img->height / 2, pict.data[2],
> &img->data[img->offsets[2]],
> > +                 pict.linesize[2], img->pitches[2]);
>
> av_image_copy()?
>

I used  av_image_copy() in new patch. I did again performance tests and
real increase is only for small dimensions.
For a movie 640x352 is is around 0.5%. For HD movies it will be even
smaller probably.
For a movie 320x480 it was around 5%, but small frames are copied fast
anyway just because they are small so optimization for them is less
important.
Yesterday I tested with gcc nationalizations turned off and got higher
values, but it's not reliable.
On other hand with av_image_copy it is slower by 0.5% for 640x352 comparing
to original code.
New patch is then 1% slower than previous for medium size frames.
I think it is not worth anyway, cleaner code I better.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-lavd-xv-simplify-write_packet.patch
Type: text/x-patch
Size: 1913 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20131115/209e580c/attachment.bin>


More information about the ffmpeg-devel mailing list