【问题标题】:Node handbrakejs runs the code but doesn't outputNode handbrakejs 运行代码但不输出
【发布时间】:2015-06-26 10:59:47
【问题描述】:

所以我有以下代码:

    var hbjs = require('handbrake-js');
    var encodingOptions = {
        input: media.file.path,
        output:  media.targetDir+"helloWorld.m4v",
        quality: 17,
        optimize: '',
        encoder: "x264"
    };
    hbjs.spawn(encodingOptions)
        .on("begin",function(){
            console.log('begin')
        })
        .on("error", function(err){
            // invalid user input, no video found etc
            console.log('error!')
        })
        .on("progress", function(progress){
            console.log(
                "Percent complete: %s, ETA: %s",
                progress.percentComplete,
                progress.eta
            );
        })
        .on("complete", function (complete) {
            console.log('hello');
        })

此代码运行,完成后我会收到以下控制台消息:

complete

现在是奇怪的部分:

progress 输出未显示在控制台中,当我尝试查找文件时没有文件:S

控制台中没有错误,也没有任何迹象表明出了什么问题?

有人知道这可能是什么吗?

当我调试我的完整功能时,我可以进入this 并获得以下output

    [16:13:41] hb_init: starting libhb thread
HandBrake rev5474 (2014032499) - Linux x86_64 - http://handbrake.fr
4 CPUs detected
Opening uploads/codeschool_13281435328020903.mp4...
[16:13:41] hb_scan: path=uploads/codeschool_13281435328020903.mp4, title_index=1
index_parse.c:191: indx_parse(): error opening uploads/codeschool_13281435328020903.mp4/BDMV/index.bdmv
index_parse.c:191: indx_parse(): error opening uploads/codeschool_13281435328020903.mp4/BDMV/BACKUP/index.bdmv
bluray.c:2356: nav_get_title_list(uploads/codeschool_13281435328020903.mp4) failed
[16:13:41] bd: not a bd - trying as a stream/file instead
libdvdnav: Using dvdnav version 5.0.3
libdvdread: Encrypted DVD support unavailable.
************************************************
**                                            **
**  No css library available. See             **
**  /usr/share/doc/libdvdread4/README.css     **
**  for more information.                     **
**                                            **
************************************************
libdvdread:DVDOpenFileUDF:UDFFindFile /VIDEO_TS/VIDEO_TS.IFO failed
libdvdread:DVDOpenFileUDF:UDFFindFile /VIDEO_TS/VIDEO_TS.BUP failed
libdvdread: Can't open file VIDEO_TS.IFO.
libdvdnav: vm: failed to read VIDEO_TS.IFO
[16:13:41] dvd: not a dvd - trying as a stream/file instead
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'uploads/codeschool_13281435328020903.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    creation_time   : 2014-05-09 02:55:07
    title           : Shaping_Up_With_Angular_JS_Level_2a
    album_artist    : Oliver Tosh
    encoder         : Lavf54.6.100
    description     : This video is about Shaping_Up_With_Angular_JS_Level_2a
  Duration: 00:04:18.10, start: 0.000000, bitrate: 1762 kb/s
    Stream #0.0(eng): Video: h264 (Main), yuvj420p, 1280x720, 1547 kb/s, 29.97 fps, 30 tbr, 30 tbn, 60 tbc
    Metadata:
      creation_time   : 2014-05-09 02:55:07
    Stream #0.1(eng): Audio: aac, 48000 Hz, stereo, fltp, 127 kb/s
    Metadata:
      creation_time   : 2014-05-09 02:55:07
    Stream #0.2(und): Data: rtp  / 0x20707472, 72 kb/s
    Metadata:
      creation_time   : 2014-05-09 03:46:24
    Stream #0.3(und): Data: rtp  / 0x20707472, 9 kb/s
    Metadata:
      creation_time   : 2014-05-09 03:46:24
