| 891 | } |
| 892 | |
| 893 | static void do_audio_out(OutputFile *of, OutputStream *ost, |
| 894 | AVFrame *frame) |
| 895 | { |
| 896 | AVCodecContext *enc = ost->enc_ctx; |
| 897 | AVPacket pkt; |
| 898 | int ret; |
| 899 | |
| 900 | av_init_packet(&pkt); |
| 901 | pkt.data = NULL; |
| 902 | pkt.size = 0; |
| 903 | |
| 904 | if (!check_recording_time(ost)) |
| 905 | return; |
| 906 | |
| 907 | if (frame->pts == AV_NOPTS_VALUE || audio_sync_method < 0) |
| 908 | frame->pts = ost->sync_opts; |
| 909 | ost->sync_opts = frame->pts + frame->nb_samples; |
| 910 | ost->samples_encoded += frame->nb_samples; |
| 911 | ost->frames_encoded++; |
| 912 | |
| 913 | av_assert0(pkt.size || !pkt.data); |
| 914 | update_benchmark(NULL); |
| 915 | if (debug_ts) { |
| 916 | av_log(NULL, AV_LOG_INFO, "encoder <- type:audio " |
| 917 | "frame_pts:%s frame_pts_time:%s time_base:%d/%d\n", |
| 918 | av_ts2str(frame->pts), av_ts2timestr(frame->pts, &enc->time_base), |
| 919 | enc->time_base.num, enc->time_base.den); |
| 920 | } |
| 921 | |
| 922 | ret = avcodec_send_frame(enc, frame); |
| 923 | if (ret < 0) |
| 924 | goto error; |
| 925 | |
| 926 | while (1) { |
| 927 | ret = avcodec_receive_packet(enc, &pkt); |
| 928 | if (ret == AVERROR(EAGAIN)) |
| 929 | break; |
| 930 | if (ret < 0) |
| 931 | goto error; |
| 932 | |
| 933 | update_benchmark("encode_audio %d.%d", ost->file_index, ost->index); |
| 934 | |
| 935 | av_packet_rescale_ts(&pkt, enc->time_base, ost->mux_timebase); |
| 936 | |
| 937 | if (debug_ts) { |
| 938 | av_log(NULL, AV_LOG_INFO, "encoder -> type:audio " |
| 939 | "pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s\n", |
| 940 | av_ts2str(pkt.pts), av_ts2timestr(pkt.pts, &enc->time_base), |
| 941 | av_ts2str(pkt.dts), av_ts2timestr(pkt.dts, &enc->time_base)); |
| 942 | } |
| 943 | |
| 944 | output_packet(of, &pkt, ost); |
| 945 | } |
| 946 | |
| 947 | return; |
| 948 | error: |
| 949 | av_log(NULL, AV_LOG_FATAL, "Audio encoding failed\n"); |
| 950 | exit_program(1); |
no test coverage detected