Framerate question...
Hi all. In my application I create different movies with different framerates with FFMpeg. I set the FFMpeg framerate in this way: c->time_base.num = 5; c->time_base.den = 50; and then I change the denominator when needed. When I start my application I get this message: [mpeg4 @ 0x833f368] removing common factors from framerate This message disappear if I use 1 as numerator... but I need more precision than a decimal unit... so I choose 5 and I have 0.2. My question... is a bad thing to have a numerator different from 1 ? _______________________________________ Mattia Roccoberton Belcom Security Systems S.R.L. Tel +39 (0)444 357920 Fax +39 (0)444 359847 _______________________________________
Hi On Wed, Aug 31, 2005 at 04:36:34PM +0200, Mattia Roccoberton wrote:
Hi all. In my application I create different movies with different framerates with FFMpeg. I set the FFMpeg framerate in this way: c->time_base.num = 5; c->time_base.den = 50; and then I change the denominator when needed.
i hope you dont mean that you change it in the middle while encoding something
When I start my application I get this message: [mpeg4 @ 0x833f368] removing common factors from framerate This message disappear if I use 1 as numerator... but I need more precision than a decimal unit... so I choose 5 and I have 0.2. My question... is a bad thing to have a numerator different from 1 ?
no, but its bad if they have a common factor >1, as some formats dont allow that btw, read http://en.wikipedia.org/wiki/Common_Factor [...] -- Michael
In my application I create different movies with different framerates with FFMpeg. I set the FFMpeg framerate in this way: c->time_base.num = 5; c->time_base.den = 50; and then I change the denominator when needed.
i hope you dont mean that you change it in the middle while encoding something
Nope. I change it when after I close a video and before opening a new video.
When I start my application I get this message: [mpeg4 @ 0x833f368] removing common factors from framerate This message disappear if I use 1 as numerator... but I need more precision than a decimal unit... so I choose 5 and I have 0.2. My question... is a bad thing to have a numerator different from 1 ?
no, but its bad if they have a common factor >1, as some formats dont allow that btw, read http://en.wikipedia.org/wiki/Common_Factor
Hahaha. I remeber what is Common Factor BTW tnx :) The thing is not clear to me is why FFMpeg don't like my numerator :) I use the MOV container + MPeg4 video codec + no audio.
On Wed, Aug 31, 2005 at 04:36:34PM +0200, Mattia Roccoberton wrote:
Hi all. In my application I create different movies with different framerates with FFMpeg. I set the FFMpeg framerate in this way: c->time_base.num = 5; c->time_base.den = 50;
You probably want to use 1/50 and increment timestamps accordingly..
and then I change the denominator when needed.
Not valid.
When I start my application I get this message: [mpeg4 @ 0x833f368] removing common factors from framerate This message disappear if I use 1 as numerator... but I need more precision than a decimal unit... so I choose 5 and I have 0.2. My question... is a bad thing to have a numerator different from 1 ?
It's nonsense and indicates that you didn't understand what time base means. 5/50 and 1/10 are equal, and either way you'll have a fundamental time unit of 1/10 second. If you want a smaller time unit, choose an appropriate one. Rich
In my application I create different movies with different framerates with FFMpeg. I set the FFMpeg framerate in this way: c->time_base.num = 5; c->time_base.den = 50;
You probably want to use 1/50 and increment timestamps accordingly..
Mmm... interesting :) Can you explain me better how can I change the timestamps...? My situation is this: I have a framegrabber which sometimes give me less frames than usual, and I can connect 1 video or more... so in the videos I produce I need to change the framerate correctly to get 30 secs movies. App structure:
Open a new movie file Loop: > Get a frame > Write the frame > If passed 30 secs: > Close the current movie file > Calculate the last framerate > Set the new framerate (the denominator) > Open a new movie file Close the last movie file
and then I change the denominator when needed.
Not valid.
Sigh... but it works :) Can you tell me what should I do in details ?
It's nonsense and indicates that you didn't understand what time base means.
This is sure :) There is so little documentation about FFMpeg development :( Do you know of any good documentation... ?
5/50 and 1/10 are equal, and either way you'll have a fundamental time unit of 1/10 second.
This is clear :) BTW 5 / 50 is my initial set. When I need to change the framerate I set only the denominator... Like 5 / 100, 5 / 41, 5 / 20, etc. etc.
If you want a smaller time unit, choose an appropriate one.
Ok, but HOW?!? :) Help me plz! :)
Mattia Roccoberton wrote:
In my application I create different movies with different framerates with FFMpeg. I set the FFMpeg framerate in this way: c->time_base.num = 5; c->time_base.den = 50;
You probably want to use 1/50 and increment timestamps accordingly..
Mmm... interesting :) Can you explain me better how can I change the timestamps...?
My situation is this: I have a framegrabber which sometimes give me less frames than usual, and I can connect 1 video or more... so in the videos I produce I need to change the framerate correctly to get 30 secs movies. App structure:
Open a new movie file Loop: Get a frame Write the frame If passed 30 secs: > Close the current movie file > Calculate the last framerate > Set the new framerate (the denominator) > Open a new movie file Close the last movie file
and then I change the denominator when needed.
Not valid.
Sigh... but it works :) Can you tell me what should I do in details ?
It's nonsense and indicates that you didn't understand what time base means.
This is sure :) There is so little documentation about FFMpeg development :( Do you know of any good documentation... ?
5/50 and 1/10 are equal, and either way you'll have a fundamental time unit of 1/10 second.
This is clear :) BTW 5 / 50 is my initial set. When I need to change the framerate I set only the denominator... Like 5 / 100, 5 / 41, 5 / 20, etc. etc.
I dont think you can. You will have to change both.
If you want a smaller time unit, choose an appropriate one.
Ok, but HOW?!? :) Help me plz! :)
-- Michel Bardiaux R&D Director T +32 [0] 2 790 29 41 F +32 [0] 2 790 29 02 E mailto:mbardiaux at mediaxim.be Mediaxim NV/SA Vorstlaan 191 Boulevard du Souverain Brussel 1160 Bruxelles http://www.mediaxim.com/
BTW 5 / 50 is my initial set. When I need to change the framerate I set only the denominator... Like 5 / 100, 5 / 41, 5 / 20, etc. etc.
I dont think you can. You will have to change both.
Change both? What do you mean? If I change both with the same rapport the framerate doesn't change... If I change both with a numerator different from 1 and from 5... I think is the same to keep 5... If I use always 1 as numerator and I change the denominator I can't get good framerates to get 30 seconds' clips...
Mattia Roccoberton wrote:
BTW 5 / 50 is my initial set. When I need to change the framerate I set only the denominator... Like 5 / 100, 5 / 41, 5 / 20, etc. etc.
I dont think you can. You will have to change both.
Change both? What do you mean?
If I change both with the same rapport the framerate doesn't change... If I change both with a numerator different from 1 and from 5... I think is the same to keep 5... If I use always 1 as numerator and I change the denominator I can't get good framerates to get 30 seconds' clips...
You set it every time as if were the first time, i.e. c->time_base.num = 5; c->time_base.den = 50; ... c->time_base.num = 5; c->time_base.den = 41; If you need to keep track of *your* denominator, use your own variable. -- Michel Bardiaux R&D Director T +32 [0] 2 790 29 41 F +32 [0] 2 790 29 02 E mailto:mbardiaux at mediaxim.be Mediaxim NV/SA Vorstlaan 191 Boulevard du Souverain Brussel 1160 Bruxelles http://www.mediaxim.com/
Change both? What do you mean?
If I change both with the same rapport the framerate doesn't change... If I change both with a numerator different from 1 and from 5... I think is the same to keep 5... If I use always 1 as numerator and I change the denominator I can't get good framerates to get 30 seconds' clips...
You set it every time as if were the first time, i.e.
c->time_base.num = 5; c->time_base.den = 50; ... c->time_base.num = 5; c->time_base.den = 41;
If you need to keep track of *your* denominator, use your own variable.
I can't understand the point for you. *I* have my own denominator in a variable and the numerator in a constant... the code I wrote is only a sample. These are only implementation details. The thing is not clear to me is if I can or cannot use a numerator different from 1 without problems.
Mattia Roccoberton wrote:
Change both? What do you mean?
If I change both with the same rapport the framerate doesn't change... If I change both with a numerator different from 1 and from 5... I think is the same to keep 5... If I use always 1 as numerator and I change the denominator I can't get good framerates to get 30 seconds' clips...
You set it every time as if were the first time, i.e.
c->time_base.num = 5; c->time_base.den = 50; ... c->time_base.num = 5; c->time_base.den = 41;
If you need to keep track of *your* denominator, use your own variable.
I can't understand the point for you. *I* have my own denominator in a variable and the numerator in a constant... the code I wrote is only a sample. These are only implementation details. The thing is not clear to me is if I can or cannot use a numerator different from 1 without problems.
Of course you can. But you should accept that lavc changes it. c->time_base.num = 5; c->time_base.den = 50; ... // lavc change num to 1 and den to 10 which still is a 10fps frame rate ... c->time_base.num = 5; c->time_base.den = 41; -- Michel Bardiaux R&D Director T +32 [0] 2 790 29 41 F +32 [0] 2 790 29 02 E mailto:mbardiaux at mediaxim.be Mediaxim NV/SA Vorstlaan 191 Boulevard du Souverain Brussel 1160 Bruxelles http://www.mediaxim.com/
Hi On Thu, Sep 01, 2005 at 03:07:54PM +0200, Mattia Roccoberton wrote:
Change both? What do you mean?
If I change both with the same rapport the framerate doesn't change... If I change both with a numerator different from 1 and from 5... I think is the same to keep 5... If I use always 1 as numerator and I change the denominator I can't get good framerates to get 30 seconds' clips...
You set it every time as if were the first time, i.e.
c->time_base.num = 5; c->time_base.den = 50; ... c->time_base.num = 5; c->time_base.den = 41;
If you need to keep track of *your* denominator, use your own variable.
I can't understand the point for you. *I* have my own denominator in a variable and the numerator in a constant... the code I wrote is only a sample. These are only implementation details. The thing is not clear to me is if I can or cannot use a numerator different from 1 without problems.
you can as long as gcd(num,den)==1 if the later is false libavcodec will _probably_ fix it for you but that will fail if you expect that libavcodec wont change them [...] -- Michael
The thing is not clear to me is if I can or cannot use a numerator different from 1 without problems.
you can as long as gcd(num,den)==1 if the later is false libavcodec will _probably_ fix it for you
_probably_ ? I look in the source and I think it fix the framerate as needed. ffmpeg/libavcodec/mpegvideo.c: 1073 ... i= ff_gcd(avctx->time_base.den, avctx->time_base.num); if(i > 1){ av_log(avctx, AV_LOG_INFO, "removing common factors from framerate\n"); avctx->time_base.den /= i; avctx->time_base.num /= i; // return -1; } ...
but that will fail if you expect that libavcodec wont change them
There's no problem for my app if libavcodec chages them. The movies I produce are ok, always 30 secs. I get always the "removing common factors from framerate", BTW I close the stdout soon so it's ok. Tnx for your reply.
On Thu, Sep 01, 2005 at 05:30:12PM +0200, Mattia Roccoberton wrote:
The thing is not clear to me is if I can or cannot use a numerator different from 1 without problems.
you can as long as gcd(num,den)==1 if the later is false libavcodec will _probably_ fix it for you
_probably_ ? I look in the source and I think it fix the framerate as needed.
ffmpeg/libavcodec/mpegvideo.c: 1073 ... i= ff_gcd(avctx->time_base.den, avctx->time_base.num); if(i > 1){ av_log(avctx, AV_LOG_INFO, "removing common factors from framerate\n"); avctx->time_base.den /= i; avctx->time_base.num /= i; // return -1; } ...
but that will fail if you expect that libavcodec wont change them
There's no problem for my app if libavcodec chages them. The movies I produce are ok, always 30 secs. I get always the "removing common factors from framerate", BTW I close the stdout soon so it's ok.
Tnx for your reply.
You really seem to have no idea what framerate and units of time mean.. Think about it a little bit or eventually you'll realize that all the videos you've been making are nonsense with random speeds.. Rich
You really seem to have no idea what framerate and units of time mean.. Think about it a little bit or eventually you'll realize that all the videos you've been making are nonsense with random speeds..
:) This is true... for a video codec with fixed framerate. But with MP4 the framerate can be variable and this is perfect for my application. ( http://en.wikipedia.org/wiki/Mp4 )
On Fri, Sep 02, 2005 at 09:10:28AM +0200, Mattia Roccoberton wrote:
You really seem to have no idea what framerate and units of time mean.. Think about it a little bit or eventually you'll realize that all the videos you've been making are nonsense with random speeds..
:) This is true... for a video codec with fixed framerate. But with MP4 the framerate can be variable and this is perfect for my application. ( http://en.wikipedia.org/wiki/Mp4 )
Like I said you have no idea what you're talking about. "Variable framerate" does not mean you randomly change the time base during the movie. It means you pick a common timebase and then set timestamps appropriately. Rich
Like I said you have no idea what you're talking about.
I already told that I have little experience in this matter. But I need to learn and I'm here for this.
"Variable framerate" does not mean you randomly change the time base during the movie.
But it works. Can you tell me what bad things could happen if I create movies in this way?
It means you pick a common timebase and then set timestamps appropriately.
I ask you again: can you tell me how could I set the timestamps? Or can you point me to a good documentation about it? What common timebases I can use?
On Mon, Sep 05, 2005 at 09:18:09AM +0200, Mattia Roccoberton wrote:
Like I said you have no idea what you're talking about.
I already told that I have little experience in this matter. But I need to learn and I'm here for this.
"Variable framerate" does not mean you randomly change the time base during the movie.
But it works. Can you tell me what bad things could happen if I create movies in this way?
It is _not_ working. As far as I can tell you just don't see it as working wrong since you're making these tiny clips, artificially adjusting their length by assuming a framerate exists when it doesn't, and also not recording sound so there's nothing to visibly/audibly desync.
It means you pick a common timebase and then set timestamps appropriately.
I ask you again: can you tell me how could I set the timestamps?
You set timebase to the fundamental time unit you want to work with, in seconds. Then you set the timestamp of each frame to the time (in timebase units) at which that frame should be shown. For example suppose you have a system in which frames may take place on 1/120 second granularity, with a mix of 24fps and 30fps content. You could use a timebase of 1/120 with timestamps: 00 05 10 15 20 25 30 34 38 42 46 50 54 58 62 66 70 ... \_________________/\_____________________________/ 24 fps sequence 30 fps sequence If your frames don't come in on any regular interval, but at completly random times (supposedly some webcam devices are random..) then you can just set a timebase of 1/1000 or something and use timestamps in milliseconds taken from the actual (system clock) times at which you sampled the frames.
Or can you point me to a good documentation about it?
Your grade school arithmetic text...
What common timebases I can use?
By common I meant one that's shared by all the content you'll be storing. For example if you had 50/3, 25, and 24000/1001 fps content, a common timebase would be 1/24000. Rich
Is there any way to allocate more buffers so that the system doesn't drop frames if some frames takes more time to encode? David
You set timebase to the fundamental time unit you want to work with, in seconds. Then you set the timestamp of each frame to the time (in timebase units) at which that frame should be shown. For example suppose you have a system in which frames may take place on 1/120 second granularity, with a mix of 24fps and 30fps content. You could use a timebase of 1/120 with timestamps:
00 05 10 15 20 25 30 34 38 42 46 50 54 58 62 66 70 ... \_________________/\_____________________________/ 24 fps sequence 30 fps sequence
If your frames don't come in on any regular interval, but at completly random times (supposedly some webcam devices are random..) then you can just set a timebase of 1/1000 or something and use timestamps in milliseconds taken from the actual (system clock) times at which you sampled the frames.
Mmm... very interesting. Perhaps I'm starting to understand better some things... ( only perhaps ;-P ) BTW tnx Rich ! Last time I ask your help ( in this thread :) , perhaps2 :) ) but it's important to me... For example... - I start to writing the new movie ... // AVStream *video_st c = video_st->codec; c->time_base.num = 1; c->time_base.den = 1000; ... - 30 sec's loop. I write each frame in the movie ... // Encode frame data... out_size = avcodec_encode_video( ... ); // Set the timestamps... for every single frame? How...? if( out_size > 0 ) { AVPacket pkt; av_init_packet( &pkt ); pkt.pts = av_rescale_q( c->coded_frame->pts, c->time_base, vo->video_st->time_base ); if( c->coded_frame->key_frame ) pkt.flags |= PKT_FLAG_KEY; pkt.stream_index = vo->video_st->index; pkt.data = vo->video_outbuf; pkt.size = out_size; // write the compressed frame in the media file ret = av_write_frame( vo->oc, &pkt ); } else ret = 0; ... - I close the movie
For example... - I start to writing the new movie ... // AVStream *video_st c = video_st->codec; c->time_base.num = 1; c->time_base.den = 1000; ... - 30 sec's loop. I write each frame in the movie ... // Encode frame data... out_size = avcodec_encode_video( ... ); // Set the timestamps... for every single frame? How...? if( out_size > 0 ) { AVPacket pkt; av_init_packet( &pkt );
pkt.pts = av_rescale_q( c->coded_frame->pts, c->time_base, vo->video_st->time_base ); if( c->coded_frame->key_frame ) pkt.flags |= PKT_FLAG_KEY; pkt.stream_index = vo->video_st->index; pkt.data = vo->video_outbuf; pkt.size = out_size;
// write the compressed frame in the media file ret = av_write_frame( vo->oc, &pkt ); } else ret = 0; ... - I close the movie
Rich! I think I'm near... but I need help. I have a var ( int64_t i64TimeStamp ) Webcam framerate = 2 fps - I create a new movie: timebase: 1 / 1000 i64TimeStamp = 0 - In the 30 sec's loop I do: i64TimeStamp += 500 pkt.pts = i64TimeStamp writeframe() - I close the movie So I should get the timestamps: [sec 1] 0, 500 [sec 2] 1000, 1500 [sec 3] 1500, 2000 ... But... I get a single movie of 1 sec compressed! ARGH :) Help me plz...
participants (5)
-
dalias@aerifal.cx -
David.Jonsson@tii.se -
mbardiaux@mediaxim.be -
michaelni@gmx.at -
roccoberton@belcom.it