MediaInfo is a tool that reads and analyzes audio and video files, extracting metadata such as video details, audio tracks, subtitles, and more. It can also be used on the web through mediainfo.js, which leverages WebAssembly technology to provide similar functionality. This article focuses on entegrating mediainfo.js into a Vue framework for detecting audio tracks in video files. Integrating mediainfo.js in Vue
mediainfo.js can be included in web applications via two methods: - CDN: Use the following script tag: <script type="text/javascript" src="https://unpkg.com/mediainfo.js/dist/mediainfo.min.js"></script>
- Bundler: Install using npm with
npm install mediainfo.js.
Since mediainfo.js relies on MediaInfoModule.wasm, both files must reside in the same service path. The CDN version automatically handles this, but when using npm, additional configuration is required, especially in frameworks like Vue where Webpack is involved. For a Vue 2 project, you need to configure vue.config.js to ensure MediaInfoModule.wasm is copied correctly during the build process. ### Configuration Steps
- Use
copy-webpack-pluginto copyMediaInfoModule.wasmto the build output directory: ```
const CopyPlugin = require('copy-webpack-plugin'); const wasmFile = resolve('node_modules/mediainfo.js/dist/MediaInfoModule.wasm');
module.exports = { configureWebpack: { plugins: [ // For development mode new CopyPlugin([{ from: wasmFile, to: '.' }]), // For production build new CopyPlugin([{ from: wasmFile, to: '/js' }]) ] } };
Note: If you're using a newer version of Webpack, update the plugin configuration as follows: ```
new CopyPlugin({
patterns: [
{ from: wasmFile, to: '.' },
{ from: 'CNAME', to: '.' }
]
});
- Ensure
MediaInfoModule.wasmis placed in different directories fornpm run devandnpm run build. ### Implementation Example
Below is an example of how to use mediainfo.js within a Vue component to detect audio tracks in uploaded video files. ```
In this example, we use the iView Upload component and intercept the file upload process in the `:before-upload` callback. The file content is read in chunks and passed to `mediainfo.js` for analysis. Summary
-------
1. `mediainfo.js` enables online parsing of video and audio parameters on web pages. 2. In Vue or similar frameworks, Webpack must be configured to copy `MediaInfoModule.wasm` to the correct output directory during the build process. 3. Combine `mediainfo.js` with upload components to analyze uploaded files and extract metadata. </div>