exponential decay, is it possible?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

exponential decay, is it possible?

Michael Koch
I'd like to ask if it's possible to make an exponential decay effect
with FFmpeg.
Let's assume a pixel is fashing to luminance = 1 in just one frame. Then
in the output video I'd like to have the pixel flashing to 1
immediately, followed by an exponential decay with a time constant of a
few seconds.

The mathematics would be something like this:

luminance = 0.95 * luminance_in_last_frame;     // exponential decay
if (luminance_in_new_frame > luminance)
   luminance = luminance_in_new_frame;

Is there any trick to do this with already existing video filters?

Thanks,
Michael


_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: exponential decay, is it possible?

Gyan Doshi


On 05-08-2018 06:41 PM, Michael Koch wrote:

> I'd like to ask if it's possible to make an exponential decay effect
> with FFmpeg.
> Let's assume a pixel is fashing to luminance = 1 in just one frame. Then
> in the output video I'd like to have the pixel flashing to 1
> immediately, followed by an exponential decay with a time constant of a
> few seconds.
>
> The mathematics would be something like this:
>
> luminance = 0.95 * luminance_in_last_frame;     // exponential decay
> if (luminance_in_new_frame > luminance)
>    luminance = luminance_in_new_frame;

So,

frame 0    --> luminance 0
frame 1    --> luminance 1
frame 2    --> as per exprs above
...
frame 2+T  -->       "
frame NEXT  --> source luminance
...
frame LAST -->       "

?

Or would the exponential decay restart each time a pixel of lum 1 is
encountered?


Gyan
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: exponential decay, is it possible?

Michael Koch
Am 05.08.2018 um 15:42 schrieb Gyan Doshi:

>
>
> On 05-08-2018 06:41 PM, Michael Koch wrote:
>> I'd like to ask if it's possible to make an exponential decay effect
>> with FFmpeg.
>> Let's assume a pixel is fashing to luminance = 1 in just one frame.
>> Then in the output video I'd like to have the pixel flashing to 1
>> immediately, followed by an exponential decay with a time constant of
>> a few seconds.
>>
>> The mathematics would be something like this:
>>
>> luminance = 0.95 * luminance_in_last_frame;     // exponential decay
>> if (luminance_in_new_frame > luminance)
>>    luminance = luminance_in_new_frame;
>
> So,
>
> frame 0    --> luminance 0
> frame 1    --> luminance 1
> frame 2    --> as per exprs above
> ...
> frame 2+T  -->       "
> frame NEXT  --> source luminance
> ...
> frame LAST -->       "
>
> ?
>
> Or would the exponential decay restart each time a pixel of lum 1 is
> encountered?
>

Every time when the input becomes brighter than the last output frame,
the output is set to the input value. If input is below the last output
value, then exponential decay.
I have a timelapse video of the night sky with meteors. Each meteor is
visible only in one frame. I'd like to make them visible a little
longer, decaying over several frames.

Example:
Input   Output
0     0
1     1            // set to input value
0     0.95      // exponential decay begins
0     0.90
0.50     0.86
0.50     0.81     // until here
0.90     0.90     // now set again to input value, because input is
brighter
0.90     0.90     // keep at the same level
0.60     0.86     // exponential decay begins
0.60     0.81
0.60     0.77

Michael

--
**********************************************
   ASTRO ELECTRONIC   Dipl.-Ing. Michael Koch
        Raabestr. 43   37412 Herzberg
           www.astro-electronic.de
   Tel. +49 5521 854265   Fax +49 5521 854266
**********************************************

_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: exponential decay, is it possible?

Paul B Mahol
On 8/5/18, Michael Koch <[hidden email]> wrote:

> Am 05.08.2018 um 15:42 schrieb Gyan Doshi:
>>
>>
>> On 05-08-2018 06:41 PM, Michael Koch wrote:
>>> I'd like to ask if it's possible to make an exponential decay effect
>>> with FFmpeg.
>>> Let's assume a pixel is fashing to luminance = 1 in just one frame.
>>> Then in the output video I'd like to have the pixel flashing to 1
>>> immediately, followed by an exponential decay with a time constant of
>>> a few seconds.
>>>
>>> The mathematics would be something like this:
>>>
>>> luminance = 0.95 * luminance_in_last_frame;     // exponential decay
>>> if (luminance_in_new_frame > luminance)
>>>    luminance = luminance_in_new_frame;
>>
>> So,
>>
>> frame 0    --> luminance 0
>> frame 1    --> luminance 1
>> frame 2    --> as per exprs above
>> ...
>> frame 2+T  -->       "
>> frame NEXT  --> source luminance
>> ...
>> frame LAST -->       "
>>
>> ?
>>
>> Or would the exponential decay restart each time a pixel of lum 1 is
>> encountered?
>>
>
> Every time when the input becomes brighter than the last output frame,
> the output is set to the input value. If input is below the last output
> value, then exponential decay.
> I have a timelapse video of the night sky with meteors. Each meteor is
> visible only in one frame. I'd like to make them visible a little
> longer, decaying over several frames.
>
> Example:
> Input   Output
> 0     0
> 1     1            // set to input value
> 0     0.95      // exponential decay begins
> 0     0.90
> 0.50     0.86
> 0.50     0.81     // until here
> 0.90     0.90     // now set again to input value, because input is
> brighter
> 0.90     0.90     // keep at the same level
> 0.60     0.86     // exponential decay begins
> 0.60     0.81
> 0.60     0.77

