annotate libvo/vo_yuv4mpeg.c @ 14178:69d9d9ec86da

Sync with 1.823: Mention how to concatenate files with -vo yuv4mpeg and -fixed-vo. + back to my way of maintaining the date field (for now)
author gpoirier
date Fri, 17 Dec 2004 22:33:30 +0000
parents 9c47f90ad94a
children 08399423fe30
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4597
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
1 /*
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
2 * vo_yuv4mpeg.c, yuv4mpeg (mjpegtools) interface
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
3 *
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
4 * Thrown together by
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
5 * Robert Kesterson <robertk@robertk.com>
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
6 * Based on the pgm output plugin, the rgb2rgb postproc filter, divxdec,
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
7 * and probably others.
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
8 *
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
9 * This is undoubtedly incomplete, inaccurate, or just plain wrong. :-)
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
10 *
6659
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
11 * 2002/06/19 Klaus Stengel <Klaus.Stengel@asamnet.de>
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
12 * - added support for interlaced output
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
13 * Activate by using '-vo yuv4mpeg:interlaced'
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
14 * or '-vo yuv4mpeg:interlaced_bf' if your source has
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
15 * bottom fields first
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
16 * - added some additional checks to catch problems
5832
041bd56e41dc added support for output of subtitles - Juergen Hammelmann <juergen.hammelmann@gmx.de>
arpi
parents: 4737
diff changeset
17 *
041bd56e41dc added support for output of subtitles - Juergen Hammelmann <juergen.hammelmann@gmx.de>
arpi
parents: 4737
diff changeset
18 * 2002/04/17 Juergen Hammelmann <juergen.hammelmann@gmx.de>
041bd56e41dc added support for output of subtitles - Juergen Hammelmann <juergen.hammelmann@gmx.de>
arpi
parents: 4737
diff changeset
19 * - added support for output of subtitles
041bd56e41dc added support for output of subtitles - Juergen Hammelmann <juergen.hammelmann@gmx.de>
arpi
parents: 4737
diff changeset
20 * best, if you give option '-osdlevel 0' to mplayer for
041bd56e41dc added support for output of subtitles - Juergen Hammelmann <juergen.hammelmann@gmx.de>
arpi
parents: 4737
diff changeset
21 * no watching the seek+timer
4597
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
22 */
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
23
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
24 #include <stdio.h>
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
25 #include <stdlib.h>
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
26 #include <string.h>
4640
ea3bd3328fc6 removed unused includes, added fastmemcpy support, removed local copy of rgb24toyv12 (using one in postproc/rgb2rgb.c)
alex
parents: 4633
diff changeset
27 #include <unistd.h>
4737
32e1f5042f65 I don't like such reports: '-vo dga:vidix or -vo x11:vidix works fine for me'
nick
parents: 4706
diff changeset
28 #include <errno.h>
4640
ea3bd3328fc6 removed unused includes, added fastmemcpy support, removed local copy of rgb24toyv12 (using one in postproc/rgb2rgb.c)
alex
parents: 4633
diff changeset
29 #include <fcntl.h>
4597
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
30
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
31 #include "config.h"
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
32 #include "video_out.h"
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
33 #include "video_out_internal.h"
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
34
13462
01cc6b0a6e72 printf --> mp_msg transition in vo_yuv4mpeg
diego
parents: 10802
diff changeset
35 #include "mp_msg.h"
01cc6b0a6e72 printf --> mp_msg transition in vo_yuv4mpeg
diego
parents: 10802
diff changeset
36 #include "help_mp.h"
01cc6b0a6e72 printf --> mp_msg transition in vo_yuv4mpeg
diego
parents: 10802
diff changeset
37
5832
041bd56e41dc added support for output of subtitles - Juergen Hammelmann <juergen.hammelmann@gmx.de>
arpi
parents: 4737
diff changeset
38 #include "sub.h"
041bd56e41dc added support for output of subtitles - Juergen Hammelmann <juergen.hammelmann@gmx.de>
arpi
parents: 4737
diff changeset
39
4640
ea3bd3328fc6 removed unused includes, added fastmemcpy support, removed local copy of rgb24toyv12 (using one in postproc/rgb2rgb.c)
alex
parents: 4633
diff changeset
40 #include "fastmemcpy.h"
13787
e047e70a9767 Handle "xxx.h" vs "../xxx.h" include paths in a consistent way.
diego
parents: 13462
diff changeset
41 #include "postproc/rgb2rgb.h"
e047e70a9767 Handle "xxx.h" vs "../xxx.h" include paths in a consistent way.
diego
parents: 13462
diff changeset
42 #include "libmpcodecs/vf_scale.h"
4597
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
43
8148
5b39e79af5fe removed get_info, using the same sheme as in libmpcodecs instead
alex
parents: 7688
diff changeset
44 static vo_info_t info =
4597
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
45 {
14095
367ba4601d47 Add a file= suboption to set output file.
reimar
parents: 13787
diff changeset
46 "yuv4mpeg output for mjpegtools",
4597
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
47 "yuv4mpeg",
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
48 "Robert Kesterson <robertk@robertk.com>",
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
49 ""
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
50 };
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
51
8148
5b39e79af5fe removed get_info, using the same sheme as in libmpcodecs instead
alex
parents: 7688
diff changeset
52 LIBVO_EXTERN (yuv4mpeg)
5b39e79af5fe removed get_info, using the same sheme as in libmpcodecs instead
alex
parents: 7688
diff changeset
53
14145
9c47f90ad94a fix leak with -fixed-vo, allow concatenating
reimar
parents: 14095
diff changeset
54 static int image_width = 0;
9c47f90ad94a fix leak with -fixed-vo, allow concatenating
reimar
parents: 14095
diff changeset
55 static int image_height = 0;
9c47f90ad94a fix leak with -fixed-vo, allow concatenating
reimar
parents: 14095
diff changeset
56 static float image_fps = 0;
4597
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
57
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
58 static uint8_t *image = NULL;
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
59 static uint8_t *image_y = NULL;
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
60 static uint8_t *image_u = NULL;
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
61 static uint8_t *image_v = NULL;
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
62
6659
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
63 static uint8_t *rgb_buffer = NULL;
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
64 static uint8_t *rgb_line_buffer = NULL;
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
65
14095
367ba4601d47 Add a file= suboption to set output file.
reimar
parents: 13787
diff changeset
66 static char *yuv_filename = NULL;
367ba4601d47 Add a file= suboption to set output file.
reimar
parents: 13787
diff changeset
67
4597
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
68 static int using_format = 0;
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
69 static FILE *yuv_out;
6659
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
70 static int write_bytes;
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
71
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
72 #define Y4M_ILACE_NONE 'p' /* non-interlaced, progressive frame */
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
73 #define Y4M_ILACE_TOP_FIRST 't' /* interlaced, top-field first */
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
74 #define Y4M_ILACE_BOTTOM_FIRST 'b' /* interlaced, bottom-field first */
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
75
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
76 /* Set progressive mode as default */
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
77 static int config_interlace = Y4M_ILACE_NONE;
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
78 #define Y4M_IS_INTERLACED (config_interlace != Y4M_ILACE_NONE)
4597
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
79
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
80 static uint32_t config(uint32_t width, uint32_t height, uint32_t d_width,
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
81 uint32_t d_height, uint32_t fullscreen, char *title,
7124
eca7dbad0166 finally removed query_vaa, bes_da and vo_tune_info - the obsoleted libvo api
alex
parents: 6659
diff changeset
82 uint32_t format)
4597
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
83 {
14145
9c47f90ad94a fix leak with -fixed-vo, allow concatenating
reimar
parents: 14095
diff changeset
84 if (image_width == width && image_height == height &&
9c47f90ad94a fix leak with -fixed-vo, allow concatenating
reimar
parents: 14095
diff changeset
85 image_fps == vo_fps && vo_config_count)
9c47f90ad94a fix leak with -fixed-vo, allow concatenating
reimar
parents: 14095
diff changeset
86 return 0;
9c47f90ad94a fix leak with -fixed-vo, allow concatenating
reimar
parents: 14095
diff changeset
87 if (vo_config_count) {
9c47f90ad94a fix leak with -fixed-vo, allow concatenating
reimar
parents: 14095
diff changeset
88 mp_msg(MSGT_VO, MSGL_WARN,
9c47f90ad94a fix leak with -fixed-vo, allow concatenating
reimar
parents: 14095
diff changeset
89 "Video formats differ (w:%i=>%i, h:%i=>%i, fps:%f=>%f), "
9c47f90ad94a fix leak with -fixed-vo, allow concatenating
reimar
parents: 14095
diff changeset
90 "restarting output.\n",
9c47f90ad94a fix leak with -fixed-vo, allow concatenating
reimar
parents: 14095
diff changeset
91 image_width, width, image_height, height, image_fps, vo_fps);
9c47f90ad94a fix leak with -fixed-vo, allow concatenating
reimar
parents: 14095
diff changeset
92 uninit();
9c47f90ad94a fix leak with -fixed-vo, allow concatenating
reimar
parents: 14095
diff changeset
93 }
6659
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
94 image_height = height;
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
95 image_width = width;
14145
9c47f90ad94a fix leak with -fixed-vo, allow concatenating
reimar
parents: 14095
diff changeset
96 image_fps = vo_fps;
6659
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
97 using_format = format;
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
98
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
99 if (Y4M_IS_INTERLACED)
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
100 {
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
101 if (height % 4)
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
102 {
13462
01cc6b0a6e72 printf --> mp_msg transition in vo_yuv4mpeg
diego
parents: 10802
diff changeset
103 mp_msg(MSGT_VO,MSGL_FATAL,
01cc6b0a6e72 printf --> mp_msg transition in vo_yuv4mpeg
diego
parents: 10802
diff changeset
104 MSGTR_VO_YUV4MPEG_InterlacedHeightDivisibleBy4);
6659
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
105 return -1;
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
106 }
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
107
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
108 rgb_line_buffer = malloc(image_width * 3);
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
109 if (!rgb_line_buffer)
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
110 {
13462
01cc6b0a6e72 printf --> mp_msg transition in vo_yuv4mpeg
diego
parents: 10802
diff changeset
111 mp_msg(MSGT_VO,MSGL_FATAL,
01cc6b0a6e72 printf --> mp_msg transition in vo_yuv4mpeg
diego
parents: 10802
diff changeset
112 MSGTR_VO_YUV4MPEG_InterlacedLineBufAllocFail);
6659
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
113 return -1;
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
114 }
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
115
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
116 if (using_format == IMGFMT_YV12)
13462
01cc6b0a6e72 printf --> mp_msg transition in vo_yuv4mpeg
diego
parents: 10802
diff changeset
117 mp_msg(MSGT_VO,MSGL_WARN,
01cc6b0a6e72 printf --> mp_msg transition in vo_yuv4mpeg
diego
parents: 10802
diff changeset
118 MSGTR_VO_YUV4MPEG_InterlacedInputNotRGB);
6659
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
119 }
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
120
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
121 if (width % 2)
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
122 {
13462
01cc6b0a6e72 printf --> mp_msg transition in vo_yuv4mpeg
diego
parents: 10802
diff changeset
123 mp_msg(MSGT_VO,MSGL_FATAL,
01cc6b0a6e72 printf --> mp_msg transition in vo_yuv4mpeg
diego
parents: 10802
diff changeset
124 MSGTR_VO_YUV4MPEG_WidthDivisibleBy2);
6659
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
125 return -1;
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
126 }
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
127
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
128 if(using_format != IMGFMT_YV12)
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
129 {
10802
alex
parents: 8450
diff changeset
130 sws_rgb2rgb_init(get_sws_cpuflags());
6659
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
131 rgb_buffer = malloc(image_width * image_height * 3);
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
132 if (!rgb_buffer)
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
133 {
13462
01cc6b0a6e72 printf --> mp_msg transition in vo_yuv4mpeg
diego
parents: 10802
diff changeset
134 mp_msg(MSGT_VO,MSGL_FATAL,
01cc6b0a6e72 printf --> mp_msg transition in vo_yuv4mpeg
diego
parents: 10802
diff changeset
135 MSGTR_VO_YUV4MPEG_NoMemRGBFrameBuf);
6659
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
136 return -1;
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
137 }
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
138 }
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
139
4597
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
140 write_bytes = image_width * image_height * 3 / 2;
6659
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
141 image = malloc(write_bytes);
4597
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
142
14095
367ba4601d47 Add a file= suboption to set output file.
reimar
parents: 13787
diff changeset
143 yuv_out = fopen(yuv_filename ? yuv_filename : "stream.yuv", "wb");
6659
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
144 if (!yuv_out || image == 0)
4597
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
145 {
13462
01cc6b0a6e72 printf --> mp_msg transition in vo_yuv4mpeg
diego
parents: 10802
diff changeset
146 mp_msg(MSGT_VO,MSGL_FATAL,
14095
367ba4601d47 Add a file= suboption to set output file.
reimar
parents: 13787
diff changeset
147 MSGTR_VO_YUV4MPEG_OutFileOpenError,
367ba4601d47 Add a file= suboption to set output file.
reimar
parents: 13787
diff changeset
148 yuv_filename ? yuv_filename : "stream.yuv");
4597
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
149 return -1;
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
150 }
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
151 image_y = image;
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
152 image_u = image_y + image_width * image_height;
6659
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
153 image_v = image_u + image_width * image_height / 4;
4597
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
154
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
155 // This isn't right.
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
156 // But it should work as long as the file isn't interlaced
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
157 // or otherwise unusual (the "Ip A0:0" part).
6659
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
158
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
159 /* At least the interlacing is ok now */
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
160 fprintf(yuv_out, "YUV4MPEG2 W%d H%d F%ld:%ld I%c A0:0\n",
14145
9c47f90ad94a fix leak with -fixed-vo, allow concatenating
reimar
parents: 14095
diff changeset
161 image_width, image_height, (long)(image_fps * 1000000.0),
6659
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
162 (long)1000000, config_interlace);
4597
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
163
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
164 fflush(yuv_out);
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
165 return 0;
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
166 }
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
167
6659
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
168 /* Only use when h divisable by 2! */
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
169 static void swap_fields(uint8_t *ptr, const int h, const int stride)
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
170 {
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
171 int i;
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
172
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
173 for (i=0; i<h; i +=2)
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
174 {
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
175 memcpy(rgb_line_buffer , ptr + stride * i , stride);
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
176 memcpy(ptr + stride * i , ptr + stride * (i+1), stride);
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
177 memcpy(ptr + stride * (i+1), rgb_line_buffer , stride);
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
178 }
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
179 }
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
180
5832
041bd56e41dc added support for output of subtitles - Juergen Hammelmann <juergen.hammelmann@gmx.de>
arpi
parents: 4737
diff changeset
181 static void draw_alpha(int x0, int y0, int w, int h, unsigned char *src,
041bd56e41dc added support for output of subtitles - Juergen Hammelmann <juergen.hammelmann@gmx.de>
arpi
parents: 4737
diff changeset
182 unsigned char *srca, int stride) {
6659
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
183 switch (using_format)
5832
041bd56e41dc added support for output of subtitles - Juergen Hammelmann <juergen.hammelmann@gmx.de>
arpi
parents: 4737
diff changeset
184 {
6659
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
185 case IMGFMT_YV12:
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
186 vo_draw_alpha_yv12(w, h, src, srca, stride,
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
187 image + y0 * image_width + x0, image_width);
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
188 break;
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
189
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
190 case IMGFMT_BGR|24:
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
191 case IMGFMT_RGB|24:
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
192 if (config_interlace != Y4M_ILACE_BOTTOM_FIRST)
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
193 vo_draw_alpha_rgb24(w, h, src, srca, stride,
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
194 rgb_buffer + (y0 * image_width + x0) * 3, image_width * 3);
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
195 else
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
196 {
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
197 swap_fields (rgb_buffer, image_height, image_width * 3);
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
198
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
199 vo_draw_alpha_rgb24(w, h, src, srca, stride,
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
200 rgb_buffer + (y0 * image_width + x0) * 3, image_width * 3);
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
201
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
202 swap_fields (rgb_buffer, image_height, image_width * 3);
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
203 }
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
204 break;
5832
041bd56e41dc added support for output of subtitles - Juergen Hammelmann <juergen.hammelmann@gmx.de>
arpi
parents: 4737
diff changeset
205 }
041bd56e41dc added support for output of subtitles - Juergen Hammelmann <juergen.hammelmann@gmx.de>
arpi
parents: 4737
diff changeset
206 }
041bd56e41dc added support for output of subtitles - Juergen Hammelmann <juergen.hammelmann@gmx.de>
arpi
parents: 4737
diff changeset
207
4597
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
208 static void draw_osd(void)
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
209 {
5832
041bd56e41dc added support for output of subtitles - Juergen Hammelmann <juergen.hammelmann@gmx.de>
arpi
parents: 4737
diff changeset
210 vo_draw_text(image_width, image_height, draw_alpha);
4597
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
211 }
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
212
6659
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
213 static void deinterleave_fields(uint8_t *ptr, const int stride,
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
214 const int img_height)
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
215 {
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
216 unsigned int i, j, k_start = 1, modv = img_height - 1;
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
217 unsigned char *line_state = malloc(modv);
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
218
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
219 for (i=0; i<modv; i++)
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
220 line_state[i] = 0;
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
221
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
222 line_state[0] = 1;
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
223
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
224 while(k_start < modv)
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
225 {
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
226 i = j = k_start;
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
227 memcpy(rgb_line_buffer, ptr + stride * i, stride);
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
228
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
229 while (!line_state[j])
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
230 {
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
231 line_state[j] = 1;
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
232 i = j;
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
233 j = j * 2 % modv;
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
234 memcpy(ptr + stride * i, ptr + stride * j, stride);
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
235 }
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
236 memcpy(ptr + stride * i, rgb_line_buffer, stride);
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
237
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
238 while(k_start < modv && line_state[k_start])
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
239 k_start++;
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
240 }
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
241 free(line_state);
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
242 }
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
243
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
244 static void vo_y4m_write(const void *ptr, const size_t num_bytes)
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
245 {
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
246 if (fwrite(ptr, 1, num_bytes, yuv_out) != num_bytes)
13462
01cc6b0a6e72 printf --> mp_msg transition in vo_yuv4mpeg
diego
parents: 10802
diff changeset
247 mp_msg(MSGT_VO,MSGL_ERR,
01cc6b0a6e72 printf --> mp_msg transition in vo_yuv4mpeg
diego
parents: 10802
diff changeset
248 MSGTR_VO_YUV4MPEG_OutFileWriteError);
6659
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
249 }
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
250
8450
8cfc9309f0cc notice vo driver about skipped/dropped frames
arpi
parents: 8148
diff changeset
251 static int write_last_frame(void)
8cfc9309f0cc notice vo driver about skipped/dropped frames
arpi
parents: 8148
diff changeset
252 {
8cfc9309f0cc notice vo driver about skipped/dropped frames
arpi
parents: 8148
diff changeset
253
8cfc9309f0cc notice vo driver about skipped/dropped frames
arpi
parents: 8148
diff changeset
254 uint8_t *upper_y, *upper_u, *upper_v, *rgb_buffer_lower;
8cfc9309f0cc notice vo driver about skipped/dropped frames
arpi
parents: 8148
diff changeset
255 int rgb_stride, uv_stride, field_height;
8cfc9309f0cc notice vo driver about skipped/dropped frames
arpi
parents: 8148
diff changeset
256 unsigned int i, low_ofs;
8cfc9309f0cc notice vo driver about skipped/dropped frames
arpi
parents: 8148
diff changeset
257
8cfc9309f0cc notice vo driver about skipped/dropped frames
arpi
parents: 8148
diff changeset
258 fprintf(yuv_out, "FRAME\n");
8cfc9309f0cc notice vo driver about skipped/dropped frames
arpi
parents: 8148
diff changeset
259
8cfc9309f0cc notice vo driver about skipped/dropped frames
arpi
parents: 8148
diff changeset
260 if (using_format != IMGFMT_YV12)
8cfc9309f0cc notice vo driver about skipped/dropped frames
arpi
parents: 8148
diff changeset
261 {
8cfc9309f0cc notice vo driver about skipped/dropped frames
arpi
parents: 8148
diff changeset
262 rgb_stride = image_width * 3;
8cfc9309f0cc notice vo driver about skipped/dropped frames
arpi
parents: 8148
diff changeset
263 uv_stride = image_width / 2;
8cfc9309f0cc notice vo driver about skipped/dropped frames
arpi
parents: 8148
diff changeset
264
8cfc9309f0cc notice vo driver about skipped/dropped frames
arpi
parents: 8148
diff changeset
265 if (Y4M_IS_INTERLACED)
8cfc9309f0cc notice vo driver about skipped/dropped frames
arpi
parents: 8148
diff changeset
266 {
8cfc9309f0cc notice vo driver about skipped/dropped frames
arpi
parents: 8148
diff changeset
267 field_height = image_height / 2;
8cfc9309f0cc notice vo driver about skipped/dropped frames
arpi
parents: 8148
diff changeset
268
8cfc9309f0cc notice vo driver about skipped/dropped frames
arpi
parents: 8148
diff changeset
269 upper_y = image;
8cfc9309f0cc notice vo driver about skipped/dropped frames
arpi
parents: 8148
diff changeset
270 upper_u = upper_y + image_width * field_height;
8cfc9309f0cc notice vo driver about skipped/dropped frames
arpi
parents: 8148
diff changeset
271 upper_v = upper_u + image_width * field_height / 4;
8cfc9309f0cc notice vo driver about skipped/dropped frames
arpi
parents: 8148
diff changeset
272 low_ofs = image_width * field_height * 3 / 2;
8cfc9309f0cc notice vo driver about skipped/dropped frames
arpi
parents: 8148
diff changeset
273 rgb_buffer_lower = rgb_buffer + rgb_stride * field_height;
8cfc9309f0cc notice vo driver about skipped/dropped frames
arpi
parents: 8148
diff changeset
274
8cfc9309f0cc notice vo driver about skipped/dropped frames
arpi
parents: 8148
diff changeset
275 /* Write Y plane */
8cfc9309f0cc notice vo driver about skipped/dropped frames
arpi
parents: 8148
diff changeset
276 for(i = 0; i < field_height; i++)
8cfc9309f0cc notice vo driver about skipped/dropped frames
arpi
parents: 8148
diff changeset
277 {
8cfc9309f0cc notice vo driver about skipped/dropped frames
arpi
parents: 8148
diff changeset
278 vo_y4m_write(upper_y + image_width * i, image_width);
8cfc9309f0cc notice vo driver about skipped/dropped frames
arpi
parents: 8148
diff changeset
279 vo_y4m_write(upper_y + image_width * i + low_ofs, image_width);
8cfc9309f0cc notice vo driver about skipped/dropped frames
arpi
parents: 8148
diff changeset
280 }
8cfc9309f0cc notice vo driver about skipped/dropped frames
arpi
parents: 8148
diff changeset
281
8cfc9309f0cc notice vo driver about skipped/dropped frames
arpi
parents: 8148
diff changeset
282 /* Write U and V plane */
8cfc9309f0cc notice vo driver about skipped/dropped frames
arpi
parents: 8148
diff changeset
283 for(i = 0; i < field_height / 2; i++)
8cfc9309f0cc notice vo driver about skipped/dropped frames
arpi
parents: 8148
diff changeset
284 {
8cfc9309f0cc notice vo driver about skipped/dropped frames
arpi
parents: 8148
diff changeset
285 vo_y4m_write(upper_u + uv_stride * i, uv_stride);
8cfc9309f0cc notice vo driver about skipped/dropped frames
arpi
parents: 8148
diff changeset
286 vo_y4m_write(upper_u + uv_stride * i + low_ofs, uv_stride);
8cfc9309f0cc notice vo driver about skipped/dropped frames
arpi
parents: 8148
diff changeset
287 }
8cfc9309f0cc notice vo driver about skipped/dropped frames
arpi
parents: 8148
diff changeset
288 for(i = 0; i < field_height / 2; i++)
8cfc9309f0cc notice vo driver about skipped/dropped frames
arpi
parents: 8148
diff changeset
289 {
8cfc9309f0cc notice vo driver about skipped/dropped frames
arpi
parents: 8148
diff changeset
290 vo_y4m_write(upper_v + uv_stride * i, uv_stride);
8cfc9309f0cc notice vo driver about skipped/dropped frames
arpi
parents: 8148
diff changeset
291 vo_y4m_write(upper_v + uv_stride * i + low_ofs, uv_stride);
8cfc9309f0cc notice vo driver about skipped/dropped frames
arpi
parents: 8148
diff changeset
292 }
8cfc9309f0cc notice vo driver about skipped/dropped frames
arpi
parents: 8148
diff changeset
293 return VO_TRUE; /* Image written; We have to stop here */
8cfc9309f0cc notice vo driver about skipped/dropped frames
arpi
parents: 8148
diff changeset
294 }
8cfc9309f0cc notice vo driver about skipped/dropped frames
arpi
parents: 8148
diff changeset
295 }
8cfc9309f0cc notice vo driver about skipped/dropped frames
arpi
parents: 8148
diff changeset
296 /* Write progressive frame */
8cfc9309f0cc notice vo driver about skipped/dropped frames
arpi
parents: 8148
diff changeset
297 vo_y4m_write(image, write_bytes);
8cfc9309f0cc notice vo driver about skipped/dropped frames
arpi
parents: 8148
diff changeset
298 return VO_TRUE;
8cfc9309f0cc notice vo driver about skipped/dropped frames
arpi
parents: 8148
diff changeset
299 }
8cfc9309f0cc notice vo driver about skipped/dropped frames
arpi
parents: 8148
diff changeset
300
4597
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
301 static void flip_page (void)
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
302 {
6659
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
303 uint8_t *upper_y, *upper_u, *upper_v, *rgb_buffer_lower;
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
304 int rgb_stride, uv_stride, field_height;
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
305 unsigned int i, low_ofs;
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
306
4597
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
307 fprintf(yuv_out, "FRAME\n");
6659
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
308
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
309 if (using_format != IMGFMT_YV12)
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
310 {
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
311 rgb_stride = image_width * 3;
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
312 uv_stride = image_width / 2;
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
313
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
314 if (Y4M_IS_INTERLACED)
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
315 {
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
316 field_height = image_height / 2;
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
317
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
318 upper_y = image;
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
319 upper_u = upper_y + image_width * field_height;
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
320 upper_v = upper_u + image_width * field_height / 4;
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
321 low_ofs = image_width * field_height * 3 / 2;
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
322 rgb_buffer_lower = rgb_buffer + rgb_stride * field_height;
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
323
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
324 deinterleave_fields(rgb_buffer, rgb_stride, image_height);
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
325
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
326 rgb24toyv12(rgb_buffer, upper_y, upper_u, upper_v,
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
327 image_width, field_height,
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
328 image_width, uv_stride, rgb_stride);
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
329 rgb24toyv12(rgb_buffer_lower, upper_y + low_ofs,
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
330 upper_u + low_ofs, upper_v + low_ofs,
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
331 image_width, field_height,
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
332 image_width, uv_stride, rgb_stride);
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
333
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
334 /* Write Y plane */
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
335 for(i = 0; i < field_height; i++)
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
336 {
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
337 vo_y4m_write(upper_y + image_width * i, image_width);
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
338 vo_y4m_write(upper_y + image_width * i + low_ofs, image_width);
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
339 }
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
340
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
341 /* Write U and V plane */
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
342 for(i = 0; i < field_height / 2; i++)
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
343 {
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
344 vo_y4m_write(upper_u + uv_stride * i, uv_stride);
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
345 vo_y4m_write(upper_u + uv_stride * i + low_ofs, uv_stride);
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
346 }
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
347 for(i = 0; i < field_height / 2; i++)
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
348 {
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
349 vo_y4m_write(upper_v + uv_stride * i, uv_stride);
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
350 vo_y4m_write(upper_v + uv_stride * i + low_ofs, uv_stride);
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
351 }
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
352 return; /* Image written; We have to stop here */
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
353 }
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
354
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
355 rgb24toyv12(rgb_buffer, image_y, image_u, image_v,
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
356 image_width, image_height,
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
357 image_width, uv_stride, rgb_stride);
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
358 }
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
359
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
360 /* Write progressive frame */
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
361 vo_y4m_write(image, write_bytes);
4597
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
362 }
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
363
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
364 static uint32_t draw_slice(uint8_t *srcimg[], int stride[], int w,int h,int x,int y)
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
365 {
6659
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
366 int i;
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
367 uint8_t *dst, *src = srcimg[0];
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
368
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
369 switch (using_format)
4597
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
370 {
6659
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
371 case IMGFMT_YV12:
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
372
4597
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
373 // copy Y:
6659
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
374 dst = image_y + image_width * y + x;
4597
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
375 for (i = 0; i < h; i++)
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
376 {
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
377 memcpy(dst, src, w);
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
378 src += stride[0];
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
379 dst += image_width;
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
380 }
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
381 {
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
382 // copy U + V:
4706
a4400910be9f yv12 slices fix by Robert Kesterson <robertk@robertk.com>
arpi
parents: 4640
diff changeset
383 int imgstride = image_width >> 1;
4597
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
384 uint8_t *src1 = srcimg[1];
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
385 uint8_t *src2 = srcimg[2];
4706
a4400910be9f yv12 slices fix by Robert Kesterson <robertk@robertk.com>
arpi
parents: 4640
diff changeset
386 uint8_t *dstu = image_u + imgstride * (y >> 1) + (x >> 1);
a4400910be9f yv12 slices fix by Robert Kesterson <robertk@robertk.com>
arpi
parents: 4640
diff changeset
387 uint8_t *dstv = image_v + imgstride * (y >> 1) + (x >> 1);
4597
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
388 for (i = 0; i < h / 2; i++)
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
389 {
4706
a4400910be9f yv12 slices fix by Robert Kesterson <robertk@robertk.com>
arpi
parents: 4640
diff changeset
390 memcpy(dstu, src1 , w >> 1);
a4400910be9f yv12 slices fix by Robert Kesterson <robertk@robertk.com>
arpi
parents: 4640
diff changeset
391 memcpy(dstv, src2, w >> 1);
4597
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
392 src1 += stride[1];
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
393 src2 += stride[2];
4706
a4400910be9f yv12 slices fix by Robert Kesterson <robertk@robertk.com>
arpi
parents: 4640
diff changeset
394 dstu += imgstride;
a4400910be9f yv12 slices fix by Robert Kesterson <robertk@robertk.com>
arpi
parents: 4640
diff changeset
395 dstv += imgstride;
4597
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
396 }
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
397 }
6659
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
398 break;
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
399
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
400 case IMGFMT_BGR24:
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
401 case IMGFMT_RGB24:
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
402 dst = rgb_buffer + (image_width * y + x) * 3;
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
403 for (i = 0; i < h; i++)
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
404 {
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
405 memcpy(dst, src, w * 3);
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
406 src += stride[0];
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
407 dst += image_width * 3;
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
408 }
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
409 break;
4597
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
410 }
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
411 return 0;
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
412 }
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
413
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
414 static uint32_t draw_frame(uint8_t * src[])
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
415 {
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
416 switch(using_format)
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
417 {
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
418 case IMGFMT_YV12:
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
419 // gets done in draw_slice
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
420 break;
6659
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
421
7688
41d242c5bee1 since draw_slice() can handle packed RGB too, set the VFCAP_ACCEPT_STRIDE flag
arpi
parents: 7124
diff changeset
422 case IMGFMT_BGR24:
41d242c5bee1 since draw_slice() can handle packed RGB too, set the VFCAP_ACCEPT_STRIDE flag
arpi
parents: 7124
diff changeset
423 case IMGFMT_RGB24:
6659
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
424 memcpy(rgb_buffer, src[0], image_width * image_height * 3);
4597
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
425 break;
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
426 }
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
427 return 0;
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
428 }
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
429
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
430 static uint32_t query_format(uint32_t format)
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
431 {
6659
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
432
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
433 if (Y4M_IS_INTERLACED)
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
434 {
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
435 /* When processing interlaced material we want to get the raw RGB
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
436 * data and do the YV12 conversion ourselves to have the chrominance
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
437 * information sampled correct. */
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
438
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
439 switch(format)
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
440 {
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
441 case IMGFMT_YV12:
7688
41d242c5bee1 since draw_slice() can handle packed RGB too, set the VFCAP_ACCEPT_STRIDE flag
arpi
parents: 7124
diff changeset
442 return VFCAP_CSP_SUPPORTED|VFCAP_OSD|VFCAP_ACCEPT_STRIDE;
6659
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
443 case IMGFMT_BGR|24:
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
444 case IMGFMT_RGB|24:
7688
41d242c5bee1 since draw_slice() can handle packed RGB too, set the VFCAP_ACCEPT_STRIDE flag
arpi
parents: 7124
diff changeset
445 return VFCAP_CSP_SUPPORTED|VFCAP_CSP_SUPPORTED_BY_HW|VFCAP_OSD|VFCAP_ACCEPT_STRIDE;
6659
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
446 }
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
447 }
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
448 else
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
449 {
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
450
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
451 switch(format)
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
452 {
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
453 case IMGFMT_YV12:
7688
41d242c5bee1 since draw_slice() can handle packed RGB too, set the VFCAP_ACCEPT_STRIDE flag
arpi
parents: 7124
diff changeset
454 return VFCAP_CSP_SUPPORTED|VFCAP_CSP_SUPPORTED_BY_HW|VFCAP_OSD|VFCAP_ACCEPT_STRIDE;
6659
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
455 case IMGFMT_BGR|24:
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
456 case IMGFMT_RGB|24:
7688
41d242c5bee1 since draw_slice() can handle packed RGB too, set the VFCAP_ACCEPT_STRIDE flag
arpi
parents: 7124
diff changeset
457 return VFCAP_CSP_SUPPORTED|VFCAP_OSD|VFCAP_ACCEPT_STRIDE;
6659
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
458 }
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
459 }
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
460 return 0;
4597
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
461 }
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
462
14145
9c47f90ad94a fix leak with -fixed-vo, allow concatenating
reimar
parents: 14095
diff changeset
463 // WARNING: config(...) also uses this
4597
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
464 static void uninit(void)
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
465 {
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
466 if(image)
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
467 free(image);
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
468 image = NULL;
6659
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
469
4597
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
470 if(yuv_out)
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
471 fclose(yuv_out);
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
472 yuv_out = NULL;
6659
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
473
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
474 if(rgb_buffer)
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
475 free(rgb_buffer);
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
476 rgb_buffer = NULL;
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
477
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
478 if(rgb_line_buffer)
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
479 free(rgb_line_buffer);
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
480 rgb_line_buffer = NULL;
14095
367ba4601d47 Add a file= suboption to set output file.
reimar
parents: 13787
diff changeset
481
367ba4601d47 Add a file= suboption to set output file.
reimar
parents: 13787
diff changeset
482 if (yuv_filename)
367ba4601d47 Add a file= suboption to set output file.
reimar
parents: 13787
diff changeset
483 free(yuv_filename);
367ba4601d47 Add a file= suboption to set output file.
reimar
parents: 13787
diff changeset
484 yuv_filename = NULL;
14145
9c47f90ad94a fix leak with -fixed-vo, allow concatenating
reimar
parents: 14095
diff changeset
485 image_width = 0;
9c47f90ad94a fix leak with -fixed-vo, allow concatenating
reimar
parents: 14095
diff changeset
486 image_height = 0;
9c47f90ad94a fix leak with -fixed-vo, allow concatenating
reimar
parents: 14095
diff changeset
487 image_fps = 0;
4597
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
488 }
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
489
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
490
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
491 static void check_events(void)
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
492 {
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
493 }
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
494
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
495
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
496 static uint32_t preinit(const char *arg)
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
497 {
4737
32e1f5042f65 I don't like such reports: '-vo dga:vidix or -vo x11:vidix works fine for me'
nick
parents: 4706
diff changeset
498 if(arg)
32e1f5042f65 I don't like such reports: '-vo dga:vidix or -vo x11:vidix works fine for me'
nick
parents: 4706
diff changeset
499 {
14095
367ba4601d47 Add a file= suboption to set output file.
reimar
parents: 13787
diff changeset
500 int parse_err = 0;
367ba4601d47 Add a file= suboption to set output file.
reimar
parents: 13787
diff changeset
501 unsigned int parse_pos = 0;
6659
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
502
14095
367ba4601d47 Add a file= suboption to set output file.
reimar
parents: 13787
diff changeset
503 while (arg[parse_pos] && !parse_err) {
367ba4601d47 Add a file= suboption to set output file.
reimar
parents: 13787
diff changeset
504 if (strncmp (&arg[parse_pos], "interlaced", 10) == 0) {
367ba4601d47 Add a file= suboption to set output file.
reimar
parents: 13787
diff changeset
505 parse_pos += 10;
367ba4601d47 Add a file= suboption to set output file.
reimar
parents: 13787
diff changeset
506 config_interlace = Y4M_ILACE_TOP_FIRST;
367ba4601d47 Add a file= suboption to set output file.
reimar
parents: 13787
diff changeset
507 }
367ba4601d47 Add a file= suboption to set output file.
reimar
parents: 13787
diff changeset
508 else if (strncmp (&arg[parse_pos], "interlaced_bf", 13) == 0) {
367ba4601d47 Add a file= suboption to set output file.
reimar
parents: 13787
diff changeset
509 parse_pos += 13;
367ba4601d47 Add a file= suboption to set output file.
reimar
parents: 13787
diff changeset
510 config_interlace = Y4M_ILACE_BOTTOM_FIRST;
367ba4601d47 Add a file= suboption to set output file.
reimar
parents: 13787
diff changeset
511 }
367ba4601d47 Add a file= suboption to set output file.
reimar
parents: 13787
diff changeset
512 else if (strncmp (&arg[parse_pos], "file=", 5) == 0) {
367ba4601d47 Add a file= suboption to set output file.
reimar
parents: 13787
diff changeset
513 int file_len;
367ba4601d47 Add a file= suboption to set output file.
reimar
parents: 13787
diff changeset
514 parse_pos += 5;
367ba4601d47 Add a file= suboption to set output file.
reimar
parents: 13787
diff changeset
515 file_len = strcspn (&arg[parse_pos], ":");
367ba4601d47 Add a file= suboption to set output file.
reimar
parents: 13787
diff changeset
516 if (file_len < 0) {
367ba4601d47 Add a file= suboption to set output file.
reimar
parents: 13787
diff changeset
517 parse_err = 1;
367ba4601d47 Add a file= suboption to set output file.
reimar
parents: 13787
diff changeset
518 break;
6659
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
519 }
14095
367ba4601d47 Add a file= suboption to set output file.
reimar
parents: 13787
diff changeset
520 yuv_filename = malloc (file_len + 1);
367ba4601d47 Add a file= suboption to set output file.
reimar
parents: 13787
diff changeset
521 memcpy (yuv_filename, &arg[parse_pos], file_len);
367ba4601d47 Add a file= suboption to set output file.
reimar
parents: 13787
diff changeset
522 yuv_filename[file_len] = 0;
367ba4601d47 Add a file= suboption to set output file.
reimar
parents: 13787
diff changeset
523 parse_pos += file_len;
367ba4601d47 Add a file= suboption to set output file.
reimar
parents: 13787
diff changeset
524 }
367ba4601d47 Add a file= suboption to set output file.
reimar
parents: 13787
diff changeset
525 if (arg[parse_pos] == ':') parse_pos++;
367ba4601d47 Add a file= suboption to set output file.
reimar
parents: 13787
diff changeset
526 else if (arg[parse_pos]) parse_err = 1;
367ba4601d47 Add a file= suboption to set output file.
reimar
parents: 13787
diff changeset
527 }
367ba4601d47 Add a file= suboption to set output file.
reimar
parents: 13787
diff changeset
528 if (parse_err) {
367ba4601d47 Add a file= suboption to set output file.
reimar
parents: 13787
diff changeset
529 mp_msg(MSGT_VO,MSGL_FATAL,
367ba4601d47 Add a file= suboption to set output file.
reimar
parents: 13787
diff changeset
530 MSGTR_VO_YUV4MPEG_UnknownSubDev,arg);
367ba4601d47 Add a file= suboption to set output file.
reimar
parents: 13787
diff changeset
531 return -1;
367ba4601d47 Add a file= suboption to set output file.
reimar
parents: 13787
diff changeset
532 }
6659
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
533 }
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
534
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
535 /* Inform user which output mode is used */
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
536 switch (config_interlace)
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
537 {
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
538 case Y4M_ILACE_TOP_FIRST:
13462
01cc6b0a6e72 printf --> mp_msg transition in vo_yuv4mpeg
diego
parents: 10802
diff changeset
539 mp_msg(MSGT_VO,MSGL_STATUS,
01cc6b0a6e72 printf --> mp_msg transition in vo_yuv4mpeg
diego
parents: 10802
diff changeset
540 MSGTR_VO_YUV4MPEG_InterlacedTFFMode);
6659
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
541 break;
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
542 case Y4M_ILACE_BOTTOM_FIRST:
13462
01cc6b0a6e72 printf --> mp_msg transition in vo_yuv4mpeg
diego
parents: 10802
diff changeset
543 mp_msg(MSGT_VO,MSGL_STATUS,
01cc6b0a6e72 printf --> mp_msg transition in vo_yuv4mpeg
diego
parents: 10802
diff changeset
544 MSGTR_VO_YUV4MPEG_InterlacedBFFMode);
6659
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
545 break;
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
546 default:
13462
01cc6b0a6e72 printf --> mp_msg transition in vo_yuv4mpeg
diego
parents: 10802
diff changeset
547 mp_msg(MSGT_VO,MSGL_STATUS,
01cc6b0a6e72 printf --> mp_msg transition in vo_yuv4mpeg
diego
parents: 10802
diff changeset
548 MSGTR_VO_YUV4MPEG_ProgressiveMode);
6659
715d93d492c3 interlacing support - Klaus Stengel <ks1@inter-ject.de>
arpi
parents: 6213
diff changeset
549 break;
4737
32e1f5042f65 I don't like such reports: '-vo dga:vidix or -vo x11:vidix works fine for me'
nick
parents: 4706
diff changeset
550 }
32e1f5042f65 I don't like such reports: '-vo dga:vidix or -vo x11:vidix works fine for me'
nick
parents: 4706
diff changeset
551 return 0;
4597
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
552 }
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
553
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
554 static uint32_t control(uint32_t request, void *data, ...)
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
555 {
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
556 switch (request) {
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
557 case VOCTRL_QUERY_FORMAT:
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
558 return query_format(*((uint32_t*)data));
8450
8cfc9309f0cc notice vo driver about skipped/dropped frames
arpi
parents: 8148
diff changeset
559 case VOCTRL_DUPLICATE_FRAME:
8cfc9309f0cc notice vo driver about skipped/dropped frames
arpi
parents: 8148
diff changeset
560 return write_last_frame();
4597
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
561 }
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
562 return VO_NOTIMPL;
4ba62f7d04c6 yuv4mpeg output, by Robert Kesterson <robertk@robertk.com>
arpi
parents:
diff changeset
563 }