Originally committed as revision 17630 to svn://svn.ffmpeg.org/ffmpeg/trunk
Michael Niedermayer authored on 2009/02/27 08:47:32... | ... |
@@ -1261,7 +1261,7 @@ static int output_packet(AVInputStream *ist, int ist_index, |
1261 | 1261 |
goto discard_packet; |
1262 | 1262 |
} |
1263 | 1263 |
if (ist->st->codec->time_base.num != 0) { |
1264 |
- int ticks= ist->st->parser ? ist->st->parser->repeat_pict+1 : 1; |
|
1264 |
+ int ticks= ist->st->parser ? ist->st->parser->repeat_pict+1 : ist->st->codec->ticks_per_frame; |
|
1265 | 1265 |
ist->next_pts += ((int64_t)AV_TIME_BASE * |
1266 | 1266 |
ist->st->codec->time_base.num * ticks) / |
1267 | 1267 |
ist->st->codec->time_base.den; |
... | ... |
@@ -1290,7 +1290,7 @@ static int output_packet(AVInputStream *ist, int ist_index, |
1290 | 1290 |
break; |
1291 | 1291 |
case CODEC_TYPE_VIDEO: |
1292 | 1292 |
if (ist->st->codec->time_base.num != 0) { |
1293 |
- int ticks= ist->st->parser ? ist->st->parser->repeat_pict+1 : 1; |
|
1293 |
+ int ticks= ist->st->parser ? ist->st->parser->repeat_pict+1 : ist->st->codec->ticks_per_frame; |
|
1294 | 1294 |
ist->next_pts += ((int64_t)AV_TIME_BASE * |
1295 | 1295 |
ist->st->codec->time_base.num * ticks) / |
1296 | 1296 |
ist->st->codec->time_base.den; |
... | ... |
@@ -1750,9 +1750,10 @@ static int av_encode(AVFormatContext **output_files, |
1750 | 1750 |
codec->bit_rate = icodec->bit_rate; |
1751 | 1751 |
codec->extradata= icodec->extradata; |
1752 | 1752 |
codec->extradata_size= icodec->extradata_size; |
1753 |
- if(av_q2d(icodec->time_base) > av_q2d(ist->st->time_base) && av_q2d(ist->st->time_base) < 1.0/1000) |
|
1753 |
+ if(av_q2d(icodec->time_base)*icodec->ticks_per_frame > av_q2d(ist->st->time_base) && av_q2d(ist->st->time_base) < 1.0/1000){ |
|
1754 | 1754 |
codec->time_base = icodec->time_base; |
1755 |
- else |
|
1755 |
+ codec->time_base.num *= icodec->ticks_per_frame; |
|
1756 |
+ }else |
|
1756 | 1757 |
codec->time_base = ist->st->time_base; |
1757 | 1758 |
switch(codec->codec_type) { |
1758 | 1759 |
case CODEC_TYPE_AUDIO: |
... | ... |
@@ -30,7 +30,7 @@ |
30 | 30 |
#include "libavutil/avutil.h" |
31 | 31 |
|
32 | 32 |
#define LIBAVCODEC_VERSION_MAJOR 52 |
33 |
-#define LIBAVCODEC_VERSION_MINOR 19 |
|
33 |
+#define LIBAVCODEC_VERSION_MINOR 20 |
|
34 | 34 |
#define LIBAVCODEC_VERSION_MICRO 0 |
35 | 35 |
|
36 | 36 |
#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ |
... | ... |
@@ -2323,6 +2323,15 @@ typedef struct AVCodecContext { |
2323 | 2323 |
* - decoding: Set by libavcodec |
2324 | 2324 |
*/ |
2325 | 2325 |
struct AVHWAccel *hwaccel; |
2326 |
+ |
|
2327 |
+ /** |
|
2328 |
+ * For some codecs, the time base is closer to the field rate than the frame rate. |
|
2329 |
+ * Most notably, H.264 and MPEG-2 specify time_base as half of frame duration |
|
2330 |
+ * if no telecine is used ... |
|
2331 |
+ * |
|
2332 |
+ * Set to time_base ticks per frame. Default 1, e.g., H.264/MPEG-2 set it to 2. |
|
2333 |
+ */ |
|
2334 |
+ int ticks_per_frame; |
|
2326 | 2335 |
} AVCodecContext; |
2327 | 2336 |
|
2328 | 2337 |
/** |
... | ... |
@@ -1269,7 +1269,7 @@ static int mpeg_decode_postinit(AVCodecContext *avctx){ |
1269 | 1269 |
//MPEG-1 aspect |
1270 | 1270 |
avctx->sample_aspect_ratio= av_d2q( |
1271 | 1271 |
1.0/ff_mpeg1_aspect[s->aspect_ratio_info], 255); |
1272 |
- |
|
1272 |
+ avctx->ticks_per_frame=1; |
|
1273 | 1273 |
}else{//MPEG-2 |
1274 | 1274 |
//MPEG-2 fps |
1275 | 1275 |
av_reduce( |
... | ... |
@@ -1278,6 +1278,7 @@ static int mpeg_decode_postinit(AVCodecContext *avctx){ |
1278 | 1278 |
ff_frame_rate_tab[s->frame_rate_index].num * s1->frame_rate_ext.num*2, |
1279 | 1279 |
ff_frame_rate_tab[s->frame_rate_index].den * s1->frame_rate_ext.den, |
1280 | 1280 |
1<<30); |
1281 |
+ avctx->ticks_per_frame=2; |
|
1281 | 1282 |
//MPEG-2 aspect |
1282 | 1283 |
if(s->aspect_ratio_info > 1){ |
1283 | 1284 |
//we ignore the spec here as reality does not match the spec, see for example |
... | ... |
@@ -393,6 +393,7 @@ static const AVOption options[]={ |
393 | 393 |
{"request_channel_layout", NULL, OFFSET(request_channel_layout), FF_OPT_TYPE_INT64, DEFAULT, 0, INT64_MAX, A|D, "request_channel_layout"}, |
394 | 394 |
{"rc_max_vbv_use", NULL, OFFSET(rc_max_available_vbv_use), FF_OPT_TYPE_FLOAT, 1.0/3, 0.0, FLT_MAX, V|E}, |
395 | 395 |
{"rc_min_vbv_use", NULL, OFFSET(rc_min_vbv_overflow_use), FF_OPT_TYPE_FLOAT, 3, 0.0, FLT_MAX, V|E}, |
396 |
+{"ticks_per_frame", NULL, OFFSET(ticks_per_frame), FF_OPT_TYPE_INT, 1, 1, INT_MAX, A|V|E|D}, |
|
396 | 397 |
{NULL}, |
397 | 398 |
}; |
398 | 399 |
|
... | ... |
@@ -2201,9 +2201,9 @@ int av_find_stream_info(AVFormatContext *ic) |
2201 | 2201 |
|
2202 | 2202 |
if (!st->r_frame_rate.num){ |
2203 | 2203 |
if( st->codec->time_base.den * (int64_t)st->time_base.num |
2204 |
- <= st->codec->time_base.num * (int64_t)st->time_base.den){ |
|
2204 |
+ <= st->codec->time_base.num * st->codec->ticks_per_frame * (int64_t)st->time_base.den){ |
|
2205 | 2205 |
st->r_frame_rate.num = st->codec->time_base.den; |
2206 |
- st->r_frame_rate.den = st->codec->time_base.num; |
|
2206 |
+ st->r_frame_rate.den = st->codec->time_base.num * st->codec->ticks_per_frame; |
|
2207 | 2207 |
}else{ |
2208 | 2208 |
st->r_frame_rate.num = st->time_base.den; |
2209 | 2209 |
st->r_frame_rate.den = st->time_base.num; |
... | ... |
@@ -2537,7 +2537,7 @@ static int compute_pkt_fields2(AVStream *st, AVPacket *pkt){ |
2537 | 2537 |
if (pkt->duration == 0) { |
2538 | 2538 |
compute_frame_duration(&num, &den, st, NULL, pkt); |
2539 | 2539 |
if (den && num) { |
2540 |
- pkt->duration = av_rescale(1, num * (int64_t)st->time_base.den, den * (int64_t)st->time_base.num); |
|
2540 |
+ pkt->duration = av_rescale(1, num * (int64_t)st->time_base.den * st->codec->ticks_per_frame, den * (int64_t)st->time_base.num); |
|
2541 | 2541 |
} |
2542 | 2542 |
} |
2543 | 2543 |
|