Basically the problem is that FFmpeg won't capture 1920x1080 on my Linux system, whereas other video capture applications will, and yet FFmpeg will successfully capture other resolutions from the same device on the same system. Weird. I've tried many combinations of FFmpeg command lines and muttered many incantations but none of them fix the problem.
I am using FFmpeg on Ubuntu 19.04 desktop on a Ryzen 2200G with 16GB RAM.
My goal is to create an H264 mp4 video that can be displayed in a web browser, with data sourced from a USB UVC device. The resulting file should play OK in the quicktime player on Windows and in a web browser.
Here are some facts about my setup and known usage:
- I have an HDMI UVC to USB device which is capable of 4K video input.
- FFmpeg works fine when I capture video using FFmpeg in any resolution EXCEPT 1920x1080
- FFmpeg also works fine capturing 4k input as well as all the lower resolutions
- gstreamer seems to be able to capture data - it created a gigantic file (see APPENDIX 1 output below)
- Ubuntu's desktop guvcview program has no trouble at all displaying video from the uvc device and needs no special configuration to do so.
- I used Ubuntu's desktop guvcview program in command line mode to capture video from the uvc device in 1920x1080 and it handled it fine.
Appendix 1: the uvc devices
ubuntu@render001:~$ ls /dev/vid*
/dev/video0 /dev/video1
Appendix 2: uvc device info
ubuntu@render001:~$ v4l2-ctl --all
Driver Info:
Driver name : uvcvideo
Card type : Cam Link 4K: Cam Link 4K
Bus info : usb-0000:08:00.3-4
Driver version : 5.0.8
Capabilities : 0x84a00001
Video Capture
Metadata Capture
Streaming
Extended Pix Format
Device Capabilities
Device Caps : 0x04200001
Video Capture
Streaming
Extended Pix Format
Priority: 2
Video input : 0 (Input 1: ok)
Format Video Capture:
Width/Height : 1920/1080
Pixel Format : 'YUYV' (YUYV 4:2:2)
Field : None
Bytes per Line : 3840
Size Image : 4147200
Colorspace : sRGB
Transfer Function : Default (maps to sRGB)
YCbCr/HSV Encoding: Default (maps to ITU-R 601)
Quantization : Default (maps to Limited Range)
Flags :
Crop Capability Video Capture:
Bounds : Left 0, Top 0, Width 1920, Height 1080
Default : Left 0, Top 0, Width 1920, Height 1080
Pixel Aspect: 1/1
Selection: crop_default, Left 0, Top 0, Width 1920, Height 1080, Flags:
Selection: crop_bounds, Left 0, Top 0, Width 1920, Height 1080, Flags:
Streaming Parameters Video Capture:
Capabilities : timeperframe
Frames per second: 60.000 (60/1)
Read buffers : 0
brightness 0x00980900 (int) : min=0 max=255 step=1 default=128 value=128
contrast 0x00980901 (int) : min=0 max=255 step=1 default=128 value=128
saturation 0x00980902 (int) : min=0 max=255 step=1 default=128 value=128
hue 0x00980903 (int) : min=0 max=255 step=1 default=128 value=128
Appendix 3: the failed FFmpeg case output
ubuntu@render001:~$ ffmpeg -y -t 5 -f video4linux2 -i /dev/video0 out.mov
ffmpeg version N-94046-gc9c1711 Copyright (c) 2000-2019 the FFmpeg developers
built with gcc 8 (Ubuntu 8.3.0-6ubuntu1)
configuration: --prefix=/home/ubuntu/ffmpeg_build --pkg-config-flags=--static --extra-cflags=-I/home/ubuntu/ffmpeg_build/include --extra-ldflags=-L/home/ubuntu/ffmpeg_build/lib --extra-libs='-lpthread -lm' --bindir=/home/ubuntu/bin --enable-gpl --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-nonfree
libavutil 56. 28.100 / 56. 28.100
libavcodec 58. 53.100 / 58. 53.100
libavformat 58. 27.103 / 58. 27.103
libavdevice 58. 7.100 / 58. 7.100
libavfilter 7. 55.100 / 7. 55.100
libswscale 5. 4.101 / 5. 4.101
libswresample 3. 4.100 / 3. 4.100
libpostproc 55. 4.100 / 55. 4.100
IMPORTANT NOTE: FFmpeg hangs at this point, and the following is displayed after pressing Control+C:
Input #0, video4linux2,v4l2, from '/dev/video0':
Duration: N/A, bitrate: 1492992 kb/s
Stream #0:0: Video: rawvideo (I420 / 0x30323449), yuv420p, 1920x1080, 1492992 kb/s, 60 fps, 60 tbr, 1000k tbn, 1000k tbc
Stream mapping:
Stream #0:0 -> #0:0 (rawvideo (native) -> h264 (libx264))
Press [q] to stop, [?] for help
Finishing stream 0:0 without any data written to it.
[libx264 @ 0x55efe29a1c00] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 0x55efe29a1c00] profile High, level 4.2
[libx264 @ 0x55efe29a1c00] 264 - core 155 r2917 0a84d98 - H.264/MPEG-4 AVC codec - Copyleft 2003-2018 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=6 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mov, to 'out.mov':
Metadata:
encoder : Lavf58.27.103
Stream #0:0: Video: h264 (libx264) (avc1 / 0x31637661), yuv420p, 1920x1080, q=-1--1, 60 fps, 15360 tbn, 60 tbc
Metadata:
encoder : Lavc58.53.100 libx264
Side data:
cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
frame= 0 fps=0.0 q=0.0 Lsize= 0kB time=00:00:00.00 bitrate=N/A speed= 0x
video:0kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
Exiting normally, received signal 2.
Appendix 4: the successful FFmpeg case output - note here that the ONLY difference was that the resolution of the input to the UVC device was changed to 3840x2160. The output .mov file plays fine in Quicktime player or in a browser.
ffmpeg -y -t 5 -f video4linux2 -i /dev/video0 out.mov
ffmpeg version N-94046-gc9c1711 Copyright (c) 2000-2019 the FFmpeg developers
built with gcc 8 (Ubuntu 8.3.0-6ubuntu1)
configuration: --prefix=/home/ubuntu/ffmpeg_build --pkg-config-flags=--static --extra-cflags=-I/home/ubuntu/ffmpeg_build/include --extra-ldflags=-L/home/ubuntu/ffmpeg_build/lib --extra-libs='-lpthread -lm' --bindir=/home/ubuntu/bin --enable-gpl --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-nonfree
libavutil 56. 28.100 / 56. 28.100
libavcodec 58. 53.100 / 58. 53.100
libavformat 58. 27.103 / 58. 27.103
libavdevice 58. 7.100 / 58. 7.100
libavfilter 7. 55.100 / 7. 55.100
libswscale 5. 4.101 / 5. 4.101
libswresample 3. 4.100 / 3. 4.100
libpostproc 55. 4.100 / 55. 4.100
Input #0, video4linux2,v4l2, from '/dev/video0':
Duration: N/A, start: 625.791663, bitrate: 2985984 kb/s
Stream #0:0: Video: rawvideo (I420 / 0x30323449), yuv420p, 3840x2160, 2985984 kb/s, 30 fps, 30 tbr, 1000k tbn, 1000k tbc
Stream mapping:
Stream #0:0 -> #0:0 (rawvideo (native) -> h264 (libx264))
Press [q] to stop, [?] for help
[libx264 @ 0x5586ca510300] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 0x5586ca510300] profile High, level 5.1
[libx264 @ 0x5586ca510300] 264 - core 155 r2917 0a84d98 - H.264/MPEG-4 AVC codec - Copyleft 2003-2018 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=6 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mov, to 'out.mov':
Metadata:
encoder : Lavf58.27.103
Stream #0:0: Video: h264 (libx264) (avc1 / 0x31637661), yuv420p, 3840x2160, q=-1--1, 30 fps, 15360 tbn, 30 tbc
Metadata:
encoder : Lavc58.53.100 libx264
Side data:
cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
frame= 151 fps= 18 q=-1.0 Lsize= 476kB time=00:00:04.93 bitrate= 791.1kbits/s dup=11 drop=0 speed=0.588x
video:474kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.538915%
[libx264 @ 0x5586ca510300] frame I:1 Avg QP:19.12 size:115507
[libx264 @ 0x5586ca510300] frame P:38 Avg QP:18.89 size: 6063
[libx264 @ 0x5586ca510300] frame B:112 Avg QP:21.48 size: 1238
[libx264 @ 0x5586ca510300] consecutive B-frames: 0.7% 1.3% 0.0% 98.0%
[libx264 @ 0x5586ca510300] mb I I16..4: 23.5% 70.7% 5.8%
[libx264 @ 0x5586ca510300] mb P I16..4: 0.1% 0.1% 0.0% P16..4: 9.8% 0.0% 0.3% 0.0% 0.0% skip:89.6%
[libx264 @ 0x5586ca510300] mb B I16..4: 0.0% 0.0% 0.0% B16..8: 2.6% 0.0% 0.0% direct: 0.0% skip:97.4% L0:34.6% L1:65.4% BI: 0.0%
[libx264 @ 0x5586ca510300] 8x8 transform intra:69.0% inter:99.8%
[libx264 @ 0x5586ca510300] coded y,uvDC,uvAC intra: 21.6% 55.2% 9.8% inter: 0.4% 3.0% 0.0%
[libx264 @ 0x5586ca510300] i16 v,h,dc,p: 56% 32% 7% 5%
[libx264 @ 0x5586ca510300] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 39% 10% 42% 2% 2% 1% 2% 1% 1%
[libx264 @ 0x5586ca510300] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 41% 12% 21% 7% 5% 4% 5% 5% 1%
[libx264 @ 0x5586ca510300] i8c dc,h,v,p: 60% 25% 14% 2%
[libx264 @ 0x5586ca510300] Weighted P-Frames: Y:0.0% UV:0.0%
[libx264 @ 0x5586ca510300] ref P L0: 81.0% 0.3% 15.1% 3.6%
[libx264 @ 0x5586ca510300] ref B L0: 68.4% 31.5% 0.2%
[libx264 @ 0x5586ca510300] ref B L1: 99.5% 0.5%
[libx264 @ 0x5586ca510300] kb/s:770.14
ubuntu@render001:~$
Appendix 7: The successful gstreamer case output
ubuntu@render001:~$ gst-launch-1.0 -v v4l2src device=/dev/video0 ! video/x-raw,framerate=60/1,width=1920,height=1080 ! filesink location=gopro2.mp4
Setting pipeline to PAUSED ...
Pipeline is live and does not need PREROLL ...
Setting pipeline to PLAYING ...
New clock: GstSystemClock
/GstPipeline:pipeline0/GstV4l2Src:v4l2src0.GstPad:src: caps = video/x-raw, framerate=(fraction)60/1, width=(int)1920, height=(int)1080, format=(string)YUY2, pixel-aspect-ratio=(fraction)1/1, colorimetry=(string)bt709, interlace-mode=(string)progressive
/GstPipeline:pipeline0/GstCapsFilter:capsfilter0.GstPad:src: caps = video/x-raw, framerate=(fraction)60/1, width=(int)1920, height=(int)1080, format=(string)YUY2, pixel-aspect-ratio=(fraction)1/1, colorimetry=(string)bt709, interlace-mode=(string)progressive
/GstPipeline:pipeline0/GstFileSink:filesink0.GstPad:sink: caps = video/x-raw, framerate=(fraction)60/1, width=(int)1920, height=(int)1080, format=(string)YUY2, pixel-aspect-ratio=(fraction)1/1, colorimetry=(string)bt709, interlace-mode=(string)progressive
/GstPipeline:pipeline0/GstCapsFilter:capsfilter0.GstPad:sink: caps = video/x-raw, framerate=(fraction)60/1, width=(int)1920, height=(int)1080, format=(string)YUY2, pixel-aspect-ratio=(fraction)1/1, colorimetry=(string)bt709, interlace-mode=(string)progressive
^Chandling interrupt.
Interrupt: Stopping pipeline ...
Execution ended after 0:00:02.464259973
Setting pipeline to PAUSED ...
Setting pipeline to READY ...
Setting pipeline to NULL ...
Freeing pipeline ...
ubuntu@render001:~$ ls -lah gopro2.mp4
-rw-rw-r-- 1 ubuntu ubuntu 550M Jun 16 12:33 gopro2.mp4
ubuntu@render001:~$
Appendix 8: The successful guvcview case output
ubuntu@render001:~$ guvcview --device=/dev/video0 --video=./guvcoutput.mkv --video_timer=5 --exit_on_term --verbosity=10
GUVCVIEW: version 2.0.6
GUVCVIEW: language catalog=> dir:/usr/share/locale type:en_AU.UTF-8
Full appendix 7 output log continues here.
And here is some possibly useful FFmpeg info as well.
EDIT REPLY TO COMMENT:
ubuntu@render001:~$ ffmpeg -f v4l2 -list_formats all -i /dev/video0
ffmpeg version N-94046-gc9c1711 Copyright (c) 2000-2019 the FFmpeg developers
built with gcc 8 (Ubuntu 8.3.0-6ubuntu1)
configuration: --prefix=/home/ubuntu/ffmpeg_build --pkg-config-flags=--static --extra-cflags=-I/home/ubuntu/ffmpeg_build/include --extra-ldflags=-L/home/ubuntu/ffmpeg_build/lib --extra-libs='-lpthread -lm' --bindir=/home/ubuntu/bin --enable-gpl --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-nonfree
libavutil 56. 28.100 / 56. 28.100
libavcodec 58. 53.100 / 58. 53.100
libavformat 58. 27.103 / 58. 27.103
libavdevice 58. 7.100 / 58. 7.100
libavfilter 7. 55.100 / 7. 55.100
libswscale 5. 4.101 / 5. 4.101
libswresample 3. 4.100 / 3. 4.100
libpostproc 55. 4.100 / 55. 4.100
[video4linux2,v4l2 @ 0x55fddc42a940] Raw : yuyv422 : YUYV 4:2:2 : 1920x1080
[video4linux2,v4l2 @ 0x55fddc42a940] Raw : nv12 : Y/CbCr 4:2:0 : 1920x1080
[video4linux2,v4l2 @ 0x55fddc42a940] Raw : yuv420p : Planar YUV 4:2:0 : 1920x1080
/dev/video0: Immediate exit requested
ffmpeg -f v4l2 -list_formats all -i /dev/video0