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

Getting list of supported formats / resolutions / framerates #14

Open
Boscop opened this issue Jun 3, 2018 · 2 comments
Open

Getting list of supported formats / resolutions / framerates #14

Boscop opened this issue Jun 3, 2018 · 2 comments

Comments

@Boscop
Copy link

Boscop commented Jun 3, 2018

Would it be possible for escapi to allow querying for the supported formats of a camera, and then query for the supported resolutions of a given format?
Similar to how it's possible with the rscam Rust crate:

extern crate rscam;

use std::io::prelude::*;
use std::fs;

fn main() -> rscam::Result<()> {
	let mut cam = rscam::new("/dev/video2").unwrap();
	for fmt in cam.formats() {
		let fmt = fmt?;
		println!("{:?}", fmt);
		if let rscam::ResolutionInfo::Discretes(v) = cam.resolutions(&fmt.format)? {
			for res in v {
				println!("{:?} {:?}", res, cam.intervals(&fmt.format, res)?);
			}
		}
	}

	cam.start(&rscam::Config {
		interval: (1, 30),      // 30 fps.
		resolution: (1920, 1080),
		format: b"MJPG",
		..Default::default()
	}).unwrap();

	for i in 0..30 {
		let frame = cam.capture().unwrap();
		let mut file = fs::File::create(&format!("frame-{}.jpg", i)).unwrap();
		file.write_all(&frame[..]).unwrap();
	}
	Ok(())
}

which prints:

