Opened 5 years ago

Closed 4 years ago

Last modified 4 years ago

#2370 closed defect (fixed)

v4l2 should not need ENUMSTD

Reported by: ubitux Owned by: holden
Priority: normal Component: avdevice
Version: git-master Keywords: v4l2 regression
Cc: Blocked By:
Blocking: Reproduced by developer: yes
Analyzed by developer: yes

Description

Problem: lavd/v4l2.c now requires the device to support VIDIOC_ENUMSTD.

This seems to be a regression according to https://github.com/umlaeute/v4l2loopback/issues/38

Steps to reproduce:

  • install v4l2loopback and load the module
    git clone git://github.com/umlaeute/v4l2loopback.git
    cd v4l2loopback
    make && sudo make install
    modprobe v4l2loopback
    
  • push some video to the device with for instance:
    gst-launch-0.10 videotestsrc ! v4l2sink device=/dev/video0 
    
  • try to play the device with FFmpeg
    % ./ffplay -v verbose -f v4l2 /dev/video0
    ffplay version N-51026-g3313b9c Copyright (c) 2003-2013 the FFmpeg developers
      built on Mar 17 2013 04:38:52 with gcc 4.7.2 (GCC)
      configuration: --enable-gpl --enable-version3 --enable-fontconfig --enable-libfreetype --enable-libmp3lame --enable-libvorbis --enable-libxvid --enable-libx264 --enable-libvpx --enable-libtheora --enable-x11grab --enable-libopenjpeg --enable-libass --enable-libmodplug --enable-libv4l2 --cc=colorgcc --samples=/home/ubitux/fate-samples --prefix=/tmp/ffinstall --disable-runtime-cpudetect --enable-libcelt --enable-libopencv --enable-frei0r --enable-libcaca --enable-libiec61883 --enable-libopencore-amrwb --enable-libopencore-amrnb --enable-libopus --enable-libpulse --enable-libspeex --enable-openal --enable-libopencv
      libavutil      52. 19.101 / 52. 19.101
      libavcodec     55.  0.100 / 55.  0.100
      libavformat    55.  0.100 / 55.  0.100
      libavdevice    55.  0.100 / 55.  0.100
      libavfilter     3. 47.102 /  3. 47.102
      libswscale      2.  2.100 /  2.  2.100
      libswresample   0. 17.102 /  0. 17.102
      libpostproc    52.  2.100 / 52.  2.100
    [video4linux2,v4l2 @ 0x7f457c000940] fd:7 capabilities:50000030/0   
    [video4linux2,v4l2 @ 0x7f457c000940] Querying the device for the current frame size
    [video4linux2,v4l2 @ 0x7f457c000940] Setting frame size to 320x240
    [video4linux2,v4l2 @ 0x7f457c000940] ioctl(VIDIOC_ENUMSTD): Invalid argument
    /dev/video0: Invalid argument
    

The device plays fine with for example mplayer, and with older ffplay (1.1.3 is working).

Attachments (4)

0002-lavd-v4l2-make-sure-VIDIOC_G_STD-does-not-return-std.patch (1009 bytes) - added by holden 4 years ago.
patched.txt (7.9 KB) - added by mrlika 4 years ago.
Output with 0002-lavd-v4l2-make-sure-VIDIOC_G_STD-does-not-return-std.patch
not_patched.txt (6.6 KB) - added by mrlika 4 years ago.
Not patched output
patched_my.txt (9.0 KB) - added by mrlika 4 years ago.
Output with my patch

Download all attachments as: .zip

Change History (21)

comment:1 Changed 5 years ago by cehoyos

Which change in FFmpeg introduced the regression?

comment:2 Changed 5 years ago by ubitux

514216d8a928cf80980ca8dc5daea46e9d41cad9 is the first bad commit.

comment:3 Changed 5 years ago by cehoyos

  • Status changed from new to open

comment:4 Changed 5 years ago by ubitux

Note that while supporting the latest version of v4l2loopback is also important, it seems some workaround recently got pushed in it to handle that issue (see github ticket). To reproduce properly the problem, you need to checkout 5568514931b063eda0aa83976fd9a68cacc53e52 in v4l2loopback repository.

