History

ffmpeg: count packets when queued

Because write_packet() fakely writes packets to muxer by queueing them when muxer hasn't been initialized, it should also increment frame_number fakely. This is required because code in do_streamcopy() rely on frame_number. Should fix Ticket6227

Muhammad Faiz committed 9 years ago

Commit c4be2881 parent 9b4648a1 file · +20 −18Browse files

Unified · Split

ffmpeg.c+20−18
@@ -669,12 +669,28 @@ static void close_all_output_streams(OutputStream *ost, OSTFinished this_stream, · 668 unmodified lines
669669 }
670670 }
671671
672−static void write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost)
672+static void write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, int unqueue)
673673 {
674674 AVFormatContext *s = of->ctx;
675675 AVStream *st = ost->st;
676676 int ret;
677677
678+ /*
679+ * Audio encoders may split the packets -- #frames in != #packets out.
680+ * But there is no reordering, so we can limit the number of output packets
681+ * by simply dropping them here.
682+ * Counting encoded video frames needs to be done separately because of
683+ * reordering, see do_video_out().
684+ * Do not count the packet when unqueued because it has been counted when queued.
685+ */
686+ if (!(st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && ost->encoding_needed) && !unqueue) {
687+ if (ost->frame_number >= ost->max_frames) {
688+ av_packet_unref(pkt);
689+ return;
690+ }
691+ ost->frame_number++;
692+ }
693+
678694 if (!of->header_written) {
679695 AVPacket tmp_pkt = {0};
680696 /* the muxer is not initialized yet, buffer the packet */
@@ -703,20 +719,6 @@ static void write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost) · 22 unmodified lines
703719 (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && audio_sync_method < 0))
704720 pkt->pts = pkt->dts = AV_NOPTS_VALUE;
705721
706− /*
707− * Audio encoders may split the packets -- #frames in != #packets out.
708− * But there is no reordering, so we can limit the number of output packets
709− * by simply dropping them here.
710− * Counting encoded video frames needs to be done separately because of
711− * reordering, see do_video_out()
712− */
713− if (!(st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && ost->encoding_needed)) {
714− if (ost->frame_number >= ost->max_frames) {
715− av_packet_unref(pkt);
716− return;
717− }
718− ost->frame_number++;
719− }
720722 if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
721723 int i;
722724 uint8_t *sd = av_packet_get_side_data(pkt, AV_PKT_DATA_QUALITY_STATS,
@@ -861,10 +863,10 @@ static void output_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost) · 138 unmodified lines
861863 goto finish;
862864 idx++;
863865 } else
864− write_packet(of, pkt, ost);
866+ write_packet(of, pkt, ost, 0);
865867 }
866868 } else
867− write_packet(of, pkt, ost);
869+ write_packet(of, pkt, ost, 0);
868870
869871 finish:
870872 if (ret < 0 && ret != AVERROR_EOF) {
@@ -2972,7 +2974,7 @@ static int check_init_output_file(OutputFile *of, int file_index) · 2101 unmodified lines
29722974 while (av_fifo_size(ost->muxing_queue)) {
29732975 AVPacket pkt;
29742976 av_fifo_generic_read(ost->muxing_queue, &pkt, sizeof(pkt), NULL);
2975− write_packet(of, &pkt, ost);
2977+ write_packet(of, &pkt, ost, 1);
29762978 }
29772979 }
29782980

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t