YUYV (YUYV 4:2:2)
(1920, 1080) Discretes: 5fps
(160, 120) Discretes: 30fps, 25fps, 20fps, 15fps
(176, 144) Discretes: 30fps, 25fps, 20fps, 15fps
(320, 240) Discretes: 30fps, 25fps, 20fps, 15fps
(352, 288) Discretes: 30fps, 25fps, 20fps, 15fps
(640, 360) Discretes: 30fps, 25fps, 20fps, 15fps
(640, 480) Discretes: 30fps, 25fps, 20fps, 15fps
(800, 600) Discretes: 10fps, 5fps
(848, 480) Discretes: 10fps, 5fps
(1024, 768) Discretes: 10fps, 5fps
(1280, 800) Discretes: 10fps, 5fps
(1280, 720) Discretes: 10fps, 5fps
MJPG (Motion-JPEG, compressed)
(1920, 1080) Discretes: 30fps, 25fps, 20fps, 5fps
(160, 120) Discretes: 30fps, 25fps, 20fps, 15fps
(176, 144) Discretes: 30fps, 25fps, 20fps, 15fps
(320, 240) Discretes: 30fps, 25fps, 20fps, 15fps
(352, 288) Discretes: 30fps, 25fps, 20fps, 15fps
(640, 360) Discretes: 30fps, 25fps, 20fps, 5fps
(640, 480) Discretes: 30fps, 25fps, 20fps, 15fps
(800, 600) Discretes: 30fps, 25fps, 20fps, 5fps
(848, 480) Discretes: 30fps, 25fps, 20fps, 5fps
(1024, 768) Discretes: 30fps, 25fps, 20fps, 5fps
(1280, 800) Discretes: 30fps, 25fps, 20fps, 5fps
(1280, 720) Discretes: 30fps, 25fps, 20fps, 5fps
RGB3 (RGB3, emulated)
(1920, 1080) Discretes: 30fps, 25fps, 20fps, 5fps
(160, 120) Discretes: 30fps, 25fps, 20fps, 15fps
(176, 144) Discretes: 30fps, 25fps, 20fps, 15fps
(320, 240) Discretes: 30fps, 25fps, 20fps, 15fps
(352, 288) Discretes: 30fps, 25fps, 20fps, 15fps
(640, 360) Discretes: 30fps, 25fps, 20fps, 15fps
(640, 480) Discretes: 30fps, 25fps, 20fps, 15fps
(800, 600) Discretes: 30fps, 25fps, 20fps, 5fps
(848, 480) Discretes: 10fps, 5fps
(1024, 768) Discretes: 30fps, 25fps, 20fps, 5fps
(1280, 800) Discretes: 30fps, 25fps, 20fps, 5fps
(1280, 720) Discretes: 30fps, 25fps, 20fps, 5fps
BGR3 (BGR3, emulated)
(1920, 1080) Discretes: 30fps, 25fps, 20fps, 5fps
(160, 120) Discretes: 30fps, 25fps, 20fps, 15fps
(176, 144) Discretes: 30fps, 25fps, 20fps, 15fps
(320, 240) Discretes: 30fps, 25fps, 20fps, 15fps
(352, 288) Discretes: 30fps, 25fps, 20fps, 15fps
(640, 360) Discretes: 30fps, 25fps, 20fps, 15fps
(640, 480) Discretes: 30fps, 25fps, 20fps, 15fps
(800, 600) Discretes: 30fps, 25fps, 20fps, 5fps
(848, 480) Discretes: 10fps, 5fps
(1024, 768) Discretes: 30fps, 25fps, 20fps, 5fps
(1280, 800) Discretes: 30fps, 25fps, 20fps, 5fps
(1280, 720) Discretes: 30fps, 25fps, 20fps, 5fps
YU12 (YU12, emulated)
(1920, 1080) Discretes: 30fps, 25fps, 20fps, 5fps
(160, 120) Discretes: 30fps, 25fps, 20fps, 15fps
(176, 144) Discretes: 30fps, 25fps, 20fps, 15fps
(320, 240) Discretes: 30fps, 25fps, 20fps, 15fps
(352, 288) Discretes: 30fps, 25fps, 20fps, 15fps
(640, 360) Discretes: 30fps, 25fps, 20fps, 15fps
(640, 480) Discretes: 30fps, 25fps, 20fps, 15fps
(800, 600) Discretes: 30fps, 25fps, 20fps, 5fps
(848, 480) Discretes: 10fps, 5fps
(1024, 768) Discretes: 30fps, 25fps, 20fps, 5fps
(1280, 800) Discretes: 30fps, 25fps, 20fps, 5fps
(1280, 720) Discretes: 30fps, 25fps, 20fps, 5fps
YV12 (YV12, emulated)
(1920, 1080) Discretes: 30fps, 25fps, 20fps, 5fps
(160, 120) Discretes: 30fps, 25fps, 20fps, 15fps
(176, 144) Discretes: 30fps, 25fps, 20fps, 15fps
(320, 240) Discretes: 30fps, 25fps, 20fps, 15fps
(352, 288) Discretes: 30fps, 25fps, 20fps, 15fps
(640, 360) Discretes: 30fps, 25fps, 20fps, 15fps
(640, 480) Discretes: 30fps, 25fps, 20fps, 15fps
(800, 600) Discretes: 30fps, 25fps, 20fps, 5fps
(848, 480) Discretes: 10fps, 5fps
(1024, 768) Discretes: 30fps, 25fps, 20fps, 5fps
(1280, 800) Discretes: 30fps, 25fps, 20fps, 5fps
(1280, 720) Discretes: 30fps, 25fps, 20fps, 5fps

http://loyd.github.io/rscam/rscam/struct.Camera.html

I'm asking because I often encounter the case where a 30 FPS FullHD capture is only possible with MJPEG, like in this case. (The emulated modes are done by v4l2 in software afaik.)
When I open this camera with escapi, it chooses the slow 5 FPS YUYV mode :(

In my modified version of escapi I added MJPEG as a supported format and then pass through the undecoded MJPEG buffer to my Rust application where I use the mozjpeg-sys crate to decode the frames.
But it's very blind (not querying what's supported) & hardcoded to my webcam, I want it to work for any webcam.
So what I would ideally want to do with escapi is: find the highest resolution with at least 20 fps and use that format (and when it's MJPEG I can decode it myself).

Is there any plan to allow querying for supported formats / resolutions / framerates like this? :)

@jarikomppa
Copy link
Owner

jarikomppa commented Jun 4, 2018 via email

@codec-abc
Copy link

Hi Boscop,
Since we talked about this earlier you might be interested in my repo. It's a (small fork) of libdshowcapture to build a Windows dll with a C interface to use it. With it, I am able to retrieve the camera list and properties (using Json with Protobuff). Also, I am able to get a buffer and use it from another end (C# for Unity in my case). It is not pretty but it may answer some questions of yours. Also, you may be able to follow the code in libshowcapture to understand the API call to the Windows SDK to see what it is doing under the hood.

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

3 participants