img2enc: Fix yuva with yuv split planes.
authorMichael Niedermayer <michaelni@gmx.at>
Tue, 6 Nov 2012 00:27:09 +0000 (01:27 +0100)
committerMichael Niedermayer <michaelni@gmx.at>
Tue, 6 Nov 2012 00:31:41 +0000 (01:31 +0100)
Previously the chroma planes where corrupted in this case.

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
libavformat/img2enc.c

index 0ab7c65..65e53bb 100644 (file)
@@ -97,10 +97,12 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt)
     }
 
     if(img->split_planes){
+        const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(codec->pix_fmt);
         int ysize = codec->width * codec->height;
+        int usize = ((-codec->width)>>desc->log2_chroma_w) * ((-codec->height)>>desc->log2_chroma_h);
         avio_write(pb[0], pkt->data        , ysize);
-        avio_write(pb[1], pkt->data + ysize, (pkt->size - ysize)/2);
-        avio_write(pb[2], pkt->data + ysize +(pkt->size - ysize)/2, (pkt->size - ysize)/2);
+        avio_write(pb[1], pkt->data + ysize        , usize);
+        avio_write(pb[2], pkt->data + ysize + usize, usize);
         avio_close(pb[1]);
         avio_close(pb[2]);
     }else{