admin管理员组

文章数量:1313807

I need to decode h264 data at browser side for that I am using openh264 library build in web Assembly using emscripten. I have build it successfully and tried to use it in java script to decode the h264 data. But I am getting one error for following line,

var open_decoder = Module.cwrap('open_decoder', 'number', null);

Error is: Uncaught TypeError: Module.cwrap is not a function

If anyone has has build openh264 with emscripten please help me to figure out issue.

Following steps I have used to build openh264 with emscripten.

  1. $ source emsdk_env.sh
  2. $./emsdk activate latest
  3. cd openh264-js-master
  4. make

Note : The code for openh264 has been downloaded from github( ttyridal) and already has make file with emscripten petent.

I need to decode h264 data at browser side for that I am using openh264 library build in web Assembly using emscripten. I have build it successfully and tried to use it in java script to decode the h264 data. But I am getting one error for following line,

var open_decoder = Module.cwrap('open_decoder', 'number', null);

Error is: Uncaught TypeError: Module.cwrap is not a function

If anyone has has build openh264 with emscripten please help me to figure out issue.

Following steps I have used to build openh264 with emscripten.

  1. $ source emsdk_env.sh
  2. $./emsdk activate latest
  3. cd openh264-js-master
  4. make

Note : The code for openh264 has been downloaded from github( ttyridal) and already has make file with emscripten petent.

Share Improve this question asked May 8, 2019 at 11:53 Kuldeep MoreKuldeep More 1384 silver badges14 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 6
-s EXTRA_EXPORTED_RUNTIME_METHODS=["cwrap"]

Include above in mand line while piling your source

emcc source.c -s EXPORTED_FUNCTIONS=['_my_add'] -s EXTRA_EXPORTED_RUNTIME_METHODS=["cwrap"]

Probably you are trying to use Module before the Emscripten runtime has been initialized, so Module.cwrap is undefined.

To make sure the runtime is ready, place your code inside of Module.onRuntimeInitialized, as in the following example:

<!doctype html>
<html>
<body>
    <script>
        var Module = {
          onRuntimeInitialized: function() {
            my_add = Module.cwrap('my_add', 'number', ['number', 'number'])
            alert('1 + 2 = ' + my_add(1, 2));
          },
        };
    </script>
    <script async type="text/javascript" src="index.js"></script>
</body>
</html>

See full example in this github repo

本文标签: javascriptUncaught TypeError Modulecwrap is not a functionStack Overflow