[16:13:42] scan: decoding previews for title 1
[16:13:42] scan: audio 0x1: aac, rate=48000Hz, bitrate=127426 English (aac) (2.0 ch)

Scanning title 1 of 1, preview 2, 20.00 %[16:13:42] scan: 10 previews, 1280x720, 29.970 fps, autocrop = 0/0/0/0, aspect 16:9, PAR 1:1

Scanning title 1 of 1, preview 10, 100.00 %[16:13:42] libhb: scan thread found 1 valid title(s)
+ title 1:
  + stream: uploads/codeschool_13281435328020903.mp4
  + duration: 00:04:18
  + size: 1280x720, pixel aspect: 1/1, display aspect: 1.78, 29.970 fps
  + autocrop: 0/0/0/0
  + chapters:
    + 1: cells 0->0, 0 blocks, duration 00:04:18
  + audio tracks:
    + 1, English (aac) (2.0 ch) (iso639-2: eng)
  + subtitle tracks:
[16:13:42] 1 job(s) to process
[16:13:42] starting job
[16:13:42] work: mixdown not specified, track 1 setting mixdown Stereo
[16:13:42] work: bitrate not specified, track 1 setting bitrate 160 Kbps
[16:13:42] sync: expecting 7735 video frames
ERROR: Invalid audio codec: 0x100
[16:13:42] render: lost time: 0 (0 frames)
[16:13:42] render: gained time: 0 (0 frames) (0 not accounted for)
[16:13:42] libhb: work result = 0

Encode done!
HandBrake has exited.

【问题讨论】:

  • 完整处理程序中complete参数的内容是什么?
  • @tomtastico 完整参数未定义
  • 这里的问题是这一行:ERROR: Invalid audio codec: 0x100.. 您的源文件的音频是 AAC.. 您在哪个操作系统上?

标签: javascript node.js handbrake handbrake-js


【解决方案1】:

可能值得尝试添加一些缺少的参数?我在 Linux 系统上使用 handbrake-js,它使用这些编码选项按预期执行:

 var encodingOptions = {
        input:  inputFile,
        output: outputFile,
        quality: 17,
        optimize: '',
        encoder: "x264"
    }

然后,你会调用:

hbjs.spawn(encodingOptions)
.on('begin', ...)...;

顺便说一句,您需要监听 on.end 事件,而不是 on.complete。来自文档:

“结束” 在成功完成编码任务时触发。总是跟随一个开始事件,中间有一些进展。

“完成” HandbrakeCLI 干净退出时触发。这并不一定意味着您的编码按计划完成..

【讨论】:

  • 感谢您的回答!如何将 encodingOptions 添加到我的手刹?
  • @MarcRasmussen 我会用一个例子来扩展上面的答案
  • 我试过了,但它仍然没有转换文件,我更新了我的问题,所以它与你所拥有的相匹配 - 请注意,它不会打印出开始
  • 您可以尝试直接使用 handbrake CLI 使用相同的参数对文件进行编码吗?也许手刹直接失败了,而您的问题不一定与 nodejs 包装器有关。
  • 我不太清楚该怎么做(对不起,我是手刹新手)顺便说一句,我在调试完整功能时发现了一条输出消息,我将其发布在我的问题中
【解决方案2】:

如果您使用的是 Ubuntu 14.04? MP4 文件存在已知错误:

https://github.com/75lb/handbrake-js#compatible-platforms

Ubuntu 14.04 通知:自 14.04 起,this reason 在 Ubuntu 上转码为 MP4 失败。

【讨论】:

    【解决方案3】:

    这里的问题是日志中的这一行:

    ERROR: Invalid audio codec: 0x100

    由于某种原因,默认的 AAC 编码器无法在您的系统上运行。为了快速获胜,请从 official list 中选择一个不同的音频编码器,然后在您的 encodingOptions 对象中指定它。像这样:

    var encodingOptions = {
        ...
        aencoder: "mp3"
    };
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-01-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多