Move output_example.c and ffplay.c to the swscale interface
authorLuca Abeni <lucabe72@email.it>
Thu, 3 Aug 2006 16:55:36 +0000 (16:55 +0000)
committerLuca Abeni <lucabe72@email.it>
Thu, 3 Aug 2006 16:55:36 +0000 (16:55 +0000)
Originally committed as revision 5923 to svn://svn.ffmpeg.org/ffmpeg/trunk

ffplay.c
output_example.c

index 79e43dd..46638bd 100644 (file)
--- a/ffplay.c
+++ b/ffplay.c
@@ -18,6 +18,7 @@
  */
 #define HAVE_AV_CONFIG_H
 #include "avformat.h"
  */
 #define HAVE_AV_CONFIG_H
 #include "avformat.h"
+#include "swscale.h"
 
 #include "version.h"
 #include "cmdutils.h"
 
 #include "version.h"
 #include "cmdutils.h"
@@ -70,6 +71,8 @@
 /* NOTE: the size must be big enough to compensate the hardware audio buffersize size */
 #define SAMPLE_ARRAY_SIZE (2*65536)
 
 /* NOTE: the size must be big enough to compensate the hardware audio buffersize size */
 #define SAMPLE_ARRAY_SIZE (2*65536)
 
+static int sws_flags = SWS_BICUBIC;
+
 typedef struct PacketQueue {
     AVPacketList *first_pkt, *last_pkt;
     int nb_packets;
 typedef struct PacketQueue {
     AVPacketList *first_pkt, *last_pkt;
     int nb_packets;
@@ -1143,6 +1146,7 @@ static int queue_picture(VideoState *is, AVFrame *src_frame, double pts)
     VideoPicture *vp;
     int dst_pix_fmt;
     AVPicture pict;
     VideoPicture *vp;
     int dst_pix_fmt;
     AVPicture pict;
+    static struct SwsContext *img_convert_ctx;
 
     /* wait until we have space to put a new picture */
     SDL_LockMutex(is->pictq_mutex);
 
     /* wait until we have space to put a new picture */
     SDL_LockMutex(is->pictq_mutex);
@@ -1195,9 +1199,18 @@ static int queue_picture(VideoState *is, AVFrame *src_frame, double pts)
         pict.linesize[0] = vp->bmp->pitches[0];
         pict.linesize[1] = vp->bmp->pitches[2];
         pict.linesize[2] = vp->bmp->pitches[1];
         pict.linesize[0] = vp->bmp->pitches[0];
         pict.linesize[1] = vp->bmp->pitches[2];
         pict.linesize[2] = vp->bmp->pitches[1];
-        img_convert(&pict, dst_pix_fmt,
-                    (AVPicture *)src_frame, is->video_st->codec->pix_fmt,
-                    is->video_st->codec->width, is->video_st->codec->height);
+        if (img_convert_ctx == NULL) {
+            img_convert_ctx = sws_getContext(is->video_st->codec->width,
+                    is->video_st->codec->height, is->video_st->codec->pix_fmt,
+                    is->video_st->codec->width, is->video_st->codec->height,
+                    dst_pix_fmt, sws_flags, NULL, NULL, NULL);
+            if (img_convert_ctx == NULL) {
+                fprintf(stderr, "Cannot initialize the conversion context\n");
+                exit(1);
+            }
+        }
+        sws_scale(img_convert_ctx, src_frame->data, src_frame->linesize,
+                  0, is->video_st->codec->height, pict.data, pict.linesize);
         /* update the bitmap content */
         SDL_UnlockYUVOverlay(vp->bmp);
 
         /* update the bitmap content */
         SDL_UnlockYUVOverlay(vp->bmp);
 
index 365a35e..083bbe5 100644 (file)
@@ -32,6 +32,7 @@
 #endif
 
 #include "avformat.h"
 #endif
 
 #include "avformat.h"
+#include "swscale.h"
 
 /* 5 seconds stream duration */
 #define STREAM_DURATION   5.0
 
 /* 5 seconds stream duration */
 #define STREAM_DURATION   5.0
@@ -39,6 +40,8 @@
 #define STREAM_NB_FRAMES  ((int)(STREAM_DURATION * STREAM_FRAME_RATE))
 #define STREAM_PIX_FMT PIX_FMT_YUV420P /* default pix_fmt */
 
 #define STREAM_NB_FRAMES  ((int)(STREAM_DURATION * STREAM_FRAME_RATE))
 #define STREAM_PIX_FMT PIX_FMT_YUV420P /* default pix_fmt */
 
+static int sws_flags = SWS_BICUBIC;
+
 /**************************************************************/
 /* audio output */
 
 /**************************************************************/
 /* audio output */
 
@@ -319,6 +322,7 @@ static void write_video_frame(AVFormatContext *oc, AVStream *st)
 {
     int out_size, ret;
     AVCodecContext *c;
 {
     int out_size, ret;
     AVCodecContext *c;
+    static struct SwsContext *img_convert_ctx;
 
     c = st->codec;
 
 
     c = st->codec;
 
@@ -330,10 +334,20 @@ static void write_video_frame(AVFormatContext *oc, AVStream *st)
         if (c->pix_fmt != PIX_FMT_YUV420P) {
             /* as we only generate a YUV420P picture, we must convert it
                to the codec pixel format if needed */
         if (c->pix_fmt != PIX_FMT_YUV420P) {
             /* as we only generate a YUV420P picture, we must convert it
                to the codec pixel format if needed */
+            if (img_convert_ctx == NULL) {
+                img_convert_ctx = sws_getContext(c->width, c->height,
+                                                 PIX_FMT_YUV420P,
+                                                 c->width, c->height,
+                                                 c->pix_fmt,
+                                                 sws_flags, NULL, NULL, NULL);
+                if (img_convert_ctx == NULL) {
+                    fprintf(stderr, "Cannot initialize the conversion context\n");
+                    exit(1);
+                }
+            }
             fill_yuv_image(tmp_picture, frame_count, c->width, c->height);
             fill_yuv_image(tmp_picture, frame_count, c->width, c->height);
-            img_convert((AVPicture *)picture, c->pix_fmt,
-                        (AVPicture *)tmp_picture, PIX_FMT_YUV420P,
-                        c->width, c->height);
+            sws_scale(img_convert_ctx, tmp_picture->data, tmp_picture->linesize,
+                      0, c->height, picture->data, picture->linesize);
         } else {
             fill_yuv_image(picture, frame_count, c->width, c->height);
         }
         } else {
             fill_yuv_image(picture, frame_count, c->width, c->height);
         }