Video standards
當然世界上現在有多個視頻標準,如NTSC和PAL,他們又細分爲好多種,那麼我們的設備輸入/輸出究竟支持什麼樣的標準呢?我們的當前在使用的輸入和輸出正在使用的是哪個標準呢?我們怎麼設置我們的某個輸入輸出使用的標準呢?這都是有方法的。
(1)查詢,我們的輸入支持什麼標準,首先就得找到當前的這個輸入的index,然後查出它的屬性,在其屬性裏面可以得到該輸入所支持的標準,
將它所支持的各個標準與所有的標準的信息進行比較,就可以獲知所支持的各個標準的屬性。一個輸入所支持的標準應該是一個集合,而這個集合是用bit與的方
式使用一個64位數字表示的。因此我們所查到的是一個數字。
- Example 1-5. Information about the current video standard
- v4l2_std_id std_id;
- struct v4l2_standard standard;
- if (-1 == ioctl (fd, VIDIOC_G_STD, &std_id)) {
-
- perror ("VIDIOC_G_STD");
- exit (EXIT_FAILURE);
- }
- memset (&standard, 0, sizeof (standard));
- standard.index = 0;
- while (0 == ioctl (fd, VIDIOC_ENUMSTD, &standard)) {
- if (standard.id & std_id) {
- printf ("Current video standard: %s/n", standard.name);
- exit (EXIT_SUCCESS);
- }
- standard.index++;
- }
- if (errno == EINVAL || standard.index == 0) {
- perror ("VIDIOC_ENUMSTD");
- exit (EXIT_FAILURE);
- }
-
- Example 1-6. Listing the video standards supported by the current input
- struct v4l2_input input;
- struct v4l2_standard standard;
- memset (&input, 0, sizeof (input));
- if (-1 == ioctl (fd, VIDIOC_G_INPUT, &input.index)) {
- perror ("VIDIOC_G_INPUT");
- exit (EXIT_FAILURE);
- }
- if (-1 == ioctl (fd, VIDIOC_ENUMINPUT, &input)) {
- perror ("VIDIOC_ENUM_INPUT");
- exit (EXIT_FAILURE);
- }
- printf ("Current input %s supports:/n", input.name);
- memset (&standard, 0, sizeof (standard));
- standard.index = 0;
- while (0 == ioctl (fd, VIDIOC_ENUMSTD, &standard)) {
- if (standard.id & input.std)
- printf ("%s/n", standard.name);
- standard.index++;
- }
- if (errno != EINVAL || standard.index == 0) {
- perror ("VIDIOC_ENUMSTD");
- exit (EXIT_FAILURE);
- }
- Example 1-7. Selecting a new video standard
- struct v4l2_input input;
- v4l2_std_id std_id;
- memset (&input, 0, sizeof (input));
- if (-1 == ioctl (fd, VIDIOC_G_INPUT, &input.index)) {
- perror ("VIDIOC_G_INPUT");
- exit (EXIT_FAILURE);
- }
- if (-1 == ioctl (fd, VIDIOC_ENUMINPUT, &input)) {
- perror ("VIDIOC_ENUM_INPUT");
- exit (EXIT_FAILURE);
- }
- if (0 == (input.std & V4L2_STD_PAL_BG)) {
- fprintf (stderr, "Oops. B/G PAL is not supported./n");
- exit (EXIT_FAILURE);
- }
- std_id = V4L2_STD_PAL_BG;
- if (-1 == ioctl (fd, VIDIOC_S_STD, &std_id)) {
- perror ("VIDIOC_S_STD");
- exit (EXIT_FAILURE);