mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2024-11-21 10:55:51 +02:00
mux/nut: factorize ff_choose_timebase() out of nut
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
This commit is contained in:
parent
05e5a24f79
commit
de707bc8bd
@ -354,5 +354,13 @@ void ff_compute_frame_duration(int *pnum, int *pden, AVStream *st,
|
||||
|
||||
int ff_get_audio_frame_size(AVCodecContext *enc, int size, int mux);
|
||||
|
||||
/**
|
||||
* Chooses a timebase for muxing the specified stream.
|
||||
*
|
||||
* The choosen timebase allows sample accurate timestamps based
|
||||
* on the framerate or sample rate for audio streams. It also is
|
||||
* at least as precisse as 1/min_precission would be.
|
||||
*/
|
||||
AVRational ff_choose_timebase(AVFormatContext *s, AVStream *st, int min_precission);
|
||||
|
||||
#endif /* AVFORMAT_INTERNAL_H */
|
||||
|
@ -103,6 +103,25 @@ static void frac_add(AVFrac *f, int64_t incr)
|
||||
f->num = num;
|
||||
}
|
||||
|
||||
AVRational ff_choose_timebase(AVFormatContext *s, AVStream *st, int min_precission)
|
||||
{
|
||||
AVRational q;
|
||||
int j;
|
||||
|
||||
if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
|
||||
q = (AVRational){1, st->codec->sample_rate};
|
||||
} else {
|
||||
q = st->codec->time_base;
|
||||
}
|
||||
for (j=2; j<2000; j+= 1+(j>2))
|
||||
while (q.den / q.num < min_precission && q.num % j == 0)
|
||||
q.num /= j;
|
||||
while (q.den / q.num < min_precission && q.den < (1<<24))
|
||||
q.den <<= 1;
|
||||
|
||||
return q;
|
||||
}
|
||||
|
||||
int avformat_alloc_output_context2(AVFormatContext **avctx, AVOutputFormat *oformat,
|
||||
const char *format, const char *filename)
|
||||
{
|
||||
|
@ -676,11 +676,7 @@ static int nut_write_header(AVFormatContext *s){
|
||||
if(st->codec->codec_type == AVMEDIA_TYPE_AUDIO && st->codec->sample_rate) {
|
||||
time_base = (AVRational){1, st->codec->sample_rate};
|
||||
} else {
|
||||
for (j=2; j<2000; j+= 1+(j>2))
|
||||
while (time_base.den / time_base.num < 48000 && time_base.num % j == 0)
|
||||
time_base.num /= j;
|
||||
while (time_base.den / time_base.num < 48000 && time_base.den < (1<<24))
|
||||
time_base.den <<= 1;
|
||||
time_base = ff_choose_timebase(s, st, 48000);
|
||||
}
|
||||
|
||||
avpriv_set_pts_info(st, 64, time_base.num, time_base.den);
|
||||
|
Loading…
Reference in New Issue
Block a user