mirror of
https://git.ffmpeg.org/ffmpeg.git
synced 2026-01-06 06:05:32 +01:00
avformat/mux: stop delaying writing the header
Every bitstream filter behaves as intended now, so there's no need to wait for the first packet of every stream. Signed-off-by: James Almer <jamrial@gmail.com>
This commit is contained in:
@@ -458,25 +458,6 @@ static void flush_if_needed(AVFormatContext *s)
|
||||
}
|
||||
}
|
||||
|
||||
static int write_header_internal(AVFormatContext *s)
|
||||
{
|
||||
if (!(s->oformat->flags & AVFMT_NOFILE) && s->pb)
|
||||
avio_write_marker(s->pb, AV_NOPTS_VALUE, AVIO_DATA_MARKER_HEADER);
|
||||
if (s->oformat->write_header) {
|
||||
int ret = s->oformat->write_header(s);
|
||||
if (ret >= 0 && s->pb && s->pb->error < 0)
|
||||
ret = s->pb->error;
|
||||
s->internal->write_header_ret = ret;
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
flush_if_needed(s);
|
||||
}
|
||||
s->internal->header_written = 1;
|
||||
if (!(s->oformat->flags & AVFMT_NOFILE) && s->pb)
|
||||
avio_write_marker(s->pb, AV_NOPTS_VALUE, AVIO_DATA_MARKER_UNKNOWN);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int avformat_init_output(AVFormatContext *s, AVDictionary **options)
|
||||
{
|
||||
int ret = 0;
|
||||
@@ -515,11 +496,18 @@ int avformat_write_header(AVFormatContext *s, AVDictionary **options)
|
||||
if ((ret = avformat_init_output(s, options)) < 0)
|
||||
return ret;
|
||||
|
||||
if (!(s->oformat->check_bitstream && s->flags & AVFMT_FLAG_AUTO_BSF)) {
|
||||
ret = write_header_internal(s);
|
||||
if (!(s->oformat->flags & AVFMT_NOFILE) && s->pb)
|
||||
avio_write_marker(s->pb, AV_NOPTS_VALUE, AVIO_DATA_MARKER_HEADER);
|
||||
if (s->oformat->write_header) {
|
||||
ret = s->oformat->write_header(s);
|
||||
if (ret >= 0 && s->pb && s->pb->error < 0)
|
||||
ret = s->pb->error;
|
||||
if (ret < 0)
|
||||
goto fail;
|
||||
flush_if_needed(s);
|
||||
}
|
||||
if (!(s->oformat->flags & AVFMT_NOFILE) && s->pb)
|
||||
avio_write_marker(s->pb, AV_NOPTS_VALUE, AVIO_DATA_MARKER_UNKNOWN);
|
||||
|
||||
if (!s->internal->streams_initialized) {
|
||||
if ((ret = init_pts(s)) < 0)
|
||||
@@ -739,12 +727,6 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt)
|
||||
}
|
||||
}
|
||||
|
||||
if (!s->internal->header_written) {
|
||||
ret = s->internal->write_header_ret ? s->internal->write_header_ret : write_header_internal(s);
|
||||
if (ret < 0)
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if ((pkt->flags & AV_PKT_FLAG_UNCODED_FRAME)) {
|
||||
AVFrame *frame = (AVFrame *)pkt->data;
|
||||
av_assert0(pkt->size == UNCODED_FRAME_PACKET_SIZE);
|
||||
@@ -760,8 +742,6 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt)
|
||||
ret = s->pb->error;
|
||||
}
|
||||
|
||||
fail:
|
||||
|
||||
if (ret < 0) {
|
||||
pkt->pts = pts_backup;
|
||||
pkt->dts = dts_backup;
|
||||
@@ -894,11 +874,6 @@ int av_write_frame(AVFormatContext *s, AVPacket *pkt)
|
||||
|
||||
if (!pkt) {
|
||||
if (s->oformat->flags & AVFMT_ALLOW_FLUSH) {
|
||||
if (!s->internal->header_written) {
|
||||
ret = s->internal->write_header_ret ? s->internal->write_header_ret : write_header_internal(s);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
}
|
||||
ret = s->oformat->write_packet(s, NULL);
|
||||
flush_if_needed(s);
|
||||
if (ret >= 0 && s->pb && s->pb->error < 0)
|
||||
@@ -1282,14 +1257,8 @@ int av_write_trailer(AVFormatContext *s)
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (!s->internal->header_written) {
|
||||
ret = s->internal->write_header_ret ? s->internal->write_header_ret : write_header_internal(s);
|
||||
if (ret < 0)
|
||||
goto fail;
|
||||
}
|
||||
|
||||
fail:
|
||||
if (s->internal->header_written && s->oformat->write_trailer) {
|
||||
if (s->oformat->write_trailer) {
|
||||
if (!(s->oformat->flags & AVFMT_NOFILE) && s->pb)
|
||||
avio_write_marker(s->pb, AV_NOPTS_VALUE, AVIO_DATA_MARKER_TRAILER);
|
||||
if (ret >= 0) {
|
||||
@@ -1302,7 +1271,6 @@ fail:
|
||||
if (s->oformat->deinit)
|
||||
s->oformat->deinit(s);
|
||||
|
||||
s->internal->header_written =
|
||||
s->internal->initialized =
|
||||
s->internal->streams_initialized = 0;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user