2

So I have the following code:

    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');
        })

This code runs and once complete I get the following console message:

complete

Now here is the odd part:

The progress output is not displayed in the console and when I attempt to find the file there is no file :S

There are no errors in the console and nothing indicating that something went wrong?

Does anyone have any ideas of what this might be?

When i debug my complete function i am able to go into this and get the following 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.
Lloyd
  • 8,204
  • 2
  • 38
  • 53
Marc Rasmussen
  • 19,771
  • 79
  • 203
  • 364

3 Answers3

2

Might be worth trying to add some missing parameters? I use handbrake-js on Linux system and it performs as expected with these encoding options:

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

Then, you will call:

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

BTW, you need to listen to the on.end event, and not the on.complete. From the documentation:

"end" Fired on successful completion of an encoding task. Always follows a begin event, with some progress in between.

"complete" Fired when HandbrakeCLI exited cleanly. This does not necessarily mean your encode completed as planned..

Luis Delgado
  • 3,644
  • 4
  • 34
  • 54
  • thank you for your answer! how do i add the encodingOptions to my Handbrake? – Marc Rasmussen Jun 26 '15 at 12:59
  • @MarcRasmussen I'll expand the answer above with an example – Luis Delgado Jun 26 '15 at 13:17
  • I tried this however it still does not convert the file ive updated my question so it matches what you have - Note that it does not print out begin – Marc Rasmussen Jun 26 '15 at 13:55
  • Can you try to encode the file directly with handbrake CLI, using the same parameters? Perhaps something is failing directly on handbrake and your problem is not necessarily related to the nodejs wrapper. – Luis Delgado Jun 26 '15 at 14:09
  • im not quite sure how to do that (sorry im new to handbrake) btw i found an output message when debugging my complete function ive posted it in my question – Marc Rasmussen Jun 26 '15 at 14:12
  • it seems like it cannot find the file however if i use a completely direct path like '/var/www/myproject/folder/file.mp4' it still does not work?! – Marc Rasmussen Jun 26 '15 at 14:22
  • actually it seems that it is trying to convert it however it is just not succeeding – Marc Rasmussen Jun 26 '15 at 14:30
  • Here's your problem: 'ERROR: Invalid audio codec: 0x100'. Handbrake can't find an audio codec to proceed and is therefore exiting the process. You're going to have to check the handbrake documentation to see if the audio codec your file is using is supported. – Luis Delgado Jun 26 '15 at 15:14
  • BTW, 2 months ago I migrated our app from handbrake to ffmpeg. There's a nodejs wrapper for it as well. Ffmpeg has extensive support for a ton of video and audio formats, might be worth checking if your format is not supported by handbrake. – Luis Delgado Jun 26 '15 at 15:26
1

If you are using Ubuntu 14.04? there is a known error with MP4 files:

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

Ubuntu 14.04 notice: Transcoding to MP4 fails on Ubuntu since 14.04 for this reason.

tomtastico
  • 6,136
  • 2
  • 23
  • 28
0

the issue here is this line from the log:

ERROR: Invalid audio codec: 0x100

For some reason, the default AAC encoder is not working on your system.. as a quick win, choose a different audio encoder from the official list then specify it in your encodingOptions object.. something like this:

var encodingOptions = {
    ...
    aencoder: "mp3"
};
Lloyd
  • 8,204
  • 2
  • 38
  • 53