| 1034 | } |
| 1035 | |
| 1036 | static void do_video_out(OutputFile *of, |
| 1037 | OutputStream *ost, |
| 1038 | AVFrame *next_picture, |
| 1039 | double sync_ipts) |
| 1040 | { |
| 1041 | int ret, format_video_sync; |
| 1042 | AVPacket pkt; |
| 1043 | AVCodecContext *enc = ost->enc_ctx; |
| 1044 | AVCodecParameters *mux_par = ost->st->codecpar; |
| 1045 | AVRational frame_rate; |
| 1046 | int nb_frames, nb0_frames, i; |
| 1047 | double delta, delta0; |
| 1048 | double duration = 0; |
| 1049 | int frame_size = 0; |
| 1050 | InputStream *ist = NULL; |
| 1051 | AVFilterContext *filter = ost->filter->filter; |
| 1052 | |
| 1053 | if (ost->source_index >= 0) |
| 1054 | ist = input_streams[ost->source_index]; |
| 1055 | |
| 1056 | frame_rate = av_buffersink_get_frame_rate(filter); |
| 1057 | if (frame_rate.num > 0 && frame_rate.den > 0) |
| 1058 | duration = 1/(av_q2d(frame_rate) * av_q2d(enc->time_base)); |
| 1059 | |
| 1060 | if(ist && ist->st->start_time != AV_NOPTS_VALUE && ist->st->first_dts != AV_NOPTS_VALUE && ost->frame_rate.num) |
| 1061 | duration = FFMIN(duration, 1/(av_q2d(ost->frame_rate) * av_q2d(enc->time_base))); |
| 1062 | |
| 1063 | if (!ost->filters_script && |
| 1064 | !ost->filters && |
| 1065 | next_picture && |
| 1066 | ist && |
| 1067 | lrintf(av_frame_get_pkt_duration(next_picture) * av_q2d(ist->st->time_base) / av_q2d(enc->time_base)) > 0) { |
| 1068 | duration = lrintf(av_frame_get_pkt_duration(next_picture) * av_q2d(ist->st->time_base) / av_q2d(enc->time_base)); |
| 1069 | } |
| 1070 | |
| 1071 | if (!next_picture) { |
| 1072 | //end, flushing |
| 1073 | nb0_frames = nb_frames = mid_pred(ost->last_nb0_frames[0], |
| 1074 | ost->last_nb0_frames[1], |
| 1075 | ost->last_nb0_frames[2]); |
| 1076 | } else { |
| 1077 | delta0 = sync_ipts - ost->sync_opts; // delta0 is the "drift" between the input frame (next_picture) and where it would fall in the output. |
| 1078 | delta = delta0 + duration; |
| 1079 | |
| 1080 | /* by default, we output a single frame */ |
| 1081 | nb0_frames = 0; // tracks the number of times the PREVIOUS frame should be duplicated, mostly for variable framerate (VFR) |
| 1082 | nb_frames = 1; |
| 1083 | |
| 1084 | format_video_sync = video_sync_method; |
| 1085 | if (format_video_sync == VSYNC_AUTO) { |
| 1086 | if(!strcmp(of->ctx->oformat->name, "avi")) { |
| 1087 | format_video_sync = VSYNC_VFR; |
| 1088 | } else |
| 1089 | format_video_sync = (of->ctx->oformat->flags & AVFMT_VARIABLE_FPS) ? ((of->ctx->oformat->flags & AVFMT_NOTIMESTAMPS) ? VSYNC_PASSTHROUGH : VSYNC_VFR) : VSYNC_CFR; |
| 1090 | if ( ist |
| 1091 | && format_video_sync == VSYNC_CFR |
| 1092 | && input_files[ist->file_index]->ctx->nb_streams == 1 |
| 1093 | && input_files[ist->file_index]->input_ts_offset == 0) { |
no test coverage detected