[FFmpeg-user] Question about random() expression

Jim DeLaHunt list+ffmpeg-user at jdlh.com
Thu Dec 28 01:54:00 EET 2023


On 2023-12-27 15:20, Michael Koch wrote:
> Am 27.12.2023 um 23:59 schrieb Jim DeLaHunt:
>> Michael:
>> On 2023-12-27 13:51, Michael Koch wrote:
>>> ...I'm using this command line to print four consecutive random 
>>> numbers:
>>> ...
>> I do not have an answer to your question about the behaviour of the 
>> random() function. However, I cannot reproduce your results on my 
>> machine. I get an error complaining about the video filter syntax 
>> instead.
> If not on a Windows machine, you may have to encapsulate the filter 
> thread in double quotes.
> Please try this command:
> ffmpeg -filter_threads 1 -loglevel repeat -f lavfi -i 
> color=gray:size=1x1,format=gray -vf 
> "geq=lum='st(0,0.123);print(random(0));print(random(0));print(random(0));print(random(0))'" 
> -frames 1 -y out.png

Right you are. Enclosing the filter expression in double quotes, I was 
able to reproduce your result. Four numbers printed out, and the first 
of them was 0.000000. The remaining three were exactly the same as your 
output. That makes those numbers seem not very random.

Interestingly, when I change "random(0)" to "random(0.9)", I get the 
identical sequence of four numbers. The behaviour of the parameter is 
not the "seed" behaviour that I expect.

The documentation says, "x is the index of the internal variable which 
will be used to save the seed/state." 
(https://ffmpeg.org/ffmpeg-all.html#Expression-Evaluation). I don't know 
what it means by "index of the internal variable", and I don't know what 
"save" means. In a function named random(), I expect the parameter to be 
used as a seed. I guess this is one of the places where one has to read 
the source code.

Apologies for my confusion,
      —Jim DeLaHunt

More information about the ffmpeg-user mailing list