summaryrefslogtreecommitdiff
path: root/libavformat
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2012-10-03 21:34:43 +0200
committerMichael Niedermayer <michaelni@gmx.at>2012-10-03 21:34:43 +0200
commitde707bc8bdfff92a1905169ba6054034d464dbb5 (patch)
tree4115aae2f3c5172d91d752c157e2a76be43c345c /libavformat
parent05e5a24f79fedc36a1addf8a8ed36e9ad5c42d8c (diff)
mux/nut: factorize ff_choose_timebase() out of nut
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavformat')
-rw-r--r--libavformat/internal.h8
-rw-r--r--libavformat/mux.c19
-rw-r--r--libavformat/nutenc.c6
3 files changed, 28 insertions, 5 deletions
diff --git a/libavformat/internal.h b/libavformat/internal.h
index 402e155e86..2689b2f48c 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 debc6a16b9..cd5481f1d2 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 1402634442..ccd6cb1800 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);