#include "libavutil/channel_layout.h"
#include "libavutil/parseutils.h"
#include "libavutil/samplefmt.h"
-#include "libavutil/colorspace.h"
#include "libavutil/fifo.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/dict.h"
/* close files */
for (i = 0; i < nb_output_files; i++) {
AVFormatContext *s = output_files[i]->ctx;
- if (s && !(s->oformat->flags & AVFMT_NOFILE) && s->pb)
+ if (s && s->oformat && !(s->oformat->flags & AVFMT_NOFILE) && s->pb)
avio_close(s->pb);
avformat_free_context(s);
av_dict_free(&output_files[i]->opts);
{
OutputFile *of = output_files[ost->file_index];
int64_t ost_tb_start_time = av_rescale_q(of->start_time, AV_TIME_BASE_Q, ost->st->time_base);
+ int64_t ist_tb_start_time = av_rescale_q(of->start_time, AV_TIME_BASE_Q, ist->st->time_base);
AVPicture pict;
AVPacket opkt;
!ost->copy_initial_nonkeyframes)
return;
- if (!ost->frame_number && ist->pts < of->start_time &&
- !ost->copy_prior_start)
- return;
+ if (pkt->pts == AV_NOPTS_VALUE) {
+ if (!ost->frame_number && ist->pts < of->start_time &&
+ !ost->copy_prior_start)
+ return;
+ } else {
+ if (!ost->frame_number && pkt->pts < ist_tb_start_time &&
+ !ost->copy_prior_start)
+ return;
+ }
if (of->recording_time != INT64_MAX &&
ist->pts >= of->recording_time + of->start_time) {
f = decoded_frame;
err = av_buffersrc_add_frame_flags(ist->filters[i]->filter, f,
AV_BUFFERSRC_FLAG_PUSH);
+ if (err == AVERROR_EOF)
+ err = 0; /* ignore */
if (err < 0)
break;
}
} else
f = decoded_frame;
ret = av_buffersrc_add_frame_flags(ist->filters[i]->filter, f, AV_BUFFERSRC_FLAG_PUSH);
- if (ret < 0) {
+ if (ret == AVERROR_EOF) {
+ ret = 0; /* ignore */
+ } else if (ret < 0) {
av_log(NULL, AV_LOG_FATAL,
"Failed to inject frame into filter network: %s\n", av_err2str(ret));
exit(1);
if (!av_dict_get(ist->opts, "threads", NULL, 0))
av_dict_set(&ist->opts, "threads", "auto", 0);
if ((ret = avcodec_open2(ist->st->codec, codec, &ist->opts)) < 0) {
+ char errbuf[128];
if (ret == AVERROR_EXPERIMENTAL)
abort_codec_experimental(codec, 0);
- snprintf(error, error_len, "Error while opening decoder for input stream #%d:%d",
- ist->file_index, ist->st->index);
+
+ av_strerror(ret, errbuf, sizeof(errbuf));
+
+ snprintf(error, error_len,
+ "Error while opening decoder for input stream "
+ "#%d:%d : %s",
+ ist->file_index, ist->st->index, errbuf);
return ret;
}
assert_avoptions(ist->opts);
}
if (ost->stream_copy) {
+ AVRational sar;
uint64_t extra_size;
av_assert0(ist && !ost->filter);
codec->height = icodec->height;
codec->has_b_frames = icodec->has_b_frames;
if (ost->frame_aspect_ratio.num) { // overridden by the -aspect cli option
- codec->sample_aspect_ratio =
- ost->st->sample_aspect_ratio =
+ sar =
av_mul_q(ost->frame_aspect_ratio,
(AVRational){ codec->height, codec->width });
av_log(NULL, AV_LOG_WARNING, "Overriding aspect ratio "
"with stream copy may produce invalid files\n");
- } else if (!codec->sample_aspect_ratio.num) {
- codec->sample_aspect_ratio =
- ost->st->sample_aspect_ratio =
- ist->st->sample_aspect_ratio.num ? ist->st->sample_aspect_ratio :
- ist->st->codec->sample_aspect_ratio.num ?
- ist->st->codec->sample_aspect_ratio : (AVRational){0, 1};
}
+ else if (ist->st->sample_aspect_ratio.num)
+ sar = ist->st->sample_aspect_ratio;
+ else
+ sar = icodec->sample_aspect_ratio;
+ ost->st->sample_aspect_ratio = codec->sample_aspect_ratio = sar;
ost->st->avg_frame_rate = ist->st->avg_frame_rate;
break;
case AVMEDIA_TYPE_SUBTITLE:
oc->interrupt_callback = int_cb;
if ((ret = avformat_write_header(oc, &output_files[i]->opts)) < 0) {
char errbuf[128];
- const char *errbuf_ptr = errbuf;
- if (av_strerror(ret, errbuf, sizeof(errbuf)) < 0)
- errbuf_ptr = strerror(AVUNERROR(ret));
- snprintf(error, sizeof(error), "Could not write header for output file #%d (incorrect codec parameters ?): %s", i, errbuf_ptr);
+ av_strerror(ret, errbuf, sizeof(errbuf));
+ snprintf(error, sizeof(error),
+ "Could not write header for output file #%d "
+ "(incorrect codec parameters ?): %s",
+ i, errbuf);
ret = AVERROR(EINVAL);
goto dump_format;
}