Commit 504ee036 authored by Michael Niedermayer's avatar Michael Niedermayer

fix b pyramid in mp4 muxing if no dts are provided to the muxer

Originally committed as revision 6133 to svn://svn.ffmpeg.org/ffmpeg/trunk
parent 56d2d2d0
...@@ -160,6 +160,7 @@ X264_init(AVCodecContext *avctx) ...@@ -160,6 +160,7 @@ X264_init(AVCodecContext *avctx)
x4->params.b_bframe_adaptive = avctx->b_frame_strategy; x4->params.b_bframe_adaptive = avctx->b_frame_strategy;
x4->params.i_bframe_bias = avctx->bframebias; x4->params.i_bframe_bias = avctx->bframebias;
x4->params.b_bframe_pyramid = (avctx->flags2 & CODEC_FLAG2_BPYRAMID); x4->params.b_bframe_pyramid = (avctx->flags2 & CODEC_FLAG2_BPYRAMID);
avctx->has_b_frames= (avctx->flags2 & CODEC_FLAG2_BPYRAMID) ? 2 : !!avctx->max_b_frames;
x4->params.i_keyint_min = avctx->keyint_min; x4->params.i_keyint_min = avctx->keyint_min;
if(x4->params.i_keyint_min > x4->params.i_keyint_max) if(x4->params.i_keyint_min > x4->params.i_keyint_max)
......
...@@ -266,6 +266,9 @@ typedef struct AVStream { ...@@ -266,6 +266,9 @@ typedef struct AVStream {
int index_entries_allocated_size; int index_entries_allocated_size;
int64_t nb_frames; ///< number of frames in this stream if known or 0 int64_t nb_frames; ///< number of frames in this stream if known or 0
#define MAX_REORDER_DELAY 4
int64_t pts_buffer[MAX_REORDER_DELAY+1];
} AVStream; } AVStream;
#define AVFMTCTX_NOHEADER 0x0001 /* signal that no header is present #define AVFMTCTX_NOHEADER 0x0001 /* signal that no header is present
......
...@@ -2213,6 +2213,7 @@ void av_close_input_file(AVFormatContext *s) ...@@ -2213,6 +2213,7 @@ void av_close_input_file(AVFormatContext *s)
AVStream *av_new_stream(AVFormatContext *s, int id) AVStream *av_new_stream(AVFormatContext *s, int id)
{ {
AVStream *st; AVStream *st;
int i;
if (s->nb_streams >= MAX_STREAMS) if (s->nb_streams >= MAX_STREAMS)
return NULL; return NULL;
...@@ -2235,6 +2236,8 @@ AVStream *av_new_stream(AVFormatContext *s, int id) ...@@ -2235,6 +2236,8 @@ AVStream *av_new_stream(AVFormatContext *s, int id)
/* default pts settings is MPEG like */ /* default pts settings is MPEG like */
av_set_pts_info(st, 33, 1, 90000); av_set_pts_info(st, 33, 1, 90000);
st->last_IP_pts = AV_NOPTS_VALUE; st->last_IP_pts = AV_NOPTS_VALUE;
for(i=0; i<MAX_REORDER_DELAY+1; i++)
st->pts_buffer[i]= AV_NOPTS_VALUE;
s->streams[s->nb_streams++] = st; s->streams[s->nb_streams++] = st;
return st; return st;
...@@ -2330,10 +2333,10 @@ int av_write_header(AVFormatContext *s) ...@@ -2330,10 +2333,10 @@ int av_write_header(AVFormatContext *s)
//FIXME merge with compute_pkt_fields //FIXME merge with compute_pkt_fields
static int compute_pkt_fields2(AVStream *st, AVPacket *pkt){ static int compute_pkt_fields2(AVStream *st, AVPacket *pkt){
int b_frames = FFMAX(st->codec->has_b_frames, st->codec->max_b_frames); int delay = FFMAX(st->codec->has_b_frames, !!st->codec->max_b_frames);
int num, den, frame_size; int num, den, frame_size, i;
// av_log(NULL, AV_LOG_DEBUG, "av_write_frame: pts:%lld dts:%lld cur_dts:%lld b:%d size:%d st:%d\n", pkt->pts, pkt->dts, st->cur_dts, b_frames, pkt->size, pkt->stream_index); // av_log(NULL, AV_LOG_DEBUG, "av_write_frame: pts:%lld dts:%lld cur_dts:%lld b:%d size:%d st:%d\n", pkt->pts, pkt->dts, st->cur_dts, delay, pkt->size, pkt->stream_index);
/* if(pkt->pts == AV_NOPTS_VALUE && pkt->dts == AV_NOPTS_VALUE) /* if(pkt->pts == AV_NOPTS_VALUE && pkt->dts == AV_NOPTS_VALUE)
return -1;*/ return -1;*/
...@@ -2347,7 +2350,7 @@ static int compute_pkt_fields2(AVStream *st, AVPacket *pkt){ ...@@ -2347,7 +2350,7 @@ static int compute_pkt_fields2(AVStream *st, AVPacket *pkt){
} }
//XXX/FIXME this is a temporary hack until all encoders output pts //XXX/FIXME this is a temporary hack until all encoders output pts
if((pkt->pts == 0 || pkt->pts == AV_NOPTS_VALUE) && pkt->dts == AV_NOPTS_VALUE && !b_frames){ if((pkt->pts == 0 || pkt->pts == AV_NOPTS_VALUE) && pkt->dts == AV_NOPTS_VALUE && !delay){
pkt->dts= pkt->dts=
// pkt->pts= st->cur_dts; // pkt->pts= st->cur_dts;
pkt->pts= st->pts.val; pkt->pts= st->pts.val;
...@@ -2355,17 +2358,13 @@ static int compute_pkt_fields2(AVStream *st, AVPacket *pkt){ ...@@ -2355,17 +2358,13 @@ static int compute_pkt_fields2(AVStream *st, AVPacket *pkt){
//calculate dts from pts //calculate dts from pts
if(pkt->pts != AV_NOPTS_VALUE && pkt->dts == AV_NOPTS_VALUE){ if(pkt->pts != AV_NOPTS_VALUE && pkt->dts == AV_NOPTS_VALUE){
if(b_frames){ st->pts_buffer[0]= pkt->pts;
if(st->last_IP_pts == AV_NOPTS_VALUE){ for(i=1; i<delay+1 && st->pts_buffer[i] == AV_NOPTS_VALUE; i++)
st->last_IP_pts= -pkt->duration; st->pts_buffer[i]= (i-delay-1) * pkt->duration;
} for(i=0; i<delay && st->pts_buffer[i] > st->pts_buffer[i+1]; i++)
if(st->last_IP_pts < pkt->pts){ SWAP(int64_t, st->pts_buffer[i], st->pts_buffer[i+1]);
pkt->dts= st->last_IP_pts;
st->last_IP_pts= pkt->pts; pkt->dts= st->pts_buffer[0];
}else
pkt->dts= pkt->pts;
}else
pkt->dts= pkt->pts;
} }
if(st->cur_dts && st->cur_dts != AV_NOPTS_VALUE && st->cur_dts >= pkt->dts){ if(st->cur_dts && st->cur_dts != AV_NOPTS_VALUE && st->cur_dts >= pkt->dts){
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment