pion / mediadevices

Go implementation of the MediaDevices API.
https://pion.ly/
MIT License
528 stars 121 forks source link

Libx264 and VPX problem with MacOS M1 #377

Closed amirhnajafiz closed 2 years ago

amirhnajafiz commented 2 years ago

Hello there. I'm using a MacBook with Apple M1 chip and I successfully installed the following frameworks and libraries:

But when I wanted to load my dependencies in my program, I got the following errors for vpx and x264:

x264

# github.com/pion/mediadevices/pkg/codec/x264
ld: warning: ignoring file /opt/homebrew/Cellar/x264/r3060/lib/libx264.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64
Undefined symbols for architecture x86_64:
  "_x264_encoder_close", referenced from:
      _enc_close in _x002.o
      __cgo_69884a29e201_Cfunc_enc_close in _x002.o
  "_x264_encoder_encode", referenced from:
      _enc_encode in _x002.o
      __cgo_69884a29e201_Cfunc_enc_encode in _x002.o
  "_x264_encoder_open_163", referenced from:
      _enc_new in _x002.o
  "_x264_param_apply_profile", referenced from:
      _enc_new in _x002.o
  "_x264_param_default_preset", referenced from:
      _enc_new in _x002.o
  "_x264_picture_alloc", referenced from:
      _enc_new in _x002.o
  "_x264_picture_clean", referenced from:
      _enc_new in _x002.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

VPX

# github.com/pion/mediadevices/pkg/codec/vpx
ld: warning: ignoring file /opt/homebrew/Cellar/libvpx/1.11.0/lib/libvpx.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64
Undefined symbols for architecture x86_64:
  "_vpx_codec_destroy", referenced from:
      __cgo_df0284dcd8d9_Cfunc_vpx_codec_destroy in _x002.o
     (maybe you meant: __cgo_df0284dcd8d9_Cfunc_vpx_codec_destroy)
  "_vpx_codec_enc_config_default", referenced from:
      __cgo_df0284dcd8d9_Cfunc_vpx_codec_enc_config_default in _x002.o
     (maybe you meant: __cgo_df0284dcd8d9_Cfunc_vpx_codec_enc_config_default)
  "_vpx_codec_enc_init_ver", referenced from:
      __cgo_df0284dcd8d9_Cfunc_vpx_codec_enc_init_ver in _x002.o
     (maybe you meant: __cgo_df0284dcd8d9_Cfunc_vpx_codec_enc_init_ver)
  "_vpx_codec_encode", referenced from:
      _encode_wrapper in _x002.o
      __cgo_df0284dcd8d9_Cfunc_encode_wrapper in _x002.o
  "_vpx_codec_get_cx_data", referenced from:
      __cgo_df0284dcd8d9_Cfunc_vpx_codec_get_cx_data in _x002.o
     (maybe you meant: __cgo_df0284dcd8d9_Cfunc_vpx_codec_get_cx_data)
  "_vpx_codec_vp8_cx", referenced from:
      _ifaceVP8 in _x002.o
      __cgo_df0284dcd8d9_Cfunc_ifaceVP8 in _x002.o
  "_vpx_codec_vp9_cx", referenced from:
      _ifaceVP9 in _x002.o
      __cgo_df0284dcd8d9_Cfunc_ifaceVP9 in _x002.o
  "_vpx_img_alloc", referenced from:
      __cgo_df0284dcd8d9_Cfunc_vpx_img_alloc in _x002.o
     (maybe you meant: __cgo_df0284dcd8d9_Cfunc_vpx_img_alloc)
  "_vpx_img_free", referenced from:
      __cgo_df0284dcd8d9_Cfunc_vpx_img_free in _x002.o
     (maybe you meant: __cgo_df0284dcd8d9_Cfunc_vpx_img_free)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I need this library to create my Video Encoder params in the following code:

mediaEngine := webrtc.MediaEngine{}

vpxP, _ := vpx.NewVP9Params()
vpxP.BitRate = 500_000
codecSelector := mediadevices.NewCodecSelector(
mediadevices.WithVideoEncoders(&vpxP),
)
codecSelector.Populate(&mediaEngine)
api := webrtc.NewAPI(webrtc.WithMediaEngine(&mediaEngine))

I looked for the solutions all over the internet but none of them were helpful. How can I fix this problem??

at-wat commented 2 years ago

Hi @amirhnajafiz !

building for macOS-x86_64 but attempting to link with file built for macOS-arm64

It looks like that you are trying to crosscompile the program for Intel Mac but the installed libraries are for M1 Mac. Could you check your GOARCH env variable and not running in Rosetta?