Browse Source

mux/nut: factorize ff_choose_timebase() out of nut

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
tags/n1.1
Michael Niedermayer 13 years ago
parent
commit
de707bc8bd
3 changed files with 28 additions and 5 deletions
  1. +8
    -0
      libavformat/internal.h
  2. +19
    -0
      libavformat/mux.c
  3. +1
    -5
      libavformat/nutenc.c

+ 8
- 0
libavformat/internal.h View File

@@ -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 */

+ 19
- 0
libavformat/mux.c View File

@@ -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)
{


+ 1
- 5
libavformat/nutenc.c View File

@@ -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…
Cancel
Save