@@ -864,9 +864,6 @@ void FFmpegWriter::flush_encoders() {
864864 return ;
865865#endif
866866
867- int error_code = 0 ;
868- int stop_encoding = 1 ;
869-
870867 // FLUSH VIDEO ENCODER
871868 if (info.has_video )
872869 for (;;) {
@@ -940,13 +937,9 @@ void FFmpegWriter::flush_encoders() {
940937 ZmqLogger::Instance ()->AppendDebugMethod (" FFmpegWriter::flush_encoders ERROR [" + (std::string) av_err2str (error_code) + " ]" , " error_code" , error_code);
941938 }
942939 if (!got_packet) {
943- stop_encoding = 1 ;
944940 break ;
945941 }
946942
947- // Override PTS (in frames and scaled to the codec's timebase)
948- // pkt.pts = write_video_count;
949-
950943 // set the timestamp
951944 if (pkt.pts != AV_NOPTS_VALUE)
952945 pkt.pts = av_rescale_q (pkt.pts , video_codec->time_base , video_st->time_base );
@@ -961,10 +954,6 @@ void FFmpegWriter::flush_encoders() {
961954 if (error_code < 0 ) {
962955 ZmqLogger::Instance ()->AppendDebugMethod (" FFmpegWriter::flush_encoders ERROR [" + (std::string)av_err2str (error_code) + " ]" , " error_code" , error_code);
963956 }
964-
965- // Deallocate memory (if needed)
966- if (video_outbuf)
967- av_freep (&video_outbuf);
968957 }
969958
970959 // FLUSH AUDIO ENCODER
@@ -986,18 +975,17 @@ void FFmpegWriter::flush_encoders() {
986975 pkt.pts = pkt.dts = write_audio_count;
987976
988977 /* encode the image */
978+ int error_code = 0 ;
989979 int got_packet = 0 ;
990980#if IS_FFMPEG_3_2
991- avcodec_send_frame (audio_codec, NULL );
992- got_packet = 0 ;
981+ error_code = avcodec_send_frame (audio_codec, NULL );
993982#else
994983 error_code = avcodec_encode_audio2 (audio_codec, &pkt, NULL , &got_packet);
995984#endif
996985 if (error_code < 0 ) {
997986 ZmqLogger::Instance ()->AppendDebugMethod (" FFmpegWriter::flush_encoders ERROR [" + (std::string)av_err2str (error_code) + " ]" , " error_code" , error_code);
998987 }
999988 if (!got_packet) {
1000- stop_encoding = 1 ;
1001989 break ;
1002990 }
1003991
@@ -1583,29 +1571,27 @@ void FFmpegWriter::write_audio_packets(bool is_final) {
15831571 channels_in_frame = frame->GetAudioChannelsCount ();
15841572 channel_layout_in_frame = frame->ChannelsLayout ();
15851573
1586-
15871574 // Get audio sample array
15881575 float *frame_samples_float = NULL ;
15891576 // Get samples interleaved together (c1 c2 c1 c2 c1 c2)
15901577 frame_samples_float = frame->GetInterleavedAudioSamples (sample_rate_in_frame, NULL , &samples_in_frame);
15911578
1592-
15931579 // Calculate total samples
15941580 total_frame_samples = samples_in_frame * channels_in_frame;
15951581
15961582 // Translate audio sample values back to 16 bit integers with saturation
1597- float valF;
1598- int16_t conv;
15991583 const int16_t max16 = 32767 ;
16001584 const int16_t min16 = -32768 ;
16011585 for (int s = 0 ; s < total_frame_samples; s++, frame_position++) {
1602- valF = frame_samples_float[s] * (1 << 15 );
1603- if (valF > max16)
1586+ float valF = frame_samples_float[s] * (1 << 15 );
1587+ int16_t conv;
1588+ if (valF > max16) {
16041589 conv = max16;
1605- else if (valF < min16)
1590+ } else if (valF < min16) {
16061591 conv = min16;
1607- else
1592+ } else {
16081593 conv = int (valF + 32768.5 ) - 32768 ; // +0.5 is for rounding
1594+ }
16091595
16101596 // Copy into buffer
16111597 all_queued_samples[frame_position] = conv;
@@ -1731,10 +1717,11 @@ void FFmpegWriter::write_audio_packets(bool is_final) {
17311717
17321718 // Determine how many samples we need
17331719 int diff = 0 ;
1734- if (remaining_frame_samples >= remaining_packet_samples)
1720+ if (remaining_frame_samples >= remaining_packet_samples) {
17351721 diff = remaining_packet_samples;
1736- else if (remaining_frame_samples < remaining_packet_samples)
1722+ } else {
17371723 diff = remaining_frame_samples;
1724+ }
17381725
17391726 // Copy frame samples into the packet samples array
17401727 if (!is_final)
@@ -1746,7 +1733,6 @@ void FFmpegWriter::write_audio_packets(bool is_final) {
17461733 audio_input_position += diff;
17471734 samples_position += diff * (av_get_bytes_per_sample (output_sample_fmt) / av_get_bytes_per_sample (AV_SAMPLE_FMT_S16));
17481735 remaining_frame_samples -= diff;
1749- remaining_packet_samples -= diff;
17501736
17511737 // Do we have enough samples to proceed?
17521738 if (audio_input_position < (audio_input_frame_size * info.channels ) && !is_final)
0 commit comments