Re: [Libav-user] AVFrame pts and av_usleep funciton.

2023-08-30 Thread Richard Hussong
On Mon, Aug 21, 2023 at 5:48 AM Denis Gottardello 
wrote:

>
> Thanks for you reply.
>
> So these lines of code:
>
> int64_t pts= av_rescale(pAVFrame->pts,
> pAVCodecContextVideo->framerate.den, pAVCodecContextVideo->framerate.num);
>
> printf("pts, %d\n", pts);
>
> Should print the timestamp (as time_t) of each frame? Is the pts value
> calculated correctly?
>

To use usleep, you need to convert the PTS interval to a number of
microseconds using something like

int64_t usecs = av_rescale_q( pts - prev_pts, video_timebase, us_timebase )

where "video_timebase" is the timebase of the video PTS values and
"us_timebase" is the microsecond timebase: num = 1, den = 100.

- Richard Hussong

>
> In data lunedì 21 agosto 2023 11:15:06 CEST, Paul B Mahol ha scritto:
>
> > On Mon, Aug 21, 2023 at 10:30 AM Denis Gottardello
>
> > 
>
> > wrote:
>
> > > In order to implement a sleep function and wait the right time to
> display
>
> > > a frame I have written this code:
>
> > >
>
> > > int framerate= pAVCodecContextVideo->framerate.num /
>
> > > pAVCodecContextVideo->framerate.den;
>
> > >
>
> > > if (previous!= 0) {
>
> > >
>
> > > av_usleep((pAVFrame->pts - previous) / framerate);
>
> > >
>
> > > }
>
> > >
>
> > > previous= pAVFrame->pts;
>
> > >
>
> > > but the value passed to av_usleep() is wrong.
>
> > >
>
> > > How have I to calculate it?
>
> >
>
> > If you really want to do it that way you need to use floating point
>
> > calculations, or use fixed point arithmetic (av_rescale*)
>
> > to convert seconds to microseconds.
>
> >
>
> > > Best regards.
>
> > >
>
> > >
>
> > > --
>
> > >
>
> > > +39.347.4070897
>
> > >
>
> > > http://www.labcsp.com
>
> > >
>
> > > http://www.denisgottardello.it
>
> > >
>
> > > GMT+1
>
> > >
>
> > > Skype: mrdebug
>
> > > ___
>
> > > Libav-user mailing list
>
> > > Libav-user@ffmpeg.org
>
> > > https://ffmpeg.org/mailman/listinfo/libav-user
>
> > >
>
> > > To unsubscribe, visit link above, or email
>
> > > libav-user-requ...@ffmpeg.org with subject "unsubscribe".
> --
>
> +39.347.4070897
>
> http://www.labcsp.com
>
> http://www.denisgottardello.it
>
> GMT+1
>
> Skype: mrdebug
> ___
> Libav-user mailing list
> Libav-user@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/libav-user
>
> To unsubscribe, visit link above, or email
> libav-user-requ...@ffmpeg.org with subject "unsubscribe".
>
___
Libav-user mailing list
Libav-user@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/libav-user

To unsubscribe, visit link above, or email
libav-user-requ...@ffmpeg.org with subject "unsubscribe".


Re: [Libav-user] AVFrame pts and av_usleep funciton.

2023-08-21 Thread Denis Gottardello
Thanks for you reply.
So these lines of code:

int64_t pts= av_rescale(pAVFrame->pts, pAVCodecContextVideo->framerate.den, 
pAVCodecContextVideo->framerate.num);
printf("pts, %d\n", pts);

Should print the timestamp (as time_t) of each frame? Is the pts value 
calculated correctly?

In data lunedì 21 agosto 2023 11:15:06 CEST, Paul B Mahol ha scritto:
> On Mon, Aug 21, 2023 at 10:30 AM Denis Gottardello
> 
> wrote:
> > In order to implement a sleep function and wait the right time to display
> > a frame I have written this code:
> > 
> > int framerate= pAVCodecContextVideo->framerate.num /
> > pAVCodecContextVideo->framerate.den;
> > 
> > if (previous!= 0) {
> > 
> > av_usleep((pAVFrame->pts - previous) / framerate);
> > 
> > }
> > 
> > previous= pAVFrame->pts;
> > 
> > but the value passed to av_usleep() is wrong.
> > 
> > How have I to calculate it?
> 
> If you really want to do it that way you need to use floating point
> calculations, or use fixed point arithmetic (av_rescale*)
> to convert seconds to microseconds.
> 
> > Best regards.
> > 
> > 
> > --
> > 
> > +39.347.4070897
> > 
> > http://www.labcsp.com
> > 
> > http://www.denisgottardello.it
> > 
> > GMT+1
> > 
> > Skype: mrdebug
> > ___
> > Libav-user mailing list
> > Libav-user@ffmpeg.org
> > https://ffmpeg.org/mailman/listinfo/libav-user
> > 
> > To unsubscribe, visit link above, or email
> > libav-user-requ...@ffmpeg.org with subject "unsubscribe".
-- 
+39.347.4070897
http://www.labcsp.com[1] 
http://www.denisgottardello.it[2] 
GMT+1
Skype: mrdebug


[1] http://www.labcsp.com
[2] http://www.denisgottardello.it
___
Libav-user mailing list
Libav-user@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/libav-user

To unsubscribe, visit link above, or email
libav-user-requ...@ffmpeg.org with subject "unsubscribe".


Re: [Libav-user] AVFrame pts and av_usleep funciton.

2023-08-21 Thread Paul B Mahol
On Mon, Aug 21, 2023 at 10:30 AM Denis Gottardello 
wrote:

>
> In order to implement a sleep function and wait the right time to display
> a frame I have written this code:
>
> int framerate= pAVCodecContextVideo->framerate.num /
> pAVCodecContextVideo->framerate.den;
>
> if (previous!= 0) {
>
> av_usleep((pAVFrame->pts - previous) / framerate);
>
> }
>
> previous= pAVFrame->pts;
>
> but the value passed to av_usleep() is wrong.
>
> How have I to calculate it?
>

If you really want to do it that way you need to use floating point
calculations, or use fixed point arithmetic (av_rescale*)
to convert seconds to microseconds.


>
> Best regards.
>
>
> --
>
> +39.347.4070897
>
> http://www.labcsp.com
>
> http://www.denisgottardello.it
>
> GMT+1
>
> Skype: mrdebug
> ___
> Libav-user mailing list
> Libav-user@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/libav-user
>
> To unsubscribe, visit link above, or email
> libav-user-requ...@ffmpeg.org with subject "unsubscribe".
>
___
Libav-user mailing list
Libav-user@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/libav-user

To unsubscribe, visit link above, or email
libav-user-requ...@ffmpeg.org with subject "unsubscribe".