Node.js 位置0视频长度处JSON中的意外标记G

Node.js 位置0视频长度处JSON中的意外标记G,node.js,npm,node-modules,Node.js,Npm,Node Modules,我正在使用nodejs获取视频的持续时间。该代码在Centos中运行良好 在Ubuntu 16.x中,它显示错误: SyntaxError: Unexpected token G in JSON at position 0 at JSON.parse (<anonymous>) at VideoLength (/.../node_modules/video-length/video-length.js:14:24) 我也安装了mediainfo。如果我做错了什么,请

我正在使用nodejs获取视频的持续时间。该代码在Centos中运行良好

在Ubuntu 16.x中,它显示错误:

SyntaxError: Unexpected token G in JSON at position 0
    at JSON.parse (<anonymous>)
    at VideoLength (/.../node_modules/video-length/video-length.js:14:24)
我也安装了mediainfo。如果我做错了什么,请指导我

在调试video-length.js之后,我发现centos和Ubuntu中获得的标准输出有以下区别。 在Centos:

{
"media": {
"@ref": "/var/kurento/tmp/30/27122019/1514kurento-recording.webm",
"track": [
{
"@type": "General",
"VideoCount": "1",
"FileExtension": "webm",
"Format": "WebM",
"Format_Version": "2",
"FileSize": "157078809",
"FrameRate": "25.028",
"IsStreamable": "Yes",
"Encoded_Date": "UTC 2019-12-27 09:44:33",
"File_Modified_Date": "UTC 2019-12-27 10:56:31",
"File_Modified_Date_Local": "2019-12-27 16:26:31",
"Encoded_Application": "GStreamer Matroska muxer",
"Encoded_Library": "GStreamer matroskamux version 1.8.1.1",
"extra": {
"IsTruncated": "Yes"
}
},
{
"@type": "Video",
"StreamOrder": "0",
"ID": "1",
"UniqueID": "2934041311738436184",
"Format": "VP8",
"CodecID": "V_VP8",
"Width": "1920",
"Height": "1080",
"PixelAspectRatio": "1.000",
"DisplayAspectRatio": "1.778",
"FrameRate_Mode": "CFR",
"FrameRate": "25.028",
"Compression_Mode": "Lossy",
"Delay": "0.000",
"Title": "Video",
"Language": "en",
"Default": "Yes",
"Forced": "No"
}
]
}
}
在Ubuntu中:

General
Count                                    : 308
Count of stream of this kind             : 1
Kind of stream                           : General
Kind of stream                           : General
Stream identifier                        : 0
Count of video streams                   : 1
Video_Format_List                        : VP8
Video_Format_WithHint_List               : VP8
Codecs Video                             : V_VP8
Video_Language_List                      : English
Complete name                            : /var/kurento/tmp/27/23012020/1355kurento-recording.webm
Folder name                              : /var/kurento/tmp/27/23012020
File name                                : 1355kurento-recording
File extension                           : webm
Format                                   : WebM
Format                                   : WebM
Format/Url                               : http://www.webmproject.org/
Format/Extensions usually used           : webm
Commercial name                          : WebM
Format version                           : Version 2
Internet media type                      : video/webm
Codec                                    : WebM
Codec                                    : WebM
Codec/Url                                : http://www.webmproject.org/
Codec/Extensions usually used            : webm
File size                                : 1760787
File size                                : 1.68 MiB
File size                                : 2 MiB
File size                                : 1.7 MiB
File size                                : 1.68 MiB
File size                                : 1.679 MiB
Duration                                 : 45037
Duration                                 : 45s 37ms
Duration                                 : 45s 37ms
Duration                                 : 45s 37ms
Duration                                 : 00:00:45.037
Duration                                 : 00:00:45.037
Overall bit rate                         : 312772
Overall bit rate                         : 313 Kbps
Encoded date                             : UTC 2020-01-23 08:25:19
File last modification date              : UTC 2020-01-23 08:26:04
File last modification date (local)      : 2020-01-23 13:56:04
Writing application                      : GStreamer Matroska muxer
Writing application                      : GStreamer Matroska muxer
Writing library                          : GStreamer matroskamux version 1.8.1.1
Writing library                          : GStreamer matroskamux version 1.8.1.1

Video
Count                                    : 311
Count of stream of this kind             : 1
Kind of stream                           : Video
Kind of stream                           : Video
Stream identifier                        : 0
StreamOrder                              : 0
ID                                       : 1
ID                                       : 1
Unique ID                                : 3811409054155698551
Format                                   : VP8
Format/Url                               : http://www.webmproject.org/
Commercial name                          : VP8
Codec ID                                 : V_VP8
Codec ID/Url                             : http://www.webmproject.org/
Codec                                    : V_VP8
Codec                                    : V_VP8
Bit rate                                 : 293486
Bit rate                                 : 293 Kbps
Width                                    : 1920
Width                                    : 1 920 pixels
Height                                   : 1080
Height                                   : 1 080 pixels
Pixel aspect ratio                       : 1.000
Display aspect ratio                     : 1.778
Display aspect ratio                     : 16:9
Frame rate mode                          : VFR
Frame rate mode                          : Variable
Compression mode                         : Lossy
Compression mode                         : Lossy
Delay                                    : 0
Delay                                    : 00:00:00.000
Delay, origin                            : Container
Delay, origin                            : Container
Title                                    : Video
Language                                 : en
Language                                 : English
Language                                 : English
Language                                 : en
Language                                 : eng
Language                                 : en
Default                                  : Yes
Default                                  : Yes
Forced                                   : No
Forced                                   : No

不知道结构差异的原因。仍在调试原因。非常感谢您的帮助。

很高兴您自己发现了这个问题,因为您可以看到Ubuntu中的
stdout
不是有效的JSON字符串,lib中的代码正在执行
JSON.parse
来解析对象,因此它抛出了错误。

我建议您不要使用该库,因为该库本身未经测试。如果您有其他选择,我建议您选择:

安装

$ npm install --save get-video-duration
用法

const { getVideoDurationInSeconds } = require('get-video-duration')

// From a local path...
getVideoDurationInSeconds('video.mov').then((duration) => {
  console.log(duration)
})

// From a URL...
getVideoDurationInSeconds('http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4').then((duration) => {
  console.log(duration)
})

// From a readable stream...

const fs = require('fs')
const stream = fs.createReadStream('video.mov')

getVideoDurationInSeconds(stream).then((duration) => {
  console.log(duration)
})     

很好,您自己发现了这个问题,因为您可以看到Ubuntu中的
stdout
不是有效的JSON字符串,lib中的代码执行
JSON.parse
来解析对象,因此它抛出了错误。

我建议您不要使用该库,因为该库本身未经测试。如果您有其他选择,我建议您选择:

安装

$ npm install --save get-video-duration
用法

const { getVideoDurationInSeconds } = require('get-video-duration')

// From a local path...
getVideoDurationInSeconds('video.mov').then((duration) => {
  console.log(duration)
})

// From a URL...
getVideoDurationInSeconds('http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4').then((duration) => {
  console.log(duration)
})

// From a readable stream...

const fs = require('fs')
const stream = fs.createReadStream('video.mov')

getVideoDurationInSeconds(stream).then((duration) => {
  console.log(duration)
})     

您在两个系统中安装mediainfo的方式是否相同?是。在centos->yum install mediainfo和Ubuntu->apt get install mediainfo中,在两个系统中都以相同的方式安装了mediainfo??是的。在centos->yum install mediainfo和Ubuntu->apt get install mediainfo中,我很高兴它有帮助:)我很高兴它有帮助:)