If it is calculating global luma instead of local one, it can be added
to deflicker filter.
Otherwise you will need to write new video filter.
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: exponential decay, is it possible?

Michael Koch

>>
>> Every time when the input becomes brighter than the last output frame,
>> the output is set to the input value. If input is below the last output
>> value, then exponential decay.
>> I have a timelapse video of the night sky with meteors. Each meteor is
>> visible only in one frame. I'd like to make them visible a little
>> longer, decaying over several frames.
>>
>> Example:
>> Input   Output
>> 0     0
>> 1     1            // set to input value
>> 0     0.95      // exponential decay begins
>> 0     0.90
>> 0.50     0.86
>> 0.50     0.81     // until here
>> 0.90     0.90     // now set again to input value, because input is
>> brighter
>> 0.90     0.90     // keep at the same level
>> 0.60     0.86     // exponential decay begins
>> 0.60     0.81
>> 0.60     0.77
> If it is calculating global luma instead of local one, it can be added
> to deflicker filter.
> Otherwise you will need to write new video filter.

I need it local for all pixels.

Michael
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: exponential decay, is it possible?

Michael Koch
In reply to this post by Paul B Mahol

>>
>> Every time when the input becomes brighter than the last output frame,
>> the output is set to the input value. If input is below the last output
>> value, then exponential decay.
>> I have a timelapse video of the night sky with meteors. Each meteor is
>> visible only in one frame. I'd like to make them visible a little
>> longer, decaying over several frames.
>>
>> Example:
>> Input   Output
>> 0     0
>> 1     1            // set to input value
>> 0     0.95      // exponential decay begins
>> 0     0.90
>> 0.50     0.86
>> 0.50     0.81     // until here
>> 0.90     0.90     // now set again to input value, because input is
>> brighter
>> 0.90     0.90     // keep at the same level
>> 0.60     0.86     // exponential decay begins
>> 0.60     0.81
>> 0.60     0.77
> If it is calculating global luma instead of local one, it can be added
> to deflicker filter.
> Otherwise you will need to write new video filter.

Unfortunately I can't write a new filter. I think the closest match to
begin with is the new tmix filter.
tmix calculates a weighted average of the last n frames.
What I need is to apply weights to the last n frames, and then use the
brightest pixel out of those frames. The last frame would get weight 1,
and the previous frames get smaller weights according to the exponential
decay function.

Michael

_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: exponential decay, is it possible?

Michael Koch
In reply to this post by Michael Koch

> luminance = 0.95 * luminance_in_last_frame;     // exponential decay

I'm trying to do the following:
Read image temp0000.jpg, set luminance to 90%, write as temp0001.jpg
Read image temp0001.jpg, set luminance to 90%, write as temp0002.jpg
and so on in an iterative process, until 10 images are written.
But it works only for the first image and then stops. I think the
problem is that ffmpeg wants to read the next image before the first
image was written. Below is the full console output.

Michael


F:\xxx>c:/ffmpeg/ffmpeg -i temp%4d.jpg -vf lutyuv="y=0.9*val"
-frames 10 -q:v 1 -start_number 1 temp%4d.jpg
ffmpeg version N-91565-g1940c27c82 Copyright (c) 2000-2018 the FFmpeg
developers

   built with gcc 7.3.1 (GCC) 20180722
   configuration: --enable-gpl --enable-version3 --enable-sdl2
