| 670 | } |
| 671 | |
| 672 | static void write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, int unqueue) |
| 673 | { |
| 674 | AVFormatContext *s = of->ctx; |
| 675 | AVStream *st = ost->st; |
| 676 | int ret; |
| 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 | |
| 694 | if (!of->header_written) { |
| 695 | AVPacket tmp_pkt = {0}; |
| 696 | /* the muxer is not initialized yet, buffer the packet */ |
| 697 | if (!av_fifo_space(ost->muxing_queue)) { |
| 698 | int new_size = FFMIN(2 * av_fifo_size(ost->muxing_queue), |
| 699 | ost->max_muxing_queue_size); |
| 700 | if (new_size <= av_fifo_size(ost->muxing_queue)) { |
| 701 | av_log(NULL, AV_LOG_ERROR, |
| 702 | "Too many packets buffered for output stream %d:%d.\n", |
| 703 | ost->file_index, ost->st->index); |
| 704 | exit_program(1); |
| 705 | } |
| 706 | ret = av_fifo_realloc2(ost->muxing_queue, new_size); |
| 707 | if (ret < 0) |
| 708 | exit_program(1); |
| 709 | } |
| 710 | ret = av_packet_ref(&tmp_pkt, pkt); |
| 711 | if (ret < 0) |
| 712 | exit_program(1); |
| 713 | av_fifo_generic_write(ost->muxing_queue, &tmp_pkt, sizeof(tmp_pkt), NULL); |
| 714 | av_packet_unref(pkt); |
| 715 | return; |
| 716 | } |
| 717 | |
| 718 | if ((st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && video_sync_method == VSYNC_DROP) || |
| 719 | (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && audio_sync_method < 0)) |
| 720 | pkt->pts = pkt->dts = AV_NOPTS_VALUE; |
| 721 | |
| 722 | if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { |
| 723 | int i; |
| 724 | uint8_t *sd = av_packet_get_side_data(pkt, AV_PKT_DATA_QUALITY_STATS, |
| 725 | NULL); |
| 726 | ost->quality = sd ? AV_RL32(sd) : -1; |
| 727 | ost->pict_type = sd ? sd[4] : AV_PICTURE_TYPE_NONE; |
| 728 | |
| 729 | for (i = 0; i<FF_ARRAY_ELEMS(ost->error); i++) { |
no test coverage detected