Try to output videos using SimpleOpenGL3App::dumFramesToVideo()

Post Reply
yluo
Posts: 8
Joined: Tue Sep 25, 2018 9:31 pm

Try to output videos using SimpleOpenGL3App::dumFramesToVideo()

Post by yluo »

Hi everyone,
I have a simple simulation running with a basic opengl app and now I want to output the simulation results into a video.

I followed the example here. Specifically, I used the built-in method SimpleOpenGL3App::dumFramesToVideo(Filename). To run this I downloaded the ffmpeg executables and added it to PATH. I'm getting error at the last frame.

Code: Select all

[rawvideo @ 000001f6a6c1c9c0] Packet corrupt (stream = 0, dts = 30).
pipe:: corrupt input packet in stream 0
[rawvideo @ 000001f6a6c309c0] Invalid buffer size, packet size 11490 < expected frame_size 3145728
Error while decoding stream #0:0: Invalid argument
frame=   30 fps= 14 q=-1.0 Lsize=     659kB time=00:00:00.45 bitrate=11997.1kbits/s speed=0.212x
video:658kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.179747%
[libx264 @ 000001f6a6c32b00] frame I:2     Avg QP:26.98  size: 25858
[libx264 @ 000001f6a6c32b00] frame P:12    Avg QP:28.75  size: 20910
[libx264 @ 000001f6a6c32b00] frame B:16    Avg QP:30.83  size: 23150
[libx264 @ 000001f6a6c32b00] consecutive B-frames:  6.7% 66.7%  0.0% 26.7%
[libx264 @ 000001f6a6c32b00] mb I  I16..4: 61.4%  7.4% 31.2%
[libx264 @ 000001f6a6c32b00] mb P  I16..4: 17.2%  5.8% 10.9%  P16..4: 35.3% 11.1%  3.2%  0.0%  0.0%    skip:16.4%
[libx264 @ 000001f6a6c32b00] mb B  I16..4: 21.7%  2.6%  9.6%  B16..8: 36.8%  9.9%  2.4%  direct: 7.2%  skip:10.0%  L0:45.6% L1:46.2% BI: 8.2%
[libx264 @ 000001f6a6c32b00] 8x8 transform intra:11.0% inter:15.6%
[libx264 @ 000001f6a6c32b00] direct mvs  spatial:62.5% temporal:37.5%
[libx264 @ 000001f6a6c32b00] coded y,uvDC,uvAC intra: 24.3% 48.4% 37.9% inter: 10.9% 36.2% 23.7%
[libx264 @ 000001f6a6c32b00] i16 v,h,dc,p: 46% 53%  1%  0%
[libx264 @ 000001f6a6c32b00] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 16%  8% 75%  0%  0%  0%  0%  0%  1%
[libx264 @ 000001f6a6c32b00] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 33% 37% 19%  2%  1%  1%  2%  2%  3%
[libx264 @ 000001f6a6c32b00] i8c dc,h,v,p: 25% 45% 29%  1%
[libx264 @ 000001f6a6c32b00] Weighted P-Frames: Y:0.0% UV:0.0%
[libx264 @ 000001f6a6c32b00] ref P L0: 18.4%  0.8% 57.4%  6.6% 16.8%
[libx264 @ 000001f6a6c32b00] ref B L0: 47.4% 36.9% 11.3%  4.5%
[libx264 @ 000001f6a6c32b00] ref B L1: 97.1%  2.9%
[libx264 @ 000001f6a6c32b00] kb/s:10768.56
I tried to googled and it seems like a pretty common error that people get when they try to implement ffmpeg themselves. The output video is also twisted. I tried to make three screenshots and compare it to what the simulation should've looked like. There is a consistent offset from frame to frame, and the colors are too corrupted.

Image

I'm completely new to ffmpeg and since it's a built-in method in Bullet I don't think the best idea is to change the source code right? So I'm totally lost what I'm missing here. I'm also attaching my main.cpp for reference

Code: Select all

int main(int argc, char** argv)
{
	std::cout << "main starts.\n";
	SimpleOpenGL3App *app = new SimpleOpenGL3App("Simulation test", 1024, 768, true);

	prevMouseButtonCallback = app->m_window->getMouseButtonCallback();
	prevMouseMoveCallback = app->m_window->getMouseMoveCallback();

	app->m_window->setMouseButtonCallback((b3MouseButtonCallback)OnMouseDown);
	app->m_window->setMouseMoveCallback((b3MouseMoveCallback)OnMouseMove);

	OpenGLGuiHelper gui(app, false);
	CommonExampleOptions options(&gui);

	Parameter *param = new Parameter();
	simulation = new Simulation(options.m_guiHelper);
	simulation->processCommandLineArgs(argc, argv);

	simulation->initParameter(param);
	simulation->initPhysics();
	simulation->resetCamera();

	char bla[32];
	float clr_black[4] = { 1, 1, 1, 1 };
	const char* videoFileName = "../output/output_video.mp4";
	app->dumpFramesToVideo(videoFileName);

	app->m_renderer->writeTransforms();

	do {
		static int frameCount = 0;
		frameCount++;

		// initializing rendered
		app->m_instancingRenderer->init();
		app->m_instancingRenderer->updateCamera(app->getUpAxis());

		// step simualtion
		//simulation->stepSimulation(param->m_time_step);
		simulation->stepSimulation(param->m_time_step);

		// render instances
		simulation->renderScene();
		app->m_renderer->renderScene();

		// draw grid
		DrawGridData dg;
		dg.gridSize = 15;
		dg.upAxis = app->getUpAxis();
		app->setBackgroundColor(1, 1, 1);
		app->drawGrid(dg);

		// draw Text
		sprintf(bla, "Frame: %d", frameCount);
		app->drawText(bla, 10, 10, 0.5, clr_black);

		// end rendering this frame
		app->swapBuffer();

	}while (!app->m_window->requestedExit() && !(exitFlag || simulation->exitSim));


	simulation->exitPhysics();
	std::cout << "Simulation terminated...\n";

	delete simulation;
	delete param;
	delete app;
	std::cout << "Done. Exit Safe.\n";


	return 0;
}
Thank you for your kind help!
yluo
Posts: 8
Joined: Tue Sep 25, 2018 9:31 pm

Re: Try to output videos using SimpleOpenGL3App::dumFramesToVideo()

Post by yluo »

I figured it out.

I'm running this on Windows OS. So I need to go to the source file "SimpleOpenGL3App.cpp" function

Code: Select all

void SimpleOpenGL3App::dumpFramesToVideo(const char* mp4FileName)
and change

Code: Select all

m_data->m_ffmpegFile = popen(cmd, "w");
into

Code: Select all

m_data->m_ffmpegFile = popen(cmd, "wb");
Post Reply