| 4115 | } |
| 4116 | |
| 4117 | static int seek_to_start(InputFile *ifile, AVFormatContext *is) |
| 4118 | { |
| 4119 | InputStream *ist; |
| 4120 | AVCodecContext *avctx; |
| 4121 | int i, ret, has_audio = 0; |
| 4122 | int64_t duration = 0; |
| 4123 | |
| 4124 | ret = av_seek_frame(is, -1, is->start_time, 0); |
| 4125 | if (ret < 0) |
| 4126 | return ret; |
| 4127 | |
| 4128 | for (i = 0; i < ifile->nb_streams; i++) { |
| 4129 | ist = input_streams[ifile->ist_index + i]; |
| 4130 | avctx = ist->dec_ctx; |
| 4131 | |
| 4132 | // flush decoders |
| 4133 | if (ist->decoding_needed) { |
| 4134 | process_input_packet(ist, NULL, 1); |
| 4135 | avcodec_flush_buffers(avctx); |
| 4136 | } |
| 4137 | |
| 4138 | /* duration is the length of the last frame in a stream |
| 4139 | * when audio stream is present we don't care about |
| 4140 | * last video frame length because it's not defined exactly */ |
| 4141 | if (avctx->codec_type == AVMEDIA_TYPE_AUDIO && ist->nb_samples) |
| 4142 | has_audio = 1; |
| 4143 | } |
| 4144 | |
| 4145 | for (i = 0; i < ifile->nb_streams; i++) { |
| 4146 | ist = input_streams[ifile->ist_index + i]; |
| 4147 | avctx = ist->dec_ctx; |
| 4148 | |
| 4149 | if (has_audio) { |
| 4150 | if (avctx->codec_type == AVMEDIA_TYPE_AUDIO && ist->nb_samples) { |
| 4151 | AVRational sample_rate = {1, avctx->sample_rate}; |
| 4152 | |
| 4153 | duration = av_rescale_q(ist->nb_samples, sample_rate, ist->st->time_base); |
| 4154 | } else |
| 4155 | continue; |
| 4156 | } else { |
| 4157 | if (ist->framerate.num) { |
| 4158 | duration = av_rescale_q(1, ist->framerate, ist->st->time_base); |
| 4159 | } else if (ist->st->avg_frame_rate.num) { |
| 4160 | duration = av_rescale_q(1, ist->st->avg_frame_rate, ist->st->time_base); |
| 4161 | } else duration = 1; |
| 4162 | } |
| 4163 | if (!ifile->duration) |
| 4164 | ifile->time_base = ist->st->time_base; |
| 4165 | /* the total duration of the stream, max_pts - min_pts is |
| 4166 | * the duration of the stream without the last frame */ |
| 4167 | duration += ist->max_pts - ist->min_pts; |
| 4168 | ifile->time_base = duration_max(duration, &ifile->duration, ist->st->time_base, |
| 4169 | ifile->time_base); |
| 4170 | } |
| 4171 | |
| 4172 | if (ifile->loop > 0) |
| 4173 | ifile->loop--; |
| 4174 |
no test coverage detected