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

May we have an example for showing how to get input device for image capturing on Mac? #126

Open
WENPIN1 opened this issue Oct 23, 2023 · 1 comment
Assignees

Comments

@WENPIN1
Copy link

WENPIN1 commented Oct 23, 2023

Hi all,
May we have an example for showing how to get input device for image capturing on Apple MAC ?
I've tried several code snippets but it always failed on either building or finding the correct video input device.
"Thank you very much!"

e.g.

unsafe {rsmpeg::ffi::avdevice_register_all();}
let s = cstr!("rawvideo");  // avfoundation ?
let mut inf = AVInputFormat::find(s);

let file=cstr!("0:0");

let mut input_format_context = AVFormatContextInput::open(file, inf, &mut None)?;

#117

@ldm0 ldm0 self-assigned this Oct 23, 2023
@WENPIN1
Copy link
Author

WENPIN1 commented Oct 24, 2023

My study till now;

$brew install sdl2

ffmpeg need sdl2 on MAC

.cargo/config.toml

[env]
FFMPEG_PKG_CONFIG_PATH = "..../tmp/ffmpeg_build/lib/pkgconfig"
RUST_BACKTRACE = "full"
FFMPEG_LIBS_DIR = "..../tmp/ffmpeg_build/lib/"
FFMPEG_INCLUDE_DIR = "..../tmp/ffmpeg_build/include/"

[build]
target = "aarch64-apple-darwin"

[target.aarch64-apple-darwin]
rustflags = [
    "-C",
    "link-arg=-undefined",
    "-C",
    "link-arg=dynamic_lookup",
    # "-C",
    # "link-arg=-lsdl2",
]

build.rs

fn main() {
    println!("cargo:rustc-flags=-l framework=GameController");  // or uncomment -sld2 in config.toml
}

test/tutorial01.rs

fn _main(file: &CStr, out_dir: &str) -> Result<()> {
    unsafe {
        ffi::avdevice_register_all();
    }
    let s = cstr!("avfoundation");
    let inf = AVInputFormat::find(s);


    fs::create_dir_all(out_dir)?;

    let mut dict = Some(
        AVDictionary::new_int(cstr!("framerate"), 30, 0)
            .set(cstr!("video_size"), cstr!("1280x720"), 0)
            .set(cstr!("pix_fmt"), cstr!("uyvy422"), 0),
    );
    let mut input_format_context = AVFormatContextInput::open(file, inf.as_deref(), &mut dict)?;

....
#[test]
fn tutorial01_test4() {
    // _main(cstr!("0:0"), "tests/output/tutorial01/mov_sample").unwrap();
    _main(cstr!("0:none"), "tests/output/tutorial01/mov_sample").unwrap();
}

$cargo test --package rsmpeg --test tutorial01 -- tutorial01_test4 --exact --nocapture

But still cannot overcome "ReadFrameError(-35)" !

-WENPIN1

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

2 participants