[FFmpeg-user] How to set a seed value for a random generator?

Michael Koch astroelectronic at t-online.de
Mon Apr 13 16:54:14 EEST 2020


Hello,

I want to add a +-10 pixels random horizontal jitter to video lines. 
This is the first test:

c:\ffmpeg\ffmpeg -f lavfi -i testsrc2=size=vga -vf 
format=gray,geq=lum='lum(X-10+20*random(0),Y)' -t 3 -y out1.mp4

This works, but it's a pixel-wise jitter and that's not what I want. I 
want that all pixels in the same line get the same random jitter.
The idea is to set a seed value for the random generator. The seed value 
is a function of N and Y.

c:\ffmpeg\ffmpeg -f lavfi -i testsrc2=size=vga -vf 
format=gray,geq=lum='st(0,N+Y);lum(X-10+20*random(0),Y)' -t 3 -y out2.mp4

This doesn't work, no jitter is visible at all.
May be the seed value must be in the [0..1] range? Let's test it:

c:\ffmpeg\ffmpeg -f lavfi -i testsrc2=size=vga -vf 
format=gray,geq=lum='st(0,mod(0.001*(N+Y),1));lum(X-10+20*random(0),Y)' 
-t 3 -y out3.mp4

Same result as before, no jitter is visible at all.

It seems that either I have totally misunderstood how the random 
generator works, or it's impossible to set seed values, or it's a bug.

The console output for the last command line is shown below.

Michael



C:\Users\mKoch\Desktop>c:\ffmpeg\ffmpeg -f lavfi -i testsrc2=size=vga 
-vf format
=gray,geq=lum='st(0,mod(0.001*(N+Y),1));lum(X-10+20*random(0),Y)' -t 3 
-y out3.m
p4
ffmpeg version git-2020-04-12-f1894c2 Copyright (c) 2000-2020 the FFmpeg 
develop
ers
   built with gcc 9.3.1 (GCC) 20200328
   configuration: --enable-gpl --enable-version3 --enable-sdl2 
--enable-fontconfi
g --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d 
--enable-libb
luray --enable-libfreetype --enable-libmp3lame 
--enable-libopencore-amrnb --enab
le-libopencore-amrwb --enable-libopenjpeg --enable-libopus 
--enable-libshine --e
nable-libsnappy --enable-libsoxr --enable-libsrt --enable-libtheora 
--enable-lib
twolame --enable-libvpx --enable-libwavpack --enable-libwebp 
--enable-libx264 --
enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma 
--enable-zlib --e
nable-gmp --enable-libvidstab --enable-libvmaf --enable-libvorbis 
--enable-libvo
-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid 
--enable-libaom
--disable-w32threads --enable-libmfx --enable-ffnvcodec 
--enable-cuda-llvm --ena
ble-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 
--enable
-avisynth --enable-libopenmpt --enable-amf
   libavutil      56. 42.102 / 56. 42.102
   libavcodec     58. 78.102 / 58. 78.102
   libavformat    58. 42.100 / 58. 42.100
   libavdevice    58.  9.103 / 58.  9.103
   libavfilter     7. 77.101 /  7. 77.101
   libswscale      5.  6.101 /  5.  6.101
   libswresample   3.  6.100 /  3.  6.100
   libpostproc    55.  6.100 / 55.  6.100
Input #0, lavfi, from 'testsrc2=size=vga':
   Duration: N/A, start: 0.000000, bitrate: N/A
     Stream #0:0: Video: rawvideo (I420 / 0x30323449), yuv420p, 640x480 
[SAR 1:1
DAR 4:3], 25 tbr, 25 tbn, 25 tbc
Stream mapping:
   Stream #0:0 -> #0:0 (rawvideo (native) -> h264 (libx264))
Press [q] to stop, [?] for help
[libx264 @ 00000000035a1880] using SAR=1/1
[libx264 @ 00000000035a1880] using cpu capabilities: MMX2 SSE2Fast SSSE3 
SSE4.2
AVX FMA3 BMI2 AVX2
[libx264 @ 00000000035a1880] profile High, level 3.0, 4:0:0, 8-bit
[libx264 @ 00000000035a1880] 264 - core 159 - H.264/MPEG-4 AVC codec - 
Copyleft
2003-2019 - 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_rang
e=16 chroma_me=0 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 
interla
ced=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 qpma
x=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to 'out3.mp4':
   Metadata:
     encoder         : Lavf58.42.100
     Stream #0:0: Video: h264 (libx264) (avc1 / 0x31637661), gray, 
640x480 [SAR 1
:1 DAR 4:3], q=-1--1, 25 fps, 12800 tbn, 25 tbc
     Metadata:
       encoder         : Lavc58.78.102 libx264
     Side data:
       cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: N/A
frame=   14 fps=0.0 q=0.0 size=       0kB time=00:00:00.00 bitrate=N/A 
speed=
frame=   28 fps= 26 q=0.0 size=       0kB time=00:00:00.00 bitrate=N/A 
speed=
frame=   42 fps= 26 q=0.0 size=       0kB time=00:00:00.00 bitrate=N/A 
speed=
frame=   56 fps= 26 q=28.0 size=       0kB time=00:00:00.12 bitrate=   
3.2kbits/
frame=   70 fps= 26 q=28.0 size=       0kB time=00:00:00.68 bitrate=   
0.6kbits/
frame=   75 fps= 24 q=-1.0 Lsize=     244kB time=00:00:02.88 bitrate= 
694.6kbits
/s speed=0.928x
video:243kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB 
muxing o
verhead: 0.687764%
[libx264 @ 00000000035a1880] frame I:1     Avg QP:16.21  size:  5580
[libx264 @ 00000000035a1880] frame P:21    Avg QP:20.55  size:  4059
[libx264 @ 00000000035a1880] frame B:53    Avg QP:30.86  size:  2959
[libx264 @ 00000000035a1880] consecutive B-frames:  1.3%  5.3% 24.0% 69.3%
[libx264 @ 00000000035a1880] mb I  I16..4: 37.8% 46.9% 15.3%
[libx264 @ 00000000035a1880] mb P  I16..4:  4.2%  4.1%  4.6% P16..4:  
6.1%  3.1
%  1.4%  0.0%  0.0%    skip:76.5%
[libx264 @ 00000000035a1880] mb B  I16..4:  0.0%  0.1%  1.3% B16..8: 
13.8%  3.2
%  0.8%  direct: 1.1%  skip:79.5%  L0:49.5% L1:43.1% BI: 7.4%
[libx264 @ 00000000035a1880] 8x8 transform intra:31.3% inter:20.8%
[libx264 @ 00000000035a1880] coded y intra: 32.6% inter: 4.2%
[libx264 @ 00000000035a1880] i16 v,h,dc,p: 88% 11%  1%  0%
[libx264 @ 00000000035a1880] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 20% 14% 65%  
0%  0%
  0%  0%  0%  0%
[libx264 @ 00000000035a1880] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 28% 16% 31%  
3%  4%
  4%  4%  4%  6%
[libx264 @ 00000000035a1880] i8c dc,h,v,p: 100%  0%  0%  0%
[libx264 @ 00000000035a1880] Weighted P-Frames: Y:0.0%
[libx264 @ 00000000035a1880] ref P L0: 59.3%  5.8% 21.6% 13.2%
[libx264 @ 00000000035a1880] ref B L0: 70.8% 23.4%  5.8%
[libx264 @ 00000000035a1880] ref B L1: 92.0%  8.0%
[libx264 @ 00000000035a1880] kb/s:660.44




More information about the ffmpeg-user mailing list