From 02521a39aef8033ecbaa1ced6f52ad1358f0a940 Mon Sep 17 00:00:00 2001 From: arpi Date: Sat, 6 Jul 2002 15:20:34 +0000 Subject: [PATCH] interlacing support - Klaus Stengel git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@6660 b3059339-0415-0410-9bf9-f77b7e298cf2 --- libvo/vo_yuv4mpeg.c | 337 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 287 insertions(+), 50 deletions(-) diff --git a/libvo/vo_yuv4mpeg.c b/libvo/vo_yuv4mpeg.c index 33ba91783b..995716330e 100644 --- a/libvo/vo_yuv4mpeg.c +++ b/libvo/vo_yuv4mpeg.c @@ -8,6 +8,12 @@ * * This is undoubtedly incomplete, inaccurate, or just plain wrong. :-) * + * 2002/06/19 Klaus Stengel + * - added support for interlaced output + * Activate by using '-vo yuv4mpeg:interlaced' + * or '-vo yuv4mpeg:interlaced_bf' if your source has + * bottom fields first + * - added some additional checks to catch problems * * 2002/04/17 Juergen Hammelmann * - added support for output of subtitles @@ -49,35 +55,85 @@ static uint8_t *image_y = NULL; static uint8_t *image_u = NULL; static uint8_t *image_v = NULL; +static uint8_t *rgb_buffer = NULL; +static uint8_t *rgb_line_buffer = NULL; + static int using_format = 0; static FILE *yuv_out; -int write_bytes; +static int write_bytes; + +#define Y4M_ILACE_NONE 'p' /* non-interlaced, progressive frame */ +#define Y4M_ILACE_TOP_FIRST 't' /* interlaced, top-field first */ +#define Y4M_ILACE_BOTTOM_FIRST 'b' /* interlaced, bottom-field first */ + +/* Set progressive mode as default */ +static int config_interlace = Y4M_ILACE_NONE; +#define Y4M_IS_INTERLACED (config_interlace != Y4M_ILACE_NONE) static uint32_t config(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t fullscreen, char *title, uint32_t format, const vo_tune_info_t *tuneinfo) { - image_height = height; - image_width = width; - write_bytes = image_width * image_height * 3 / 2; + image_height = height; + image_width = width; using_format = format; - image = malloc(write_bytes); + + if (Y4M_IS_INTERLACED) + { + if (height % 4) + { + perror("yuv4mpeg: Interlaced mode requires image height to be divisable by 4"); + return -1; + } + + rgb_line_buffer = malloc(image_width * 3); + if (!rgb_line_buffer) + { + perror("yuv4mpeg: Unable to allocate line buffer for interlaced mode"); + return -1; + } + + if (using_format == IMGFMT_YV12) + printf("yuv4mpeg: WARNING: Input not RGB; Can't seperate chrominance by fields!\n"); + } + + if (width % 2) + { + perror("yuv4mpeg: Image width must be divisable by 2"); + return -1; + } + + if(using_format != IMGFMT_YV12) + { + rgb_buffer = malloc(image_width * image_height * 3); + if (!rgb_buffer) + { + perror("yuv4mpeg: Not enough memory to allocate RGB framebuffer"); + return -1; + } + } + + write_bytes = image_width * image_height * 3 / 2; + image = malloc(write_bytes); yuv_out = fopen("stream.yuv", "wb"); - if (!yuv_out || image == NULL) + if (!yuv_out || image == 0) { - perror("Can't get memory or file handle to stream.yuv"); + perror("yuv4mpeg: Can't get memory or file handle to write stream.yuv"); return -1; } image_y = image; image_u = image_y + image_width * image_height; - image_v = image_u + (image_width * image_height) / 4; + image_v = image_u + image_width * image_height / 4; // This isn't right. // But it should work as long as the file isn't interlaced // or otherwise unusual (the "Ip A0:0" part). - fprintf(yuv_out, "YUV4MPEG2 W%d H%d F%ld:%ld Ip A0:0\n", - image_width, image_height, (long)(vo_fps * 1000000.0), 1000000); + + /* At least the interlacing is ok now */ + fprintf(yuv_out, "YUV4MPEG2 W%d H%d F%ld:%ld I%c A0:0\n", + image_width, image_height, (long)(vo_fps * 1000000.0), + (long)1000000, config_interlace); fflush(yuv_out); return 0; @@ -88,12 +144,43 @@ static const vo_info_t* get_info(void) return &vo_info; } +/* Only use when h divisable by 2! */ +static void swap_fields(uint8_t *ptr, const int h, const int stride) +{ + int i; + + for (i=0; i