OSDN Git Service

mjpegenc: write the JFIF header if the sample aspect ratio is set
authorAnton Khirnov <anton@khirnov.net>
Sun, 1 Dec 2013 20:31:25 +0000 (21:31 +0100)
committerAnton Khirnov <anton@khirnov.net>
Thu, 5 Dec 2013 12:28:32 +0000 (13:28 +0100)
MpegEncContext.aspect_ratio_info is never set for mjpeg, so this was
never written before.

libavcodec/mjpegenc.c

index 0bf3dc1..a22f340 100644 (file)
@@ -148,13 +148,12 @@ static void jpeg_table_header(MpegEncContext *s)
     AV_WB16(ptr, size);
 }
 
-static void jpeg_put_comments(MpegEncContext *s)
+static void jpeg_put_comments(AVCodecContext *avctx, PutBitContext *p)
 {
-    PutBitContext *p = &s->pb;
     int size;
     uint8_t *ptr;
 
-    if (s->aspect_ratio_info /* && !lossless */)
+    if (avctx->sample_aspect_ratio.num > 0 && avctx->sample_aspect_ratio.den > 0)
     {
     /* JFIF header */
     put_marker(p, APP0);
@@ -162,14 +161,14 @@ static void jpeg_put_comments(MpegEncContext *s)
     avpriv_put_string(p, "JFIF", 1); /* this puts the trailing zero-byte too */
     put_bits(p, 16, 0x0201); /* v 1.02 */
     put_bits(p, 8, 0); /* units type: 0 - aspect ratio */
-    put_bits(p, 16, s->avctx->sample_aspect_ratio.num);
-    put_bits(p, 16, s->avctx->sample_aspect_ratio.den);
+    put_bits(p, 16, avctx->sample_aspect_ratio.num);
+    put_bits(p, 16, avctx->sample_aspect_ratio.den);
     put_bits(p, 8, 0); /* thumbnail width */
     put_bits(p, 8, 0); /* thumbnail height */
     }
 
     /* comment */
-    if(!(s->flags & CODEC_FLAG_BITEXACT)){
+    if (!(avctx->flags & CODEC_FLAG_BITEXACT)) {
         put_marker(p, COM);
         flush_put_bits(p);
         ptr = put_bits_ptr(p);
@@ -179,9 +178,9 @@ static void jpeg_put_comments(MpegEncContext *s)
         AV_WB16(ptr, size);
     }
 
-    if(  s->avctx->pix_fmt == AV_PIX_FMT_YUV420P
-       ||s->avctx->pix_fmt == AV_PIX_FMT_YUV422P
-       ||s->avctx->pix_fmt == AV_PIX_FMT_YUV444P){
+    if(  avctx->pix_fmt == AV_PIX_FMT_YUV420P
+       ||avctx->pix_fmt == AV_PIX_FMT_YUV422P
+       ||avctx->pix_fmt == AV_PIX_FMT_YUV444P){
         put_marker(p, COM);
         flush_put_bits(p);
         ptr = put_bits_ptr(p);
@@ -198,7 +197,7 @@ void ff_mjpeg_encode_picture_header(MpegEncContext *s)
 
     put_marker(&s->pb, SOI);
 
-    jpeg_put_comments(s);
+    jpeg_put_comments(s->avctx, &s->pb);
 
     jpeg_table_header(s);