[FFmpeg-user] USB Camera ffplay real-time and save to file

Hans Carlson forbyta at gmx.com
Fri Sep 11 22:30:06 EEST 2020


On Fri, 11 Sep 2020, Moritz Barsnick wrote:

> ffmpeg has several display output muxers/devices. The most common one 
> (saying it works well, and that on many platforms) is "sdl" a.k.a. 
> "sdl". Have ffmpeg create two outputs:
>
> $ ffmpeg -i INPUT -c whatever OUTPUTFILE -c copy -f sdl :0
>
> (You may need to drop the copy codec if sdl cannot handle your input or
> it isn't raw, and/or at least adjust the pixel format to one which sdl
> handles - but it will report that in an error message, I believe.)

Thanks Moritz, I didn't know about this...  but, I can't seem to get it to 
work.  I believe the codec and/or pixel format (as you suspected) may be 
to blame.

Any suggestions for a codec and/or pixel format that:

   1) is compatible with the camera mjpeg input (yuvj422p ?)

   2) does NOT change the framerate from 30 fps to 10 fps

If I try this:

   $ ffmpeg -f v4l2 -input_format mjpeg -framerate 30 -video_size 1280x720 -i /dev/video2 -map 0:0 -c:v copy -f sdl :0

I get:

   [sdl,sdl2 @ 0x3ef9980] Only supports one rawvideo stream

So I try this:

   $ ffmpeg -f v4l2 -input_format mjpeg -framerate 30 -video_size 1280x720 -i /dev/video2 -map 0:0 -c:v rawvideo -f sdl :0

Then I get this:

   [sdl,sdl2 @ 0x3a5f980] Unsupported pixel format 'yuvj422p'.

So then I try this.
NOTE: I'm just guessing with yuv422p... I really have no idea what pixel 
format to use:

   $ ffmpeg -f v4l2 -input_format mjpeg -framerate 30 -video_size 1280x720 -i /dev/video2 -map 0:0 -c:v rawvideo -pixel_format yuv422p -f sdl :0

But get the same error:

   [sdl,sdl2 @ 0x3a5f980] Unsupported pixel format 'yuvj422p'.

So, I try it as an input option:

   $ ffmpeg -f v4l2 -input_format mjpeg -pixel_format yuv422p -framerate 30 -video_size 1280x720 -i /dev/video2 -map 0:0 -c:v rawvideo -f sdl :0
   (see complete output below)

This doesn't work, but it seems like it tries to work.  I briefly see what 
I assume is a window flash on the monitor, then it disappears and I get 
this error:

   av_interleaved_write_frame(): Operation not permitted

One other problem with this particular command is this notice:

   [video4linux2,v4l2 @ 0x3b9ff80] The driver changed the time per frame from 1/30 to 1/10

Which I definitely do NOT want.

If I go back to ffplay and use "-pixel_format yuv422p" as an input option:

   $ ffplay -f v4l2 -input_format mjpeg -pixel_format yuv422p -framerate 30 -video_size 1280x720 -i /dev/video2

it does work (ie, I see a video window with camera output), BUT I get the 
same notice about the framerate:

   [video4linux2,v4l2 @ 0x7efd78000bc0] The driver changed the time per frame from 1/30 to 1/10


Complete output for command that "tries to work".  Happy to provide 
complete output for any other commands:

   $ ffmpeg -f v4l2 -input_format mjpeg -pixel_format yuv422p -framerate 30 -video_size 1280x720 -i /dev/video2 -map 0:0 -c:v rawvideo -f sdl :0
ffmpeg version N-99076-gb0203fa72b Copyright (c) 2000-2020 the FFmpeg developers
   built with gcc 9 (GCC)
   configuration: --enable-gpl --enable-version3 --enable-nonfree --enable-static --disable-shared --disable-debug --enable-libass --enable-libfdk-aac --enable-libfontconfig --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-openssl --enable-libbluray --enable-libcdio --enable-libtesseract
   libavutil      56. 58.100 / 56. 58.100
   libavcodec     58.105.100 / 58.105.100
   libavformat    58. 54.100 / 58. 54.100
   libavdevice    58. 11.101 / 58. 11.101
   libavfilter     7. 87.100 /  7. 87.100
   libswscale      5.  8.100 /  5.  8.100
   libswresample   3.  8.100 /  3.  8.100
   libpostproc    55.  8.100 / 55.  8.100
[video4linux2,v4l2 @ 0x3b9ff80] The driver changed the time per frame from 1/30 to 1/10
Input #0, video4linux2,v4l2, from '/dev/video2':
   Duration: N/A, start: 2054789.182838, bitrate: 147456 kb/s
     Stream #0:0: Video: rawvideo (YUY2 / 0x32595559), yuyv422, 1280x720, 147456 kb/s, 10 fps, 10 tbr, 1000k tbn, 1000k tbc
Stream mapping:
   Stream #0:0 -> #0:0 (rawvideo (native) -> rawvideo (native))
Press [q] to stop, [?] for help
Output #0, sdl,sdl2, to ':0':
   Metadata:
     encoder         : Lavf58.54.100
     Stream #0:0: Video: rawvideo (YUY2 / 0x32595559), yuyv422, 1280x720, q=2-31, 147456 kb/s, 10 fps, 10 tbn, 10 tbc
     Metadata:
       encoder         : Lavc58.105.100 rawvideo
av_interleaved_write_frame(): Operation not permitted
frame=    1 fps=0.0 q=-0.0 Lsize=N/A time=00:00:00.10 bitrate=N/A speed=0.364x 
video:1800kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
Conversion failed!




More information about the ffmpeg-user mailing list