MCPcopy Create free account
hub / github.com/OpenShot/libopenshot / flush_encoders

Method flush_encoders

src/FFmpegWriter.cpp:770–909  ·  view source on GitHub ↗

Flush encoders

Source from the content-addressed store, hash-verified

768
769// Flush encoders
770void FFmpegWriter::flush_encoders() {
771 if (info.has_audio && audio_codec_ctx && AV_GET_CODEC_TYPE(audio_st) == AVMEDIA_TYPE_AUDIO && AV_GET_CODEC_ATTRIBUTES(audio_st, audio_codec_ctx)->frame_size <= 1)
772 return;
773#if (LIBAVFORMAT_VERSION_MAJOR < 58)
774 // FFmpeg < 4.0
775 if (info.has_video && video_codec_ctx && AV_GET_CODEC_TYPE(video_st) == AVMEDIA_TYPE_VIDEO && (oc->oformat->flags & AVFMT_RAWPICTURE) && AV_FIND_DECODER_CODEC_ID(video_st) == AV_CODEC_ID_RAWVIDEO)
776 return;
777#else
778 if (info.has_video && video_codec_ctx && AV_GET_CODEC_TYPE(video_st) == AVMEDIA_TYPE_VIDEO && AV_FIND_DECODER_CODEC_ID(video_st) == AV_CODEC_ID_RAWVIDEO)
779 return;
780#endif
781
782 // FLUSH VIDEO ENCODER
783 if (info.has_video) {
784 for (;;) {
785
786 // Increment PTS (in frames and scaled to the codec's timebase)
787 video_timestamp += av_rescale_q(1, av_make_q(info.fps.den, info.fps.num), video_codec_ctx->time_base);
788
789#if IS_FFMPEG_3_2
790 AVPacket* pkt = av_packet_alloc();
791#else
792 AVPacket* pkt;
793 av_init_packet(pkt);
794#endif
795 pkt->data = NULL;
796 pkt->size = 0;
797
798 /* encode the image */
799 int got_packet = 0;
800 int error_code = 0;
801
802#if IS_FFMPEG_3_2
803 // Encode video packet (latest version of FFmpeg)
804 error_code = avcodec_send_frame(video_codec_ctx, NULL);
805 got_packet = 0;
806 while (error_code >= 0) {
807 error_code = avcodec_receive_packet(video_codec_ctx, pkt);
808 if (error_code == AVERROR(EAGAIN)|| error_code == AVERROR_EOF) {
809 got_packet = 0;
810 // Write packet
811 avcodec_flush_buffers(video_codec_ctx);
812 break;
813 }
814 av_packet_rescale_ts(pkt, video_codec_ctx->time_base, video_st->time_base);
815 pkt->stream_index = video_st->index;
816 error_code = av_interleaved_write_frame(oc, pkt);
817 }
818#else // IS_FFMPEG_3_2
819
820 // Encode video packet (older than FFmpeg 3.2)
821 error_code = avcodec_encode_video2(video_codec_ctx, pkt, NULL, &got_packet);
822
823#endif // IS_FFMPEG_3_2
824
825 if (error_code < 0) {
826 ZmqLogger::Instance()->AppendDebugMethod(
827 "FFmpegWriter::flush_encoders ERROR ["

Callers

nothing calls this directly

Calls 2

av_err2stringFunction · 0.85
AppendDebugMethodMethod · 0.80

Tested by

no test coverage detected