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
669 }669 }
670}670}
671 671
672static void write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost)672static void write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, int unqueue)
673{673{
674 AVFormatContext *s = of->ctx;674 AVFormatContext *s = of->ctx;
675 AVStream *st = ost->st;675 AVStream *st = ost->st;
676 int ret;676 int ret;
677 677
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
678 if (!of->header_written) {694 if (!of->header_written) {
679 AVPacket tmp_pkt = {0};695 AVPacket tmp_pkt = {0};
680 /* the muxer is not initialized yet, buffer the packet */696 /* 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
703 (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && audio_sync_method < 0))719 (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && audio_sync_method < 0))
704 pkt->pts = pkt->dts = AV_NOPTS_VALUE;720 pkt->pts = pkt->dts = AV_NOPTS_VALUE;
705 721
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 }
720 if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {722 if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
721 int i;723 int i;
722 uint8_t *sd = av_packet_get_side_data(pkt, AV_PKT_DATA_QUALITY_STATS,724 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
861 goto finish;863 goto finish;
862 idx++;864 idx++;
863 } else865 } else
864 write_packet(of, pkt, ost);866 write_packet(of, pkt, ost, 0);
865 }867 }
866 } else868 } else
867 write_packet(of, pkt, ost);869 write_packet(of, pkt, ost, 0);
868 870
869finish:871finish:
870 if (ret < 0 && ret != AVERROR_EOF) {872 if (ret < 0 && ret != AVERROR_EOF) {
@@ -2972,7 +2974,7 @@ static int check_init_output_file(OutputFile *of, int file_index) · 2101 unmodified lines
2972 while (av_fifo_size(ost->muxing_queue)) {2974 while (av_fifo_size(ost->muxing_queue)) {
2973 AVPacket pkt;2975 AVPacket pkt;
2974 av_fifo_generic_read(ost->muxing_queue, &pkt, sizeof(pkt), NULL);2976 av_fifo_generic_read(ost->muxing_queue, &pkt, sizeof(pkt), NULL);
2975 write_packet(of, &pkt, ost);2977 write_packet(of, &pkt, ost, 1);
2976 }2978 }
2977 }2979 }
2978 2980

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