Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

It's possible to extract an image frame "offline" to generate thumbnails? #76

Open
moebiussurfing opened this issue Oct 2, 2022 · 1 comment

Comments

@moebiussurfing
Copy link

moebiussurfing commented Oct 2, 2022

Hello,
I would like to generate 10 thumbnails from the loaded video,
but without having to play the video (with a semi manual workflow...)

I tried to set the player position into a for loop but it seems, that video position is not updated if not "really playing".
All the output thumbs are the same image frame.
(Then current being drawn frame)

That's my approach:

void doGenerateThumbnails()
{
	ofImageType type = OF_IMAGE_COLOR;
	
	int n = 10;//thumbnails amount
	
	for (int i = 0; i < n; i++)
	{
		float p = i * (1.0f / n);
		
		player.stop();//trying to force refresh

		player.setPosition(p);
                
                //trying tricks
		//ofGetAppPtr()->update();
		//ofGetAppPtr()->draw();

		player.play();//trying to force refresh
		player.update();//trying to force refresh

		ofTexture* t = player.getTexture();
		int w = t->getWidth();
		int h = t->getHeight();

		ofFbo fbo;
		fbo.allocate(w, h);
		fbo.begin();
		ofClear(0);
		player.draw(0, 0);
		fbo.end();

		ofPixels pix;
		pix.allocate(w, h, type);

		fbo.readToPixels(pix);

		ofImage img;
		img.allocate(w, h, type);
		img.setFromPixels(pix);
		img.update();

		img.saveImage(ofToString(i) + ".jpg");
	}
}

Any idea or workaround?

@moebiussurfing
Copy link
Author

moebiussurfing commented Oct 9, 2022

I found a workaround using an FFMPEG script:
https://ottverse.com/thumbnails-screenshots-using-ffmpeg/

then we can call a system command doing something like that:

string s = "ffmpeg -i myHapVideo.mov -vf \"select='not(mod(n,300))',setpts='N/(30*TB)\'" -f image2 thumb%02d.jpg"
cout << ofSystem(s) << endl;

take care with the use of slashing by \" instead of " :

..
s += "))',setpts='N/(30*TB)'\" ";
..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant