[FFmpeg-cvslog] mux/nut: factorize ff_choose_timebase() out of nut
Michael Niedermayer
git at videolan.org
Wed Oct 3 22:17:57 CEST 2012
ffmpeg | branch: master | Michael Niedermayer <michaelni at gmx.at> | Wed Oct 3 21:34:43 2012 +0200| [de707bc8bdfff92a1905169ba6054034d464dbb5] | committer: Michael Niedermayer
mux/nut: factorize ff_choose_timebase() out of nut
Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=de707bc8bdfff92a1905169ba6054034d464dbb5
---
libavformat/internal.h | 8 ++++++++
libavformat/mux.c | 19 +++++++++++++++++++
libavformat/nutenc.c | 6 +-----
3 files changed, 28 insertions(+), 5 deletions(-)
diff --git a/libavformat/internal.h b/libavformat/internal.h
index 402e155..2689b2f 100644
--- a/libavformat/internal.h
+++ b/libavformat/internal.h
@@ -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 */
diff --git a/libavformat/mux.c b/libavformat/mux.c
index debc6a1..cd5481f 100644
--- a/libavformat/mux.c
+++ b/libavformat/mux.c
@@ -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)
{
diff --git a/libavformat/nutenc.c b/libavformat/nutenc.c
index 1402634..ccd6cb1 100644
--- a/libavformat/nutenc.c
+++ b/libavformat/nutenc.c
@@ -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);
More information about the ffmpeg-cvslog
mailing list