# HG changeset patch # User arpi # Date 1025968834 0 # Node ID 715d93d492c3ad587101548c75eda5ddebfb48ed # Parent 64cf429bd7ebf103751133befb8bd1f0bf20d8b1 interlacing support - Klaus Stengel diff -r 64cf429bd7eb -r 715d93d492c3 libvo/vo_yuv4mpeg.c --- a/libvo/vo_yuv4mpeg.c Sat Jul 06 15:20:10 2002 +0000 +++ b/libvo/vo_yuv4mpeg.c Sat Jul 06 15:20:34 2002 +0000 @@ -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_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; + image_height = height; + image_width = width; + using_format = format; + + 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; - using_format = format; - image = malloc(write_bytes); + 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 @@ 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