简体   繁体   English

如何使用mp4.js节点模块从mp4中读取元数据?

[英]How to read metadata from mp4 using mp4.js node module?

I am trying to read the metadata tags from an mp4 file into my javascript using the node module mp4js . 我正在尝试使用节点模块mp4js将mp4文件中的元数据标签读取到我的javascript中。 I followed the model provided on that page but with some issue. 我遵循了该页面上提供的模型,但是存在一些问题。

I tried the following: 我尝试了以下方法:

var mp4 = require('mp4js');

mp4({ file: 'small.mp4', type: 'local' }, function (err, tags) {
    // tags now contains your MP4 tags
    console.log('Tags: ' + tags)
    $scope.mp4Tags = tags;
});

and I was met with Uncaught TypeError: Cannot read property 'join' of undefined 并且遇到了Uncaught TypeError: Cannot read property 'join' of undefined

Does anyone know what I'm missing here? 有人知道我在这里想念的吗? Could it be that the mp4 doesn't have any tags? mp4可能没有标签吗? I just googled "sample mp4" and downloaded something. 我只是用Google搜索“示例mp4”并下载了一些内容。 It's my first time trying this module and I am pretty new to node. 这是我第一次尝试此模块,并且对Node来说还很陌生。

I'm also open to other suggestions for reading mp4 metadata. 我也欢迎阅读mp4元数据的其他建议。

Thank you very much for your time and let me know if you need any additional from me. 非常感谢您的宝贵时间,如果您需要我提供的其他任何信息,请告诉我。

EDIT 8.26.2015 编辑8.26.2015

Following Brad's suggestion, I tried the following code to read metadata from an mp4: 按照Brad的建议,我尝试了以下代码从mp4中读取元数据:

    var child_process = require('child_process');
ls = child_process.spawn('ffmpeg/bin/ffprobe.exe', ['-print_format', 'json', 'out.mp4']);

ls.stdout.on('data', function (data) {
    console.log('stdout: ' + data);
    $scope.mp4data = data;
});

I created mp4.out by following this example for adding a title meta tag using ffmpeg from the command line. 我通过遵循以下示例通过从命令行使用ffmpeg添加标题元标记来创建mp4.out。 Here is a screenshot of my output . 这是我的输出的屏幕截图 Here is the command I entered: 这是我输入的命令:

ffmpeg -i in.avi -metadata title="my title" out.flv

After running my app with the code above, the value stored in $scope.mp4data is a Native Buffer that looks like this . 使用上面的代码运行我的应用程序之后,存储在$scope.mp4data的值是一个本机缓冲区, 看起来像这样 All I see are some numbers, but no metadata tags. 我所看到的只是一些数字,但没有元数据标签。 How can I view the metadata such as the title that I set using the command above? 如何查看使用上述命令设置的元数据(例如标题)? Am I missing something in the arguments? 我在论据中遗漏了什么吗? Or maybe I should be looking at something other than data ? 还是我应该查看data以外的其他内容?

Thanks for the help. 谢谢您的帮助。 I may just post this as a new question since the focus has shifted. 由于重点已经转移,我可以将其发布为新问题。

EDIT: Solution 编辑:解决方案

Here's where I landed thanks to Brad's help: 在布拉德的帮助下,我到达了这里:

$scope.mp4data = "";
ls.stdout.on('data', function (data) {
    $scope.mp4data = $scope.mp4data + data.toString();
});

ls.stdout.on('end', function (data) {
    $scope.mp4data = JSON.parse($scope.mp4data);
});

works great for reading metadata from my mp4! 非常适合从mp4中读取元数据! Thanks Brad! 谢谢布拉德!

I recommend using FFprobe (from the FFmpeg project) to do this instead. 我建议使用FFprobe(来自FFmpeg项目)来代替。 It supports many containers, including MP4. 它支持许多容器,包括MP4。

You can use ffprobe -print_format json to have it output JSON data that you can parse inside your Node.js app. 您可以使用ffprobe -print_format json使其输出可在Node.js应用程序中解析的JSON数据。

Some examples here: https://stackoverflow.com/a/8191228/362536 此处为一些示例: https : //stackoverflow.com/a/8191228/362536

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM