3

I want to do video captures with a video4linux2 device.

The video data contains a lot of darker shades of grey.
When I capture a single PNG file, everything is fine.
Capturing with ffmpeg/avconf using x264 truncates my color space to 16..235.

I tried to define -color_range 2 but it didn't have any effect.
I also played with the different pixel formats (yuv444p, yuv420, ..) --without success.

This is the command line which produces the reduce color range video:

$avconv -f video4linux2 -i /dev/video0 -vcodec libx264 -pix_fmt yuv444p -color_range 2 -crf 14 -t 120 -y out.mp4

avconv version 0.8.17-4:0.8.17-0ubuntu0.12.04.1, Copyright (c) 2000-2014 the Libav developers
  built on Mar 16 2015 13:26:50 with gcc 4.6.3
[video4linux2 @ 0x2044b60] Estimating duration from bitrate, this may be inaccurate
Input #0, video4linux2, from '/dev/video0':
  Duration: N/A, start: 1445936359.182177, bitrate: 890634 kb/s
    Stream #0.0: Video: rawvideo, yuyv422, 1280x720, 890634 kb/s, 60.40 tbr, 1000k tbn, 60.40 tbc
[buffer @ 0x20450a0] w:1280 h:720 pixfmt:yuyv422
[format @ 0x2046d20] auto-inserting filter 'auto-inserted scaler 0' between the filter 'src' and the filter 'Parsed filter 0 format'
[scale @ 0x2047660] w:1280 h:720 fmt:yuyv422 -> w:1280 h:720 fmt:yuv444p flags:0x4
[libx264 @ 0x2045fe0] using cpu capabilities: MMX2 SSE2Fast SSSE3 FastShuffle SSE4.2 AVX
[libx264 @ 0x2045fe0] profile High 4:4:4 Predictive, level 4.0, 4:4:4 8-bit
[libx264 @ 0x2045fe0] 264 - core 120 r2151 a3f4407 - H.264/MPEG-4 AVC codec - Copyleft 2003-2011 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x1:0x111 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=0 me_range=16 chroma_me=1 trellis=1 8x8dct=0 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=4 threads=12 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=0 b_adapt=1 b_bias=0 direct=1 weightb=0 open_gop=1 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=14.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.25 aq=1:1.00
Output #0, mp4, to 'out.mp4':
  Metadata:
    encoder         : Lavf53.21.1
    Stream #0.0: Video: libx264, yuv444p, 1280x720, q=-1--1, 302 tbn, 60.40 tbc
Stream mapping:
  Stream #0:0 -> #0:0 (rawvideo -> libx264)

My last tries were to define a color matrix to manually scale 0..255 to 16..235, so that I will end up with a slightly compressed, but a least complete color space.

But this resulted in an error from avconf

$ avconv -f video4linux2 -i /dev/video0 -vcodec libx264 -pix_fmt yuv444p -color_range 2 -vf 'format=yuv444p,colormatrix=bt709:bt601' -crf 14 -t 120 -y out.mp4

avconv version 0.8.17-4:0.8.17-0ubuntu0.12.04.1, Copyright (c) 2000-2014 the Libav developers
  built on Mar 16 2015 13:26:50 with gcc 4.6.3
[video4linux2 @ 0xabbb60] Estimating duration from bitrate, this may be inaccurate
Input #0, video4linux2, from '/dev/video0':
  Duration: N/A, start: 1445936333.196864, bitrate: 890634 kb/s
    Stream #0.0: Video: rawvideo, yuyv422, 1280x720, 890634 kb/s, 60.40 tbr, 1000k tbn, 60.40 tbc
[buffer @ 0xac0ee0] w:1280 h:720 pixfmt:yuyv422
No such filter: 'colormatrix'
Error opening filters!

Do you know how to get ffmpeg to encode the full color range?

1 Answer 1

2

In this case, the problem didn't come from ffmpeg/avconv.

The rawvideo source I use offers different color formats to be used:

  • argb32
  • rgb24
  • bgr24
  • yuv444
  • yuv420
  • [...]

When I extract a png file (which was fine), the bgr24 color format is used. When I capture a video, avconv automatically chose one of the yuv formats. I guess the clamping to (16..235) did happen in the driver itself, that's why I couldn't influence it.

By giving the parameter -input_format bgr24 to the input device, I chose the unclamped value range and the capturing worked fine.

Final command line, with yuv420p as target format which produces even a Windows Media Player complatible output:

avconv -f video4linux2 -input_format bgr24 -i /dev/video0 -vcodec libx264 -pix_fmt yuv420p -color_range 2 -crf 14 -t 120 -y out.mp4

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.