[FFmpeg-devel] [PATCH] lavd/v4l2: add list_standards option

Stefano Sabatini stefasab at gmail.com
Wed Jan 30 01:05:17 CET 2013


On date Tuesday 2013-01-29 13:16:33 +0100, Giorgio Vazzana encoded:
> Hi,
> 
> this patch adds the 'list_standards' option, which prints a table like this:
> 
> $ ./ffplay -f video4linux2 -channel 0 -list_standards all /dev/video0
> ffplay version N-49406-gac5b948 Copyright (c) 2003-2013 the FFmpeg developers
>   built on Jan 29 2013 12:52:03 with gcc 4.4.3 (Ubuntu 4.4.3-4ubuntu5.1)
>   configuration: --enable-gpl --enable-x11grab --enable-libxvid
> --enable-libmp3lame --enable-libtheora --enable-libvorbis
> --enable-libopus --enable-libvpx --enable-libx264
>   libavutil      52. 17.100 / 52. 17.100
>   libavcodec     54. 91.100 / 54. 91.100
>   libavformat    54. 61.104 / 54. 61.104
>   libavdevice    54.  3.102 / 54.  3.102
>   libavfilter     3. 34.101 /  3. 34.101
>   libswscale      2.  2.100 /  2.  2.100
>   libswresample   0. 17.102 /  0. 17.102
>   libpostproc    52.  2.100 / 52.  2.100
> [video4linux2,v4l2 @ 0x2055ea0] Std:  0, 0x000000000000b000, NTSC
> [video4linux2,v4l2 @ 0x2055ea0] Std:  1, 0x0000000000001000, NTSC-M
> [video4linux2,v4l2 @ 0x2055ea0] Std:  2, 0x0000000000002000, NTSC-M-JP
> [video4linux2,v4l2 @ 0x2055ea0] Std:  3, 0x0000000000008000, NTSC-M-KR
> [video4linux2,v4l2 @ 0x2055ea0] Std:  4, 0x00000000000000ff, PAL
> [video4linux2,v4l2 @ 0x2055ea0] Std:  5, 0x0000000000000007, PAL-BG
> [video4linux2,v4l2 @ 0x2055ea0] Std:  6, 0x0000000000000008, PAL-H
> [video4linux2,v4l2 @ 0x2055ea0] Std:  7, 0x0000000000000010, PAL-I
> [video4linux2,v4l2 @ 0x2055ea0] Std:  8, 0x00000000000000e0, PAL-DK
> [video4linux2,v4l2 @ 0x2055ea0] Std:  9, 0x0000000000000100, PAL-M
> [video4linux2,v4l2 @ 0x2055ea0] Std: 10, 0x0000000000000200, PAL-N
> [video4linux2,v4l2 @ 0x2055ea0] Std: 11, 0x0000000000000400, PAL-Nc
> [video4linux2,v4l2 @ 0x2055ea0] Std: 12, 0x0000000000000800, PAL-60
> [video4linux2,v4l2 @ 0x2055ea0] Std: 13, 0x0000000000ff0000, SECAM
> [video4linux2,v4l2 @ 0x2055ea0] Std: 14, 0x0000000000010000, SECAM-B
> [video4linux2,v4l2 @ 0x2055ea0] Std: 15, 0x0000000000040000, SECAM-G
> [video4linux2,v4l2 @ 0x2055ea0] Std: 16, 0x0000000000080000, SECAM-H
> [video4linux2,v4l2 @ 0x2055ea0] Std: 17, 0x0000000000320000, SECAM-DK
> [video4linux2,v4l2 @ 0x2055ea0] Std: 18, 0x0000000000400000, SECAM-L
> [video4linux2,v4l2 @ 0x2055ea0] Std: 19, 0x0000000000800000, SECAM-Lc
> /dev/video0: Immediate exit requested
> 
> Useful / not useful?

Possibly useful.

BTW this would be also useful at the programmatic level, if you can
get your head around the recently added av_opt_query_* API.

> 
> Regards,
> Giorgio Vazzana

> From be3fa89c581a959b0b01321b1b737add2bc028ac Mon Sep 17 00:00:00 2001
> From: Giorgio Vazzana <mywing81 at gmail.com>
> Date: Tue, 29 Jan 2013 13:11:01 +0100
> Subject: [PATCH] lavd/v4l2: add list_standards option
> 
> Since the user is expected to choose the standard by name (with -standard option),
> add the possibility to list all the supported standards.
> ---
>  libavdevice/v4l2.c |   35 +++++++++++++++++++++++++++++++++++
>  1 files changed, 35 insertions(+), 0 deletions(-)

Missing documentation update.

> 
> diff --git a/libavdevice/v4l2.c b/libavdevice/v4l2.c
> index 879201f..95bb477 100644
> --- a/libavdevice/v4l2.c
> +++ b/libavdevice/v4l2.c
> @@ -116,6 +116,7 @@ struct video_data {
>      int channel;
>      char *pixel_format; /**< Set by a private option. */
>      int list_format;    /**< Set by a private option. */
> +    int list_standard;  /**< Set by a private option. */
>      char *framerate;    /**< Set by a private option. */
>  };
>  
> @@ -381,6 +382,32 @@ static void list_formats(AVFormatContext *ctx, int fd, int type)
>      }
>  }
>  
> +static void list_standards(AVFormatContext *ctx)
> +{
> +    int ret;
> +    struct video_data *s = ctx->priv_data;
> +    struct v4l2_standard standard;
> +

> +    if (s->std_id == 0) {
> +        av_log(ctx, AV_LOG_WARNING, "This device does not support any standard\n");
> +        return;
> +    }

Possibly more script-friendly, don't output nothing in case of no
supported standards.

> +
> +    for (standard.index = 0; ; standard.index++) {
> +        ret = v4l2_ioctl(s->fd, VIDIOC_ENUMSTD, &standard);
> +        if (ret < 0) {
> +            if (errno == EINVAL)
> +                break;
> +            else {
> +                av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_ENUMSTD): %s\n", strerror(errno));
> +                return;
> +            }
> +        }

> +        av_log(ctx, AV_LOG_INFO, "Std: %2d, 0x%016llx, %s\n",
> +               standard.index, standard.id, standard.name);

"Std:" may be replaced by "Standard" or dropped altogether since the
user knows what she asked for, maybe you could remove the many leading
"0" in the ID.

I have no special objections to the current form but some more thought
about the most preferrable format can't hurt. OTOH the output is meant
for the human reader thus we can change it later without infliciting
too much pain to users.

BTW what's the type of "standard.id"?

LGTM otherwise.
-- 
FFmpeg = Forgiving and Foolish Merciless Peaceless Extreme God


More information about the ffmpeg-devel mailing list