--enable-bzlib --e
nable-fontconfig --enable-gnutls --enable-iconv --enable-libass
--enable-libblur
ay --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb
--enable-
libopencore-amrwb --enable-libopenjpeg --enable-libopus
--enable-libshine --enab
le-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame
--enable-li
bvpx --enable-libwavpack --enable-libwebp --enable-libx264
--enable-libx265 --en
able-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp
--enable-
libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa
--enabl
e-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-amf
--enabl
e-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc
--enable-nvdec --enab
le-dxva2 --enable-avisynth
   libavutil      56. 18.102 / 56. 18.102
   libavcodec     58. 22.100 / 58. 22.100
   libavformat    58. 17.101 / 58. 17.101
   libavdevice    58.  4.101 / 58.  4.101
   libavfilter     7. 26.100 /  7. 26.100
   libswscale      5.  2.100 /  5.  2.100
   libswresample   3.  2.100 /  3.  2.100
   libpostproc    55.  2.100 / 55.  2.100
Input #0, image2, from 'temp%4d.jpg':
   Duration: 00:00:00.04, start: 0.000000, bitrate: N/A
     Stream #0:0: Video: mjpeg, yuvj422p(pc, bt470bg/unknown/unknown),
5472x3648,
  25 tbr, 25 tbn, 25 tbc
Stream mapping:
   Stream #0:0 -> #0:0 (mjpeg (native) -> mjpeg (native))
Press [q] to stop, [?] for help
Output #0, image2, to 'temp%4d.jpg':
   Metadata:
     encoder         : Lavf58.17.101
     Stream #0:0: Video: mjpeg, yuvj422p(pc), 5472x3648, q=2-31, 200
kb/s, 25 fps
, 25 tbn, 25 tbc
     Metadata:
       encoder         : Lavc58.22.100 mjpeg
     Side data:
       cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: -1
frame=    1 fps=0.0 q=1.0 Lsize=N/A time=00:00:00.04 bitrate=N/A
speed=0.122x

video:783kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB
muxing o
verhead: unknown


_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: exponential decay, is it possible?

Gyan Doshi


On 07-08-2018 04:09 AM, Michael Koch wrote:

> F:\xxx>c:/ffmpeg/ffmpeg -i temp%4d.jpg -vf lutyuv="y=0.9*val"
> -frames 10 -q:v 1 -start_number 1 temp%4d.jpg

FFmpeg does not edit files in-place. Input and output have to be different.

Besides,

 > Input #0, image2, from 'temp%4d.jpg':
 >   Duration: 00:00:00.04, start: 0.000000, bitrate: N/A

FFmpeg only sees one image.

Regards,
Gyan
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: exponential decay, is it possible?

Michael Koch

>
>> F:\xxx>c:/ffmpeg/ffmpeg -i temp%4d.jpg -vf lutyuv="y=0.9*val"
>> -frames 10 -q:v 1 -start_number 1 temp%4d.jpg
>
> FFmpeg does not edit files in-place. Input and output have to be
> different.

Input and output are different. Input starts with number 0, and output
starts with number 1.

>
> Besides,
>
> > Input #0, image2, from 'temp%4d.jpg':
> >   Duration: 00:00:00.04, start: 0.000000, bitrate: N/A
>
> FFmpeg only sees one image.

That's correct, at the beginning there is only one image temp0000.jpg
Is there any way to tell ffmpeg to write the output file temp0001.jpg
before it reads the next input image which has the same filename?

Michael

_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: exponential decay, is it possible?

Michael Koch
Am 07.08.2018 um 09:54 schrieb Michael Koch:
>
>>
>>> F:\xxx>c:/ffmpeg/ffmpeg -i temp%4d.jpg -vf lutyuv="y=0.9*val"
>>> -frames 10 -q:v 1 -start_number 1 temp%4d.jpg
>>
>> FFmpeg does not edit files in-place. Input and output have to be
>> different.

Let's assume I have a complex filter with several inputs. Is it possible
that one of the inputs is the previous output frame?

Michael
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: exponential decay, is it possible?

Gyan Doshi
In reply to this post by Michael Koch


On 07-08-2018 01:24 PM, Michael Koch wrote:
> That's correct, at the beginning there is only one image temp0000.jpg

ffmpeg's image sequence demuxer, when not reading from a pipe, will
probe for sequence size at initialization, so if an image doesn't exist
at that stage, it won't be considered.

 > Is it possible that one of the inputs is the previous output frame?

There's no general recursive mechanism. You can always manually chain
the same filter, however, this will get unwieldy quick.

For your particular case, you can use the geq filter

     ffmpeg -loop 1 -i starting-image.jpg -vf
"geq=lum='p(X,Y)*pow(0.9,N)':cb='p(X,Y)'" -vframes 10 -q:v 2 out%d.jpg

The input luma is multiplied with 0.9 raised to the input frame count;
count starts from zero. Chroma channels remain as-is.

Regards,
Gyan

_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".