The colorspace field can now be specified for output formats.
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
" --list-fields list supported fields for the current format\n"
" -V, --get-fmt-video\n"
" query the video capture format [VIDIOC_G_FMT]\n"
- " -v, --set-fmt-video=width=<w>,height=<h>,pixelformat=<pf>,field=<f>\n"
- " set the video capture format [VIDIOC_S_FMT]\n"
- " pixelformat is either the format index as reported by\n"
- " --list-formats, or the fourcc value as a string.\n"
- " <f> can be one of:\n"
- " any, none, top, bottom, interlaced, seq_tb, seq_bt,\n"
- " alternate, interlaced_tb, interlaced_bt\n"
+ " -v, --set-fmt-video\n"
" --try-fmt-video=width=<w>,height=<h>,pixelformat=<pf>,field=<f>\n"
- " try the video capture format [VIDIOC_TRY_FMT]\n"
+ " set/try the video capture format [VIDIOC_S/TRY_FMT]\n"
" pixelformat is either the format index as reported by\n"
" --list-formats, or the fourcc value as a string.\n"
" <f> can be one of:\n"
void vidcap_cmd(int ch, char *optarg)
{
- __u32 width, height, field, pixfmt;
+ __u32 width, height, pixfmt, field, colorspace;
char *value, *subs;
switch (ch) {
case OptSetVideoFormat:
case OptTryVideoFormat:
- set_fmts = parse_fmt(optarg, width, height, field, pixfmt);
- if (!set_fmts) {
+ set_fmts = parse_fmt(optarg, width, height, pixfmt, field, colorspace);
+ if (!set_fmts || (set_fmts & FmtColorspace)) {
vidcap_usage();
exit(1);
}
if (is_multiplanar) {
vfmt_cap.fmt.pix_mp.width = width;
vfmt_cap.fmt.pix_mp.height = height;
- vfmt_cap.fmt.pix_mp.field = field;
vfmt_cap.fmt.pix_mp.pixelformat = pixfmt;
+ vfmt_cap.fmt.pix_mp.field = field;
+ vfmt_cap.fmt.pix_mp.colorspace = colorspace;
} else {
vfmt_cap.fmt.pix.width = width;
vfmt_cap.fmt.pix.height = height;
- vfmt_cap.fmt.pix.field = field;
vfmt_cap.fmt.pix.pixelformat = pixfmt;
+ vfmt_cap.fmt.pix.field = field;
+ vfmt_cap.fmt.pix.colorspace = colorspace;
}
break;
case OptListFrameSizes:
false, true);
}
}
+ if (set_fmts & FmtField)
+ vfmt.fmt.pix_mp.field = vfmt_cap.fmt.pix_mp.field;
/* G_FMT might return bytesperline values > width,
* reset them to 0 to force the driver to update them
* to the closest value for the new width. */
false, false);
}
}
+ if (set_fmts & FmtField)
+ vfmt.fmt.pix.field = vfmt_cap.fmt.pix.field;
/* G_FMT might return a bytesperline value > width,
* reset this to 0 to force the driver to update it
* to the closest value for the new width. */
" --get-fmt-video-out\n"
" query the video output format [VIDIOC_G_FMT]\n"
" --set-fmt-video-out\n"
- " --try-fmt-video-out=width=<w>,height=<h>,pixelformat=<pf>,field=<f>\n"
- " set/try the video output format [VIDIOC_TRY_FMT]\n"
+ " --try-fmt-video-out=width=<w>,height=<h>,pixelformat=<pf>,field=<f>,colorspace=<c>\n"
+ " set/try the video output format [VIDIOC_S/TRY_FMT]\n"
" pixelformat is either the format index as reported by\n"
" --list-formats-out, or the fourcc value as a string.\n"
" <f> can be one of:\n"
" any, none, top, bottom, interlaced, seq_tb, seq_bt,\n"
" alternate, interlaced_tb, interlaced_bt\n"
+ " <c> can be one of:\n"
+ " smpte170m, smpte240m, rec709, bt878, 470m, 470bg, jpeg, srgb\n"
);
}
void vidout_cmd(int ch, char *optarg)
{
- __u32 width, height, field, pixfmt;
+ __u32 width, height, pixfmt, field, colorspace;
switch (ch) {
case OptSetVideoOutFormat:
case OptTryVideoOutFormat:
- set_fmts_out = parse_fmt(optarg, width, height, field, pixfmt);
+ set_fmts_out = parse_fmt(optarg, width, height, pixfmt, field, colorspace);
if (!set_fmts_out) {
vidcap_usage();
exit(1);
if (is_multiplanar) {
vfmt_out.fmt.pix_mp.width = width;
vfmt_out.fmt.pix_mp.height = height;
- vfmt_out.fmt.pix_mp.field = field;
vfmt_out.fmt.pix_mp.pixelformat = pixfmt;
+ vfmt_out.fmt.pix_mp.field = field;
+ vfmt_out.fmt.pix_mp.colorspace = colorspace;
} else {
vfmt_out.fmt.pix.width = width;
vfmt_out.fmt.pix.height = height;
- vfmt_out.fmt.pix.field = field;
vfmt_out.fmt.pix.pixelformat = pixfmt;
+ vfmt_out.fmt.pix.field = field;
+ vfmt_out.fmt.pix.colorspace = colorspace;
}
break;
}
true, true);
}
}
+ if (set_fmts_out & FmtField)
+ vfmt.fmt.pix_mp.field = vfmt_out.fmt.pix_mp.field;
+ if (set_fmts_out & FmtColorspace)
+ vfmt.fmt.pix_mp.colorspace = vfmt_out.fmt.pix_mp.colorspace;
/* G_FMT might return bytesperline values > width,
* reset them to 0 to force the driver to update them
* to the closest value for the new width. */
true, false);
}
}
+ if (set_fmts_out & FmtField)
+ vfmt.fmt.pix.field = vfmt_out.fmt.pix.field;
+ if (set_fmts_out & FmtColorspace)
+ vfmt.fmt.pix.colorspace = vfmt_out.fmt.pix.colorspace;
/* G_FMT might return a bytesperline value > width,
* reset this to 0 to force the driver to update it
* to the closest value for the new width. */
return V4L2_FIELD_ANY;
}
-int parse_fmt(char *optarg, __u32 &width, __u32 &height, __u32 &field, __u32 &pixelformat)
+static __u32 parse_colorspace(const char *s)
+{
+ if (!strcmp(s, "smpte170m")) return V4L2_COLORSPACE_SMPTE170M;
+ if (!strcmp(s, "smpte240m")) return V4L2_COLORSPACE_SMPTE240M;
+ if (!strcmp(s, "rec709")) return V4L2_COLORSPACE_REC709;
+ if (!strcmp(s, "bt878")) return V4L2_COLORSPACE_BT878;
+ if (!strcmp(s, "470m")) return V4L2_COLORSPACE_470_SYSTEM_M;
+ if (!strcmp(s, "470bg")) return V4L2_COLORSPACE_470_SYSTEM_BG;
+ if (!strcmp(s, "jpeg")) return V4L2_COLORSPACE_JPEG;
+ if (!strcmp(s, "srgb")) return V4L2_COLORSPACE_SRGB;
+ return 0;
+}
+
+int parse_fmt(char *optarg, __u32 &width, __u32 &height, __u32 &pixelformat,
+ __u32 &field, __u32 &colorspace)
{
char *value, *subs;
int fmts = 0;
static const char *const subopts[] = {
"width",
"height",
- "field",
"pixelformat",
+ "field",
+ "colorspace",
NULL
};
fmts |= FmtHeight;
break;
case 2:
- field = parse_field(value);
- fmts |= FmtField;
- break;
- case 3:
if (strlen(value) == 4)
pixelformat =
v4l2_fourcc(value[0], value[1],
pixelformat = strtol(value, 0L, 0);
fmts |= FmtPixelFormat;
break;
+ case 3:
+ field = parse_field(value);
+ fmts |= FmtField;
+ break;
+ case 4:
+ colorspace = parse_colorspace(value);
+ if (colorspace)
+ fmts |= FmtColorspace;
+ else
+ fprintf(stderr, "unknown colorspace %s\n", value);
+ break;
default:
return 0;
}
#define FmtLeft (1L<<5)
#define FmtTop (1L<<6)
#define FmtField (1L<<7)
+#define FmtColorspace (1L<<8)
// v4l2-ctl.cpp
int doioctl_name(int fd, unsigned long int request, void *parm, const char *name);
std::string field2s(int val);
void print_v4lstd(v4l2_std_id std);
__u32 parse_field(const char *s);
-int parse_fmt(char *optarg, __u32 &width, __u32 &height, __u32 &field, __u32 &pixelformat);
+int parse_fmt(char *optarg, __u32 &width, __u32 &height, __u32 &pixelformat,
+ __u32 &field, __u32 &colorspace);
__u32 find_pixel_format(int fd, unsigned index, bool output, bool mplane);
void printfmt(const struct v4l2_format &vfmt);
void print_video_formats(int fd, __u32 type);