Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mpc-hc/FFmpeg.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorerankor <eran.kornblau@kaltura.com>2017-05-03 11:50:15 +0300
committerMichael Niedermayer <michael@niedermayer.cc>2017-05-10 15:00:20 +0300
commit2b06f2d2e24ccc4098f3ab40efd68e8f3f02b273 (patch)
tree2257e48c62074ecf19683c90221f03664f6c29be /ffmpeg.c
parent6ce57fb3c2ef139bbe164d1811422b91e2dedc26 (diff)
ffmpeg: add enc_time_base option
add a per-stream option for setting the encoder timebase. the following values are allowed: 0 - for video, use 1/frame_rate, for audio use 1/sample_rate (this is the default) -1 - match the input timebase (when possible) >0 - set the timebase to provided number Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
Diffstat (limited to 'ffmpeg.c')
-rw-r--r--ffmpeg.c31
1 files changed, 29 insertions, 2 deletions
diff --git a/ffmpeg.c b/ffmpeg.c
index e798d92277..76bf008c73 100644
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -3234,6 +3234,30 @@ static void parse_forced_key_frames(char *kf, OutputStream *ost,
ost->forced_kf_pts = pts;
}
+static void init_encoder_time_base(OutputStream *ost, AVRational default_time_base)
+{
+ InputStream *ist = get_input_stream(ost);
+ AVCodecContext *enc_ctx = ost->enc_ctx;
+ AVFormatContext *oc;
+
+ if (ost->enc_timebase.num > 0) {
+ enc_ctx->time_base = ost->enc_timebase;
+ return;
+ }
+
+ if (ost->enc_timebase.num < 0) {
+ if (ist) {
+ enc_ctx->time_base = ist->st->time_base;
+ return;
+ }
+
+ oc = output_files[ost->file_index]->ctx;
+ av_log(oc, AV_LOG_WARNING, "Input stream data not available, using default time base\n");
+ }
+
+ enc_ctx->time_base = default_time_base;
+}
+
static int init_output_stream_encode(OutputStream *ost)
{
InputStream *ist = get_input_stream(ost);
@@ -3304,10 +3328,13 @@ static int init_output_stream_encode(OutputStream *ost)
enc_ctx->sample_rate = av_buffersink_get_sample_rate(ost->filter->filter);
enc_ctx->channel_layout = av_buffersink_get_channel_layout(ost->filter->filter);
enc_ctx->channels = av_buffersink_get_channels(ost->filter->filter);
- enc_ctx->time_base = (AVRational){ 1, enc_ctx->sample_rate };
+
+ init_encoder_time_base(ost, av_make_q(1, enc_ctx->sample_rate));
break;
+
case AVMEDIA_TYPE_VIDEO:
- enc_ctx->time_base = av_inv_q(ost->frame_rate);
+ init_encoder_time_base(ost, av_inv_q(ost->frame_rate));
+
if (!(enc_ctx->time_base.num && enc_ctx->time_base.den))
enc_ctx->time_base = av_buffersink_get_time_base(ost->filter->filter);
if ( av_q2d(enc_ctx->time_base) < 0.001 && video_sync_method != VSYNC_PASSTHROUGH