FFmpeg build with Zig on macOS 15.2 (M1, aarch64) crashes on execution
I am building FFmpeg with Zig on macOS 15.2 (M1, aarch64) using Zig version 0.14.0-dev.3012 (but I also tried with earlier versions of Zig).
I fixed compilation errors and created a PR with the fixes: PR #19.
There are still linking errors related to Video4Linux (v4l2), such as:
error: undefined symbol: _ff_h263_v4l2m2m_decoder
note: referenced by /Users/a/projects/zig/7phs/ffmpeg/.zig-cache/o/471050c645269de17013a79fb70abb5d/libffmpeg.a(allcodecs.o):_codec_list
error: undefined symbol: _ff_h263_v4l2m2m_encoder
note: referenced by /Users/a/projects/zig/7phs/ffmpeg/.zig-cache/o/471050c645269de17013a79fb70abb5d/libffmpeg.a(allcodecs.o):_codec_list
I resolved these by filtering out the codecs during the build: Commit c809de8.
With this fix, the build completes without errors.
However, when I try to run the compiled executable (e.g., show_metadata_zig or show_metadata_c), it crashes with the following log:
{
"value": 6484581168,
"symbolLocation": 408,
"symbol": "dyld3::MachOAnalyzer::forEachRebase_Opcodes(Diagnostics&, dyld3::MachOLoaded::LinkEditInfo const&, dyld3::MachOFile::SegmentInfo const*, void (char const*, dyld3::MachOLoaded::LinkEditInfo const&, dyld3::MachOFile::SegmentInfo const*, bool, unsigned int, unsigned char, unsigned long long, dyld3::MachOAnalyzer::Rebase, bool&) block_pointer) const"
},
{
"value": 6484581020,
"symbolLocation": 260,
"symbol": "dyld3::MachOAnalyzer::forEachRebase_Opcodes(Diagnostics&, dyld3::MachOLoaded::LinkEditInfo const&, dyld3::MachOFile::SegmentInfo const*, void (char const*, dyld3::MachOLoaded::LinkEditInfo const&, dyld3::MachOFile::SegmentInfo const*, bool, unsigned int, unsigned char, unsigned long long, dyld3::MachOAnalyzer::Rebase, bool&) block_pointer) const"
},
{
"value": 0
},
{
"sourceLine": 399,
"value": 4341349760,
"sourceFile": "h264idct_neon.S",
"symbol": "ff_h264_idct8_add4_neon",
"symbolLocation": 96
},
{
"value": 4353990968,
"symbolLocation": 0,
"symbol": "scan8"
},
...
"esr": {
"value": 2449473615,
"description": "(Data Abort) byte write Permission fault"
},
I tried different versions of Zig, but the result is always the same.
Do you have any insights into the cause of this crash?
Do you know how to debug such an issue?
I can't answer your original question, because I didn't find any solution, but what I ended up doing was, compile ffmpeg with clang as a static library, then copied the libraries and headers I needed into my Zig project like this: project/ ├── src/ │ └── main.zig ├── lib/ │ ├── libavcodec.a │ ├── libavformat.a │ ├── libavutil.a │ └── libswscale.a └── include/ ├── libavcodec/ │ └── avcodec.h ├── libavformat/ │ └── avformat.h ├── libavutil/ │ └── avutil.h └── libswscale/ └── swscale.h
Then I just included the libraries and 'av.zig' in my Zig.build, and, well, it works on macOS with M1.