2

I'm currently on a project to grab an IP camera video and streaming it to a website. This camera is located in the beach, so the idea is to send the streaming signal to a server and from the server to the client devices.

For this I’m using a Raspberry Pi 3 B+ on the beach that is in charge to grab the signal from the camera and send it to the server.

I’m using FFmpeg to convert the RTSP signal into HLS segments, and then store them on a server, then use VideoJS 7.4.1 to play the segments in the browsers.

This is the code in FFmpeg that I’m using:

ffmpeg -i  rtsp://CameraIP/onvif1 -c:v libx264  -preset veryfast -crf 17 -an -hls_time 40 -hls_list_size 5 ftp://ServerIP/stream/abc.m3u8

This works very well, but the problem is that the Raspberry uses about 70% of CPU usage for this task, and I have to reduce the quality because of that, the good news is that the camera signal is already in h264 format (says h264 native) so I try instead of converting the video codecs to libx264, just copy the stream using this command:

ffmpeg -i  rtsp://cameraIP/onvif1 -c:v copy -an -hls_time 40 -hls_list_size 5 ftp://ServerIP/stream/abc.m3u8

Using, this command the CPU usage drop down to 2 or 3% so that is great, I could improve the quality or even better, get a better camera. But the problem is that is not working on mobiles (try it in FireFix, Chrome and Safari, in both operating systems, android and iOs), VideoJS shows this error:

The media playback was aborted due to a corruption problem or because the media used features your browser did not support

All the browsers are up to date.

This is the log copying the video codec, no encoder used

ffmpeg version 3.2.12-1~deb9u1+rpt1 Copyright (c) 2000-2018 the FFmpeg developers built with gcc 6.3.0 (Raspbian 6.3.0-18+rpi1+deb9u1) 20170516
  configuration: --prefix=/usr --extra-version='1~deb9u1+rpt1' --toolchain=hardened --libdir=/usr/lib/arm-linux-gnueabihf --incdir=/usr/include/arm-linux-gnueabihf --enable-gpl --disable-stripping --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libebur128 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-omx --enable-omx-rpi --enable-mmal --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libiec61883 --arch=armhf --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared
  libavutil      55. 34.101 / 55. 34.101
  libavcodec     57. 64.101 / 57. 64.101
  libavformat    57. 56.101 / 57. 56.101
  libavdevice    57.  1.100 / 57.  1.100
  libavfilter     6. 65.100 /  6. 65.100
  libavresample   3.  1.  0 /  3.  1.  0
  libswscale      4.  2.100 /  4.  2.100
  libswresample   2.  3.100 /  2.  3.100
  libpostproc    54.  1.100 / 54.  1.100
Guessed Channel Layout for Input Stream #0.1 : mono
Input #0, rtsp, from 'rtsp://CameraIP/onvif1':
  Metadata:
    title           : H.264 Video, RtspServer_0.0.0.2
  Duration: N/A, start: 0.000000, bitrate: N/A
    Stream #0:0: Video: h264 (High), yuvj420p(pc, bt709, progressive), 1280x960, 15 tbr, 90k tbn, 180k tbc
    Stream #0:1: Audio: pcm_alaw, 8000 Hz, mono, s16, 64 kb/s
[hls @ 0xc52be0] Opening 'ftp://ServerIP/stream/abc0.ts' for writing
Output #0, hls, to 'ftp://ServerIP/stream/abc.m3u8':
  Metadata:
    title           : H.264 Video, RtspServer_0.0.0.2
    encoder         : Lavf57.56.101
    Stream #0:0: Video: h264 (High), yuvj420p(pc, bt709, progressive), 1280x960, q=2-31, 15 tbr, 90k tbn, 90k tbc
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
Press [q] to stop, [?] for help

This is the FFmpeg log for convertir h264 into libx264

ffmpeg version 3.2.12-1~deb9u1+rpt1 Copyright (c) 2000-2018 the FFmpeg developers built with gcc 6.3.0 (Raspbian 6.3.0-18+rpi1+deb9u1) 20170516
  configuration: --prefix=/usr --extra-version='1~deb9u1+rpt1' --toolchain=hardened --libdir=/usr/lib/arm-linux-gnueabihf --incdir=/usr/include/arm-linux-gnueabihf --enable-gpl --disable-stripping --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libebur128 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-omx --enable-omx-rpi --enable-mmal --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libiec61883 --arch=armhf --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared
  libavutil      55. 34.101 / 55. 34.101
  libavcodec     57. 64.101 / 57. 64.101
  libavformat    57. 56.101 / 57. 56.101
  libavdevice    57.  1.100 / 57.  1.100
  libavfilter     6. 65.100 /  6. 65.100
  libavresample   3.  1.  0 /  3.  1.  0
  libswscale      4.  2.100 /  4.  2.100
  libswresample   2.  3.100 /  2.  3.100
  libpostproc    54.  1.100 / 54.  1.100
Guessed Channel Layout for Input Stream #0.1 : mono
Input #0, rtsp, from 'rtsp://CameraIP/onvif1':
  Metadata:
    title           : H.264 Video, RtspServer_0.0.0.2
  Duration: N/A, start: 0.000000, bitrate: N/A
    Stream #0:0: Video: h264 (High), yuvj420p(pc, bt709, progressive), 1280x960, 15 tbr, 90k tbn, 180k tbc
    Stream #0:1: Audio: pcm_alaw, 8000 Hz, mono, s16, 64 kb/s
No pixel format specified, yuvj420p for H.264 encoding chosen.
Use -pix_fmt yuv420p for compatibility with outdated media players.
[libx264 @ 0x814a50] using cpu capabilities: ARMv6 NEON
[libx264 @ 0x814a50] profile High, level 3.2
[hls @ 0x6addd0] Opening 'ftp://ServerIP/stream/abc0.ts' for writing
Output #0, hls, to 'ftp://ServerIP/stream/abc.m3u8':
  Metadata:
    title           : H.264 Video, RtspServer_0.0.0.2
    encoder         : Lavf57.56.101
    Stream #0:0: Video: h264 (libx264), yuvj420p(pc), 1280x960, q=-1--1, 15 fps, 90k tbn, 15 tbc
    Metadata:
      encoder         : Lavc57.64.101 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
Press [q] to stop, [?] for help

So it seems that the mobile browsers can't support h264 native, it have to be converted to libx264, so there is any other way to solve this, maybe another encoder that is compatible with mobile browsers?

1

"No pixel format specified, yuvj420p for H.264 encoding chosen. Use -pix_fmt yuv420p for compatibility with outdated media players."

Try adding -pix_fmt yuv420p to your command to see if that helps playback compatibility.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.