如何使用 mp4.js 节点模块从 mp4 读取元数据?
How to read metadata from mp4 using mp4.js node module?
我正在尝试使用节点模块 mp4js 将 mp4 文件中的元数据标签读入我的 javascript。我遵循了该页面上提供的模型,但遇到了一些问题。
我尝试了以下方法:
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;
});
我遇到了 Uncaught TypeError: Cannot read property 'join' of undefined
有人知道我在这里错过了什么吗?难道mp4没有标签?我刚刚用谷歌搜索 "sample mp4" 并下载了一些东西。这是我第一次尝试这个模块,我对节点还很陌生。
我也乐于接受有关阅读 mp4 元数据的其他建议。
非常感谢您抽出宝贵时间,如果您需要我提供任何其他信息,请告诉我。
编辑 2015 年 8 月 26 日
按照 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;
});
我通过关注 this example for adding a title meta tag using ffmpeg from the command line. Here is a screenshot of my output 创建了 mp4.out。这是我输入的命令:
ffmpeg -i in.avi -metadata title="my title" out.flv
在运行我的应用程序使用上面的代码之后,存储在$scope.mp4data
中的值是一个looks like this的本地缓冲区。我只看到一些数字,但没有元数据标签。如何查看我使用上面的命令设置的标题等元数据?我在争论中遗漏了什么吗?或者我应该看看 data
以外的东西?
感谢您的帮助。我可能只是 post 这是一个新问题,因为焦点已经转移。
编辑:解决方案
感谢 Brad 的帮助,我在这里着陆了:
$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);
});
非常适合从我的 mp4 中读取元数据!谢谢布拉德!
我建议改用 FFprobe(来自 FFmpeg 项目)来执行此操作。它支持许多容器,包括 MP4。
您可以使用 ffprobe -print_format json
让它输出 JSON 数据,您可以在 Node.js 应用程序中解析这些数据。
这里有一些例子:
我正在尝试使用节点模块 mp4js 将 mp4 文件中的元数据标签读入我的 javascript。我遵循了该页面上提供的模型,但遇到了一些问题。
我尝试了以下方法:
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;
});
我遇到了 Uncaught TypeError: Cannot read property 'join' of undefined
有人知道我在这里错过了什么吗?难道mp4没有标签?我刚刚用谷歌搜索 "sample mp4" 并下载了一些东西。这是我第一次尝试这个模块,我对节点还很陌生。
我也乐于接受有关阅读 mp4 元数据的其他建议。
非常感谢您抽出宝贵时间,如果您需要我提供任何其他信息,请告诉我。
编辑 2015 年 8 月 26 日
按照 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;
});
我通过关注 this example for adding a title meta tag using ffmpeg from the command line. Here is a screenshot of my output 创建了 mp4.out。这是我输入的命令:
ffmpeg -i in.avi -metadata title="my title" out.flv
在运行我的应用程序使用上面的代码之后,存储在$scope.mp4data
中的值是一个looks like this的本地缓冲区。我只看到一些数字,但没有元数据标签。如何查看我使用上面的命令设置的标题等元数据?我在争论中遗漏了什么吗?或者我应该看看 data
以外的东西?
感谢您的帮助。我可能只是 post 这是一个新问题,因为焦点已经转移。
编辑:解决方案
感谢 Brad 的帮助,我在这里着陆了:
$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);
});
非常适合从我的 mp4 中读取元数据!谢谢布拉德!
我建议改用 FFprobe(来自 FFmpeg 项目)来执行此操作。它支持许多容器,包括 MP4。
您可以使用 ffprobe -print_format json
让它输出 JSON 数据,您可以在 Node.js 应用程序中解析这些数据。
这里有一些例子: