if ((ret = init_muxer(s, options)) < 0)
return ret;
- if (!s->oformat->check_bitstream) {
+ if (!(s->oformat->check_bitstream && s->flags & AVFMT_FLAG_AUTO_BSF)) {
ret = write_header_internal(s);
if (ret < 0)
goto fail;
static int write_packet(AVFormatContext *s, AVPacket *pkt)
{
int ret, did_split;
+ int64_t pts_backup, dts_backup;
+
+ pts_backup = pkt->pts;
+ dts_backup = pkt->dts;
if (s->output_ts_offset) {
AVStream *st = s->streams[pkt->stream_index];
if (did_split)
av_packet_merge_side_data(pkt);
+ if (ret < 0) {
+ pkt->pts = pts_backup;
+ pkt->dts = dts_backup;
+ }
+
return ret;
}
AVStream *st = s->streams[pkt->stream_index];
int i, ret;
+ if (!(s->flags & AVFMT_FLAG_AUTO_BSF))
+ return 1;
+
if (s->oformat->check_bitstream) {
if (!st->internal->bitstream_checked) {
if ((ret = s->oformat->check_bitstream(s, pkt)) < 0)
int stream_count = 0;
int noninterleaved_count = 0;
int i, ret;
+ int eof = flush;
if (pkt) {
if ((ret = ff_interleave_add_packet(s, pkt, interleave_compare_dts)) < 0)
}
}
+ if (s->internal->packet_buffer &&
+ eof &&
+ (s->flags & AVFMT_FLAG_SHORTEST) &&
+ s->internal->shortest_end == AV_NOPTS_VALUE) {
+ AVPacket *top_pkt = &s->internal->packet_buffer->pkt;
+
+ s->internal->shortest_end = av_rescale_q(top_pkt->dts,
+ s->streams[top_pkt->stream_index]->time_base,
+ AV_TIME_BASE_Q);
+ }
+
+ if (s->internal->shortest_end != AV_NOPTS_VALUE) {
+ while (s->internal->packet_buffer) {
+ AVPacket *top_pkt = &s->internal->packet_buffer->pkt;
+ AVStream *st;
+ int64_t top_dts = av_rescale_q(top_pkt->dts,
+ s->streams[top_pkt->stream_index]->time_base,
+ AV_TIME_BASE_Q);
+
+ if (s->internal->shortest_end + 1 >= top_dts)
+ break;
+
+ pktl = s->internal->packet_buffer;
+ st = s->streams[pktl->pkt.stream_index];
+
+ s->internal->packet_buffer = pktl->next;
+ if (!s->internal->packet_buffer)
+ s->internal->packet_buffer_end = NULL;
+
+ if (st->last_in_packet_buffer == pktl)
+ st->last_in_packet_buffer = NULL;
+
+ av_packet_unref(&pktl->pkt);
+ av_freep(&pktl);
+ flush = 0;
+ }
+ }
+
if (stream_count && flush) {
AVStream *st;
pktl = s->internal->packet_buffer;