rsmpeg icon indicating copy to clipboard operation
rsmpeg copied to clipboard

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

Open WENPIN1 opened this issue 2 years ago • 1 comments

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)?;

https://github.com/larksuite/rsmpeg/issues/117

WENPIN1 avatar Oct 23 '23 07:10 WENPIN1

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

WENPIN1 avatar Oct 24 '23 04:10 WENPIN1