comment:5 Changed 5 years ago by holden

  • Analyzed by developer set
  • Owner set to holden
  • Priority changed from important to normal

The problem has been fixed on v4l2loopback git/master, so now ffmpeg should work again.
I will try to see if we can apply a workaround to allow ffmpeg to work with older versions of v4l2loopback.

comment:6 Changed 4 years ago by ubitux

Any news from this or it should be ignored?

comment:7 follow-up: Changed 4 years ago by mrlika

This regression effects DVP-7620HE device driver. Latest ffmpeg throws the following error:

ffmpeg -f video4linux2 -i /dev/video1 -an -vcodec copy -s cif  test.h264 -loglevel verbose
ffmpeg version git-2013-07-12-0da0caa Copyright (c) 2000-2013 the FFmpeg developers
  built on Jul 12 2013 16:55:30 with gcc 4.7 (Ubuntu/Linaro 4.7.3-1ubuntu1)
  configuration: --enable-libfaac --enable-libmp3lame --enable-nonfree --disable-vaapi --enable-shared --enable-libx264 --enable-version3 --enable-gpl
  libavutil      52. 39.100 / 52. 39.100
  libavcodec     55. 18.102 / 55. 18.102
  libavformat    55. 12.102 / 55. 12.102
  libavdevice    55.  3.100 / 55.  3.100
  libavfilter     3. 80.100 /  3. 80.100
  libswscale      2.  3.100 /  2.  3.100
  libswresample   0. 17.102 /  0. 17.102
  libpostproc    52.  3.100 / 52.  3.100
[video4linux2,v4l2 @ 0x1467900] fd:3 capabilities:4000001
[video4linux2,v4l2 @ 0x1467900] Querying the device for the current frame size
[video4linux2,v4l2 @ 0x1467900] Setting frame size to 1920x1080
[video4linux2,v4l2 @ 0x1467900] ioctl(VIDIOC_ENUMSTD): Invalid argument
/dev/video1: Invalid argument

Older FFmpeg versions work correct with this device:

ffmpeg -f video4linux2 -i /dev/video1 -an -vcodec copy -s cif  test.h264 -loglevel verbose
ffmpeg version 0.8.6-6:0.8.6-1ubuntu2, Copyright (c) 2000-2013 the Libav developers
  built on Mar 30 2013 22:20:06 with gcc 4.7.2
  configuration: --arch=amd64 --enable-pthreads --enable-runtime-cpudetect --extra-version='6:0.8.6-1ubuntu2' --libdir=/usr/lib/x86_64-linux-gnu --prefix=/usr --enable-bzlib --enable-libdc1394 --enable-libfreetype --enable-gnutls --enable-libgsm --enable-libpulse --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-vaapi --enable-vdpau --enable-libvorbis --enable-libvpx --enable-zlib --enable-gpl --enable-postproc --enable-swscale --enable-libcdio --enable-x11grab --shlibdir=/usr/lib/x86_64-linux-gnu --enable-shared --disable-static
  libavutil    51. 22. 1 / 51. 22. 1
  libavcodec   53. 35. 0 / 53. 35. 0
  libavformat  53. 21. 1 / 53. 21. 1
  libavdevice  53.  2. 0 / 53.  2. 0
  libavfilter   2. 15. 0 /  2. 15. 0
  libswscale    2.  1. 0 /  2.  1. 0
  libpostproc  52.  0. 0 / 52.  0. 0
*** THIS PROGRAM IS DEPRECATED ***
This program is only provided for compatibility and will be removed in a future release. Please use avconv instead.                                                                                     
[video4linux2 @ 0x1b6a1e0] [4]Capabilities: 4000001
[video4linux2 @ 0x1b6a1e0] Querying the device for the current frame size
[video4linux2 @ 0x1b6a1e0] Setting frame size to 1920x1080
[video4linux2 @ 0x1b6a1e0] Estimating duration from bitrate, this may be inaccurate
Input #0, video4linux2, from '/dev/video1':
  Duration: N/A, start: 1378115441.148443, bitrate: 829440 kb/s
    Stream #0.0: Video: rawvideo, yuyv422, 1920x1080, 829440 kb/s, 25 tbr, 1000k tbn, 25 tbc
