citolen / goproh4

Node.js module to control a GoPro Hero 4
MIT License
103 stars 24 forks source link

Rejection [21] #11

Closed joelongstreet closed 8 years ago

joelongstreet commented 8 years ago

When running the live stream example, I get the following error: Potentially unhandled rejection [21] null (WARNING: non-Error used)

I noticed this, but I have ffmpeg installed.

citolen commented 8 years ago

Hello Joe,

I'm not sure where it comes from with only this information, but it's probably because the command to start the stream didn't work properly.

Can you make sure that you are connected to the GoPro's wifi. Open http://10.5.5.9/gp/gpControl/execute?p1=gpStream&c1=restart to check.

Otherwise can you tell me more about the GoPro you are using ? Were you recording at the time you tried to livestream ?

joelongstreet commented 8 years ago

Thanks for getting back to me.

Looks like this might be a problem with the goPro I'm using. Opening the URL gives me a JSON blob with a little message:

{
    version: "3.00",
    path_info: "/execute",
    query_string: "p1=gpStream&c1=restart",
    error_code: -3,
    error_msg: "unknown request",
    function: "control_router",
    line: 461
}

Changing the c1 query param to start or stop gives me the same message. I googled around and found this thread - https://m.reddit.com/r/gopro/comments/2md8hm/how_to_livestream_from_a_gopro_hero4/cpncnbt

Looks like an update to the firmware is all that's needed. I'll give it a try and post the results back here.

joelongstreet commented 8 years ago

The firmware update appears to have worked, but the images in the example are a bit broken. See below:

I'm guessing this might have something to do with the stream headers? Can you explain how the following work in your example:

  var streamHeader = new Buffer(8);

  streamHeader.write('jsmp');
  streamHeader.writeUInt16BE(320, 4);
  streamHeader.writeUInt16BE(240, 6);

Thanks again for your help

screen shot 2016-02-26 at 2 32 16 pm

citolen commented 8 years ago

Indeed it's quite broken.

The stream headers should be right, I just tried it again and ffplay is guessing the resolution of 320x240, values should be good.

In the example what it does is create a buffer of 8 bytes. From 0 to 3 it's [ j, s, m, p ]. Then the width on 2 bytes and the height on the two last one. This is taken from an example somewhere I don't remember.

Can you try restarting the GoPro and try again. I got this once and restarting it was enough.

joelongstreet commented 8 years ago

Thanks for your help. I restarted the go pro a few times but had no luck in the frames getting fixed. I thought that possibly the frames were getting pushed to the client too quickly and tried to limit the throughput with a timeout, but it didn't work.

I did notice that the ffmpeg stdout gives me a few warnings.

[mpegts @ 0x7fadd3000000] Could not find codec parameters for stream 2 (Unknown: none ([128][0][0][0] / 0x0080)): unknown codec
Consider increasing the value for the 'analyzeduration' and 'probesize' options
[swscaler @ 0x7fadd2023e00] deprecated pixel format used, make sure you did set range correctly

I added the analyzeduration and probesize flags but wasn't sure what the values should be. Do I need to install anything outside of ffmpeg? I'm not sure what codec it's warning about.

citolen commented 8 years ago

Hum ok, maybe your GoPro outputs at a different resolution or that could definitely be a codec problem. Indeed you might need something more than ffmpeg that I already had when testing. Let's try to find what it is.

When you do:

node livestream.js

Here is the output of the ffmpeg part I get, you could compare to see if there is any difference with yours:

Input #0, mpegts, from 'udp://10.5.5.9:8554':
  Duration: N/A, start: 0.500500, bitrate: N/A
  Program 1
    Stream #0:0[0x1011]: Video: h264 (Main) ([27][0][0][0] / 0x001B), yuvj420p, 320x240 [SAR 1:1 DAR 4:3], 29.97 fps, 29.97 tbr, 90k tbn, 59.94 tbc
    Stream #0:1[0x1100]: Audio: aac ([15][0][0][0] / 0x000F), 0 channels, fltp
    Stream #0:2[0x200]: Unknown: none ([128][0][0][0] / 0x0080)
Please use -b:a or -b:v, -b is ambiguous
Stream Connected: ::ffff:127.0.0.1:38813 size: 320x240
Output #0, mpeg1video, to 'http://127.0.0.1:8082/publish':
  Metadata:
    encoder         : Lavf55.0.100
    Stream #0:0: Video: mpeg1video, yuv420p, 320x240 [SAR 1:1 DAR 4:3], q=2-31, 800 kb/s, 90k tbn, 30 tbc
Stream mapping:
  Stream #0:0 -> #0:0 (h264 -> mpeg1video)
joelongstreet commented 8 years ago

Huh, looks like my output is slightly different

ffmpeg version 2.8.5 Copyright (c) 2000-2016 the FFmpeg developers
  built with Apple LLVM version 7.0.2 (clang-700.1.81)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/2.8.5 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-opencl --enable-libx264 --enable-libmp3lame --enable-libvo-aacenc --enable-libxvid --enable-libvpx --enable-vda
  libavutil      54. 31.100 / 54. 31.100
  libavcodec     56. 60.100 / 56. 60.100
  libavformat    56. 40.101 / 56. 40.101
  libavdevice    56.  4.100 / 56.  4.100
  libavfilter     5. 40.101 /  5. 40.101
  libavresample   2.  1.  0 /  2.  1.  0
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  2.101 /  1.  2.101
  libpostproc    53.  3.100 / 53.  3.100
[mpegts @ 0x7fadd3000000] Could not find codec parameters for stream 2 (Unknown: none ([128][0][0][0] / 0x0080)): unknown codec
Consider increasing the value for the 'analyzeduration' and 'probesize' options
Input #0, mpegts, from 'udp://10.5.5.9:8554':
  Duration: N/A, start: 0.000000, bitrate: N/A
  Program 1
    Stream #0:0[0x1011]: Video: h264 (Main) ([27][0][0][0] / 0x001B), yuvj420p(pc, bt709), 432x240 [SAR 1:1 DAR 9:5], 29.97 fps, 29.97 tbr, 90k tbn, 59.94 tbc
    Stream #0:1[0x1100]: Audio: aac (LC) ([15][0][0][0] / 0x000F), 48000 Hz, stereo, fltp, 130 kb/s
    Stream #0:2[0x200]: Unknown: none ([128][0][0][0] / 0x0080)
Please use -b:a or -b:v, -b is ambiguous
[swscaler @ 0x7fadd2023e00] deprecated pixel format used, make sure you did set range correctly
Stream Connected: ::ffff:127.0.0.1:57783 size: 320x240
Output #0, mpeg1video, to 'http://127.0.0.1:8082/publish':
  Metadata:
    encoder         : Lavf56.40.101
    Stream #0:0: Video: mpeg1video, yuv420p, 432x240 [SAR 1:1 DAR 9:5], q=2-31, 800 kb/s, 30 fps, 30 tbn, 30 tbc
    Metadata:
      encoder         : Lavc56.60.100 mpeg1video
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> mpeg1video (native))
Press [q] to stop, [?] for help

On closer examination of this output I noticed Stream #0:0: Video: mpeg1video, yuv420p, 432x240 [SAR 1:1 DAR 9:5], q=2-31, 800 kb/s, 30 fps, 30 tbn, 30 tbc. Changing the width and height on the header output to 432 and 240 fixed everything. Thanks for your help!

By the way, everything else has worked perfectly. Nice work with the library.

shealan commented 6 years ago

Setting the size to 640x480 on the GoPro Hero Black fixed the glitchy video issue for me. Thanks for the pointers.