Help with FFMPEG + streamer.py

jzvi12

New Member
I read your article https://flashphoner.com/how-to-grab-a-video-from-youtube-and-share-it-via-webrtc-in-real-time/and when I ran the script I got the following error:

Code:
$ sudo python streamer.py https://www.youtube.com/watch?v=JwLJ995H live rtmp://1.2.3.4/myapp
ubuntu@tool:~/yt-live2nginx$ ffmpeg version 4.1.3-patrickz Copyright (c) 2000-2019 the FFmpeg developers
  built with gcc 7 (Ubuntu 7.5.0-3ubuntu1~18.04)
  configuration: --prefix=/home/ubuntu/encoder --disable-shared --enable-static --enable-pthreads --enable-nonfree --enable-version3 --enable-hardcoded-tables --enable-avresample --enable-ffplay --enable-gpl --enable-libmp3lame --enable-libopus --enable-librubberband --enable-libsnappy --enable-libtesseract --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libxvid --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librtmp --enable-libspeex --disable-libjack --disable-indev=jack --enable-libsoxr --enable-openssl --enable-runtime-cpudetect --extra-version=patrickz
  libavutil      56. 22.100 / 56. 22.100
  libavcodec     58. 35.100 / 58. 35.100
  libavformat    58. 20.100 / 58. 20.100
  libavdevice    58.  5.100 / 58.  5.100
  libavfilter     7. 40.101 /  7. 40.101
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  3.100 /  5.  3.100
  libswresample   3.  3.100 /  3.  3.100
  libpostproc    55.  3.100 / 55.  3.100
[youtube] JwLJ995H : Downloading webpage
[youtube] JwLJ995H : Downloading MPD manifest
[download] Destination: -
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'pipe:':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: isommp42
    creation_time   : 2020-05-18T04:00:46.000000Z
  Duration: 02:35:40.02, start: 0.000000, bitrate: N/A
    Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, bt709), 1280x720 [SAR 1:1 DAR 16:9], 869 kb/s, 29.97 fps, 29.97 tbr, 30k tbn, 59.94 tbc (default)
    Metadata:
      creation_time   : 2020-05-18T04:00:46.000000Z
      handler_name    : ISO Media file produced by Google Inc. Created on: 05/17/2020.
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 127 kb/s (default)
    Metadata:
      creation_time   : 2020-05-18T04:00:46.000000Z
      handler_name    : ISO Media file produced by Google Inc. Created on: 05/17/2020.
Output #0, flv, to 'rtmp://1.2.3.4/myapp/live':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: isommp42
    encoder         : Lavf58.20.100
    Stream #0:0(und): Video: h264 (Main) ([7][0][0][0] / 0x0007), yuv420p(tv, bt709), 1280x720 [SAR 1:1 DAR 16:9], q=2-31, 869 kb/s, 29.97 fps, 29.97 tbr, 1k tbn, 30k tbc (default)
    Metadata:
      creation_time   : 2020-05-18T04:00:46.000000Z
      handler_name    : ISO Media file produced by Google Inc. Created on: 05/17/2020.
    Stream #0:1(eng): Audio: aac (LC) ([10][0][0][0] / 0x000A), 44100 Hz, stereo, fltp, 127 kb/s (default)
    Metadata:
      creation_time   : 2020-05-18T04:00:46.000000Z
      handler_name    : ISO Media file produced by Google Inc. Created on: 05/17/2020.
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:1 -> #0:1 (copy)
WriteN, RTMP send error 104 (136 bytes)7kB time=00:00:05.07 bitrate=1319.0kbits/s speed=   1x 
WriteN, RTMP send error 32 (39 bytes)
WriteN, RTMP send error 9 (42 bytes)
av_interleaved_write_frame(): Operation not permitted
[flv @ 0x55a8b6981d00] Failed to update header with correct duration.
[flv @ 0x55a8b6981d00] Failed to update header with correct filesize.
Error writing trailer of rtmp://1.2.3.4/myapp/live: Operation not permitted
frame=  155 fps= 30 q=-1.0 Lsize=     939kB time=00:00:05.17 bitrate=1485.9kbits/s speed=0.999x 
video:862kB audio:81kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
Conversion failed!

ERROR: unable to write data: [Errno 32] Broken pipe

Could you please shed some light?
 
Last edited:

Max

Administrator
Staff member
Good day.
Please make sure that:
- RTMP port is explicitly set in URL: rtmp://1.2.3.4:1935/myapp
- myapp server application is created using add app command as described on this page:
Code:
add app myapp myapp "http://localhost/my_app" -m com.flashphoner.server.client.handler.wcs4.FlashStreamingHandler -c com.flashphoner.server.client.handler.wcs4.FlashStreamingCallbackHandler
Note that the special handlers should be set to myapp to publish RTMP stream.
Please also check the following:
- is RTMP stream from ffmpeg published successfully to your application?
- is RTMP stream from ffmpeg published successfully to standard WCS application rtmp://1.2.3.4:1935/live
 

jzvi12

New Member
resolved the issue by adding more options to the ffmpeg subprocess:

Code:
_ffmpeg_process = subprocess.Popen(('/home/ubuntu/encoder/bin/ffmpeg','-re', '-i', '-', '-profile:v', 'baseline', '-preset', 'ultrafast','-c:v', 'libx264','-pix_fmt', 'yuv420p', '-vf', 'scale=1280:720','-crf','30', '-b:v', '750k', '-maxrate', '750k', '-bufsize', '1500k', '-r', '10', '-c:a', 'aac', '-ac', '2', '-b:a', '128k', '-ar', '44100', '-g', '20', '-f', 'flv', destination + "/" + stream_id), stdin=_youtube_process.stdout)
 
Top