File 'test.h264' already exists. Overwrite ? [y/N] y
Output #0, h264, to 'test.h264':
  Metadata:
    encoder         : Lavf53.21.1
    Stream #0.0: Video: rawvideo, yuyv422, 1920x1080, q=2-31, 829440 kb/s, 90k tbn, 25 tbc
Stream mapping:
  Stream #0.0 -> #0.0
Press ctrl-c to stop encoding

comment:8 in reply to: ↑ 7 Changed 4 years ago by cehoyos

Replying to mrlika:

Older FFmpeg versions work correct with this device:

ffmpeg -f video4linux2 -i /dev/video1 -an -vcodec copy -s cif  test.h264 -loglevel verbose
ffmpeg version 0.8.6-6:0.8.6-1ubuntu2

This unfortunately is not FFmpeg, testing makes no sense (this intentionally broken version has several hundred known regressions, some of them security relevant).
Please test 402ea62

comment:9 follow-up: Changed 4 years ago by mrlika

Patch that fixes the issue:

diff --git a/libavdevice/v4l2.c b/libavdevice/v4l2.c
index c7cd519..7ada54f 100644
--- a/libavdevice/v4l2.c
+++ b/libavdevice/v4l2.c
@@ -687,6 +687,10 @@ static int v4l2_set_parameters(AVFormatContext *s1)
             standard.index = i;
             if (v4l2_ioctl(s->fd, VIDIOC_ENUMSTD, &standard) < 0) {
                 ret = AVERROR(errno);
+                if (ret == AVERROR(EINVAL)) {
+                    tpf = &streamparm.parm.capture.timeperframe;
+                    break;
+                }
                 av_log(s1, AV_LOG_ERROR, "ioctl(VIDIOC_ENUMSTD): %s\n", av_err2str(ret));
                 return ret;
             }

The patch sent to ffmpeg-devel for review: http://ffmpeg.org/pipermail/ffmpeg-devel/2013-September/147793.html

comment:10 in reply to: ↑ 9 Changed 4 years ago by holden

Replying to mrlika:

Patch that fixes the issue:

Hi,

thanks for the patch. Could you please apply the attached patch to the latest ffmpeg git and provide the output of the following commands (change you video device if you need to):

ffmpeg -loglevel debug -f video4linux2 -list_formats all -i /dev/video0
ffmpeg -loglevel debug -f video4linux2 -list_standards all -i /dev/video0
ffmpeg -loglevel debug -f video4linux2 -i /dev/video0 out.avi

Thanks.

Changed 4 years ago by mrlika

Output with 0002-lavd-v4l2-make-sure-VIDIOC_G_STD-does-not-return-std.patch

Changed 4 years ago by mrlika

Not patched output

Changed 4 years ago by mrlika

Output with my patch

comment:11 follow-up: Changed 4 years ago by mrlika

Hi Holden,

patched.txt - output of the commands from latest FFmpeg with your patch
not_patched.txt - output of the commands from not patched latest FFmpeg
patched_my.txt - output from FFmpeg with my patch

Only with my patch third command starts encoding.

Regards.

comment:12 in reply to: ↑ 11 Changed 4 years ago by holden

Replying to mrlika:

Hi Holden,

patched.txt - output of the commands from latest FFmpeg with your patch
not_patched.txt - output of the commands from not patched latest FFmpeg
patched_my.txt - output from FFmpeg with my patch

Only with my patch third command starts encoding.

Regards.

Thanks for the tests, I changed the commit message on your original patch and sent it to the mailing list. Once it gets applied I think we can close this ticket.

comment:13 Changed 4 years ago by mrlika

Thank you

comment:14 Changed 4 years ago by cehoyos

  • Resolution set to fixed
  • Status changed from open to closed

Fixed by mrlika in ed72542

comment:15 follow-up: Changed 4 years ago by cehoyos

Should the patch be backported to release/2.0 ?

comment:16 in reply to: ↑ 15 Changed 4 years ago by holden

Replying to cehoyos:

Should the patch be backported to release/2.0 ?

Sorry for the late replay, but if we're still in time I'd say sure, it can be backported.

comment:17 Changed 4 years ago by cehoyos

Merged into release/2.0 and release/1.2.

Note: See TracTickets for help on using tickets.