Untitled

mail@pastecode.io avatar
unknown
plain_text
3 years ago
975 B
2
Indexable
Never
static int write_flush_video_frame(AVFormatContext *oc, OutputStream *ost)
{
	int ret;
	AVCodecContext *c;
	AVFrame *frame = NULL;
	int got_packet = 0;
	AVPacket pkt = { 0 };
	c = ost->enc;


	av_init_packet(&pkt);
	ret = avcodec_send_frame(c, frame);
	if (ret < 0) {
		fprintf(stderr, "Error encoding video frame: %s\n", av_err2str(ret));
		//exit(1);
		goto cleanup;
	}
	/////////
	while (ret >= 0) {
		ret = avcodec_receive_packet(c, &pkt);
		if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)
			break;
		else if (ret < 0) {
			fprintf(stderr, "Error during encoding\n");
			//exit(1);
			goto cleanup;
		}

		ret = write_frame(oc, &c->time_base, ost->st, &pkt, 0);

		got_packet = 1;
	}
	////////
cleanup:
    av_packet_unref(&pkt);

	return (frame || got_packet) ? 0 : 1;
}

int do_flush_video_eof() {
    int ret = 1;
    do {
        ret = write_flush_video_frame(oc, &video_st);
    }while(ret == 0);

    return ret;
}