X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=ffmpeg.c;h=55b5f865c79114917d1a62de16a5d7820bb269cd;hb=45eed9b197511e3c9c5d6235cedf744932c2407b;hp=0c98fb7c6bbb7050076b6fc4ad7ee1b6bc045f4a;hpb=3d52083a274eaf92b1ef4c6e607e03374647a8c7;p=ffmpeg diff --git a/ffmpeg.c b/ffmpeg.c index 0c98fb7c6bb..55b5f865c79 100644 --- a/ffmpeg.c +++ b/ffmpeg.c @@ -846,6 +846,10 @@ static void do_video_out(AVFormatContext *s, method. */ enc->coded_frame->interlaced_frame = in_picture->interlaced_frame; enc->coded_frame->top_field_first = in_picture->top_field_first; + if (enc->coded_frame->interlaced_frame) + enc->field_order = enc->coded_frame->top_field_first ? AV_FIELD_TB:AV_FIELD_BT; + else + enc->field_order = AV_FIELD_PROGRESSIVE; pkt.data = (uint8_t *)in_picture; pkt.size = sizeof(AVPicture); pkt.pts = av_rescale_q(in_picture->pts, enc->time_base, ost->st->time_base); @@ -868,6 +872,14 @@ static void do_video_out(AVFormatContext *s, big_picture.top_field_first = !!ost->top_field_first; } + if (big_picture.interlaced_frame) { + if (enc->codec->id == AV_CODEC_ID_MJPEG) + enc->field_order = big_picture.top_field_first ? AV_FIELD_TT:AV_FIELD_BB; + else + enc->field_order = big_picture.top_field_first ? AV_FIELD_TB:AV_FIELD_BT; + } else + enc->field_order = AV_FIELD_PROGRESSIVE; + big_picture.quality = ost->st->codec->global_quality; if (!enc->me_threshold) big_picture.pict_type = 0; @@ -965,7 +977,7 @@ static void do_video_stats(OutputStream *ost, int frame_size) } } -/* +/** * Get and encode new output from any of the filtergraphs, without causing * activity. * @@ -2752,18 +2764,39 @@ static int process_input(int file_index) if (debug_ts) { av_log(NULL, AV_LOG_INFO, "demuxer -> ist_index:%d type:%s " - "next_dts:%s next_dts_time:%s next_pts:%s next_pts_time:%s pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s off:%"PRId64"\n", - ifile->ist_index + pkt.stream_index, av_get_media_type_string(ist->st->codec->codec_type), - av_ts2str(ist->next_dts), av_ts2timestr(ist->next_dts, &AV_TIME_BASE_Q), - av_ts2str(ist->next_pts), av_ts2timestr(ist->next_pts, &AV_TIME_BASE_Q), - av_ts2str(pkt.pts), av_ts2timestr(pkt.pts, &ist->st->time_base), - av_ts2str(pkt.dts), av_ts2timestr(pkt.dts, &ist->st->time_base), - input_files[ist->file_index]->ts_offset); - } - - if(!ist->wrap_correction_done && input_files[file_index]->ctx->start_time != AV_NOPTS_VALUE && ist->st->pts_wrap_bits < 64){ - int64_t stime = av_rescale_q(input_files[file_index]->ctx->start_time, AV_TIME_BASE_Q, ist->st->time_base); - int64_t stime2= stime + (1ULL<st->pts_wrap_bits); + "next_dts:%s next_dts_time:%s next_pts:%s next_pts_time:%s pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s off:%s off_time:%s\n", + ifile->ist_index + pkt.stream_index, av_get_media_type_string(ist->st->codec->codec_type), + av_ts2str(ist->next_dts), av_ts2timestr(ist->next_dts, &AV_TIME_BASE_Q), + av_ts2str(ist->next_pts), av_ts2timestr(ist->next_pts, &AV_TIME_BASE_Q), + av_ts2str(pkt.pts), av_ts2timestr(pkt.pts, &ist->st->time_base), + av_ts2str(pkt.dts), av_ts2timestr(pkt.dts, &ist->st->time_base), + av_ts2str(input_files[ist->file_index]->ts_offset), + av_ts2timestr(input_files[ist->file_index]->ts_offset, &AV_TIME_BASE_Q)); + } + + if(!ist->wrap_correction_done && is->start_time != AV_NOPTS_VALUE && ist->st->pts_wrap_bits < 64){ + int64_t stime, stime2; + // Correcting starttime based on the enabled streams + // FIXME this ideally should be done before the first use of starttime but we do not know which are the enabled streams at that point. + // so we instead do it here as part of discontinuity handling + if ( ist->next_dts == AV_NOPTS_VALUE + && ifile->ts_offset == -is->start_time + && (is->iformat->flags & AVFMT_TS_DISCONT)) { + int64_t new_start_time = INT64_MAX; + for (i=0; inb_streams; i++) { + AVStream *st = is->streams[i]; + if(st->discard == AVDISCARD_ALL || st->start_time == AV_NOPTS_VALUE) + continue; + new_start_time = FFMIN(new_start_time, av_rescale_q(st->start_time, st->time_base, AV_TIME_BASE_Q)); + } + if (new_start_time > is->start_time) { + av_log(is, AV_LOG_VERBOSE, "Correcting start time by %"PRId64"\n", new_start_time - is->start_time); + ifile->ts_offset = -new_start_time; + } + } + + stime = av_rescale_q(is->start_time, AV_TIME_BASE_Q, ist->st->time_base); + stime2= stime + (1ULL<st->pts_wrap_bits); ist->wrap_correction_done = 1; if(stime2 > stime && pkt.dts != AV_NOPTS_VALUE && pkt.dts > stime + (1LL<<(ist->st->pts_wrap_bits-1))) { @@ -2824,11 +2857,12 @@ static int process_input(int file_index) } if (debug_ts) { - av_log(NULL, AV_LOG_INFO, "demuxer+ffmpeg -> ist_index:%d type:%s pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s off:%"PRId64"\n", - ifile->ist_index + pkt.stream_index, av_get_media_type_string(ist->st->codec->codec_type), - av_ts2str(pkt.pts), av_ts2timestr(pkt.pts, &ist->st->time_base), - av_ts2str(pkt.dts), av_ts2timestr(pkt.dts, &ist->st->time_base), - input_files[ist->file_index]->ts_offset); + av_log(NULL, AV_LOG_INFO, "demuxer+ffmpeg -> ist_index:%d type:%s pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s off:%s off_time:%s\n", + ifile->ist_index + pkt.stream_index, av_get_media_type_string(ist->st->codec->codec_type), + av_ts2str(pkt.pts), av_ts2timestr(pkt.pts, &ist->st->time_base), + av_ts2str(pkt.dts), av_ts2timestr(pkt.dts, &ist->st->time_base), + av_ts2str(input_files[ist->file_index]->ts_offset), + av_ts2timestr(input_files[ist->file_index]->ts_offset, &AV_TIME_BASE_Q)); } sub2video_heartbeat(ist, pkt.pts);