Republishing edited video stream

jasonkc

Member
I'm building an app to use webrtc to capture video from web browser, stream it as RTMP stream, edited the RTMP stream using ffmpeg then forward it to FB or Instagram.

To add to above, I want to re-publish the edited video stream as a new RTMP stream...how do I do that in Flashphoner/webcallserver?
 

Max

Administrator
Staff member
Good day.
To add to above, I want to re-publish the edited video stream as a new RTMP stream...how do I do that in Flashphoner/webcallserver?
You can publish RTMP stream to WCS as described here, using RTMP URL, for example
Code:
rtmp://wcs_server_address:1935/live/test[/ICODE]
The stream named [ICODE]test[/ICODE] will be published on WCS server in this case.
Then, you can republish this stream to Facebook using REST API as described here. For example, with the following paramaters in flashphoner.properties configuration file
[CODE]
rtmp_transponder_stream_name_prefix=
rtmp_transponder_full_url=true
a REST API query should look like this
Code:
POST /rest-api/push/startup HTTP/1.1
Host: 192.168.1.101:8081
Content-Type: application/json

{
    "streamName": "test",
    "rtmpUrl":"rtmps://live-api-s.facebook.com:443/rtmp/facebook_stream_key"
}
where test is a stream name to republish (see example above), facebook_stream_key is Facebook stream key generated by FB Live composer.
Please also read this article
 

jasonkc

Member
I executed the below ffmpeg commands to edit the rtmp stream then publish to FB and another RTMP stream using different stream ID:

apache 29063 29042 8 05:56 ? 00:00:00 /snap/ffmpeg/821/usr/bin/ffmpeg -i rtmp://127.0.0.1:1935/stream/rtmp_dc78 -i /home/apache/logo.png -f image2 -loop 1 -i /home/apache/prod1.png -filter_complex [0:v][1:v]overlay=x=30:y=10[vt];[vt][2:v]overlay=x='if(lte(-w+(t)*100,200),-w+(t)*100+100,200)':y=10 -framerate 25 -r 30 -ar 44100 -c:a libfdk_aac -b:a 20000k -movflags +faststart -preset medium -crf 1 -tune zerolatency -maxrate 20000k -vcodec libx264 -fflags nobuffer -g 60 -max_muxing_queue_size 1024 -f flv pipe:1
apache 29064 29042 13 05:56 ? 00:00:00 /snap/ffmpeg/821/usr/bin/ffmpeg -i pipe:0 -vf drawtext=textfile=/home/apache/sampletext.txt: reload=1: fontcolor=white: fontsize=24: box=1: boxcolor=black@0.5: boxborderw=5: y=((h)-20):x=w-(mod(4*n\,w+tw)-tw/40) -framerate 25 -r 30 -ar 44100 -c:a libfdk_aac -b:a 20000k -movflags +faststart -preset medium -crf 1 -tune zerolatency -maxrate 20000k -vcodec libx264 -fflags nobuffer -g 60 -max_muxing_queue_size 1024 -bsf:a aac_adtstoasc -map 0 -f tee [f=flv:eek:nfail=ignore]rtmps://live-api-s.facebook.com:443/rtmp/182175200247613?s_bl=1&s_hv=0&s_psm=1&s_sc=182175213580945&s_sw=0&s_vt=api-s&a=AbzKVCCHH-FqgPCG|[f=flv:eek:nfail=ignore]rtmp://127.0.0.1:1935/stream/rtmp_rpdc78

But when I used the PLAYER (demo page) to replay the RTMP stream with this new RTMP stream ID, it says 'Session does not exist'!
 

jasonkc

Member
Question now is why I could not play the edited RTMP stream (stream id: rpdc78) via the Player on demo page?
 

Max

Administrator
Staff member
Please clarify, how do you publish a stream to WCS instance?
Also, collect the report while publishing RTMP stream as described here and send using this form.
 

jasonkc

Member
I used ffmpeg to send the edited video to a new RTMP stream with new stream ID (rpdc78 in below example):


apache 29063 29042 8 05:56 ? 00:00:00 /snap/ffmpeg/821/usr/bin/ffmpeg -i rtmp://127.0.0.1:1935/stream/rtmp_dc78 -i /home/apache/logo.png -f image2 -loop 1 -i /home/apache/prod1.png -filter_complex [0:v][1:v]overlay=x=30:y=10[vt];[vt][2:v]overlay=x='if(lte(-w+(t)*100,200),-w+(t)*100+100,200)':y=10 -framerate 25 -r 30 -ar 44100 -c:a libfdk_aac -b:a 20000k -movflags +faststart -preset medium -crf 1 -tune zerolatency -maxrate 20000k -vcodec libx264 -fflags nobuffer -g 60 -max_muxing_queue_size 1024 -f flv pipe:1
apache 29064 29042 13 05:56 ? 00:00:00 /snap/ffmpeg/821/usr/bin/ffmpeg -i pipe:0 -vf drawtext=textfile=/home/apache/sampletext.txt: reload=1: fontcolor=white: fontsize=24: box=1: boxcolor=black@0.5: boxborderw=5: y=((h)-20):x=w-(mod(4*n\,w+tw)-tw/40) -framerate 25 -r 30 -ar 44100 -c:a libfdk_aac -b:a 20000k -movflags +faststart -preset medium -crf 1 -tune zerolatency -maxrate 20000k -vcodec libx264 -fflags nobuffer -g 60 -max_muxing_queue_size 1024 -bsf:a aac_adtstoasc -map 0 -f tee [f=flv:eek:nfail=ignore]rtmps://live-api-s.facebook.com:443/rtmp/182175200247613?s_bl=1&s_hv=0&s_psm=1&s_sc=182175213580945&s_sw=0&s_vt=api-s&a=AbzKVCCHH-FqgPCG|[f=flv:eek:nfail=ignore]rtmp://127.0.0.1:1935/stream/rtmp_rpdc78
 

Max

Administrator
Staff member
The default WCS RTMP URL for streams publishing is
Code:
rtmp://host:1935/live/stream_name
Please also read here for details
You are using
Code:
rtmp://127.0.0.1:1935/stream/rtmp_dc78
So you are probably either do not using WCS at all or using custom WCS configuration.
Have you installed WCS for testing? If not, install it as described here. If yes, collect a report as described here and send using this form.
 

Max

Administrator
Staff member
We checked your logs. Please use this form next time to prevent the info from dropping to spam.
Seems like you are trying to publish a stream named rtmp_rpdc78
Code:
rtmp://127.0.0.1:1935/stream/rtmp_rpdc78
but to play this stream by name rpdc78. These are different streams at servers point. The prefix "rtmp_" is automatically added by default to streams republished via REST API query /push/startup which you do not use. In your case, you should play the stream exactly by name you set to publish it, i.e. rtmp_rpdc78
The second issue is that we do not see in logs neither any tries to publish the stream rtmp_rpdc78, nor any tries to connect for publishing by ffmpeg, just playing rtmp_dc78. Please check your second ffmpeg command to publish the stream, it seems to be failed before establishing connection to WCS.
The third issue is that your flow is too complex. You don't need to republish the original stream dc78 to fetch it by ffmpeg. Just use the URL
Code:
rtmp://127.0.0.1:1935/stream/dc78
in the first ffmpeg command.
We also recommend you to update at least to build 5.2.785 which contains some security and RTMP republishing fixes.
 

jasonkc

Member
I did in fact modify webrtc-as-rtmp-republishing.js & webrtc-as-rtmp-republishing.html files to use
rtmp://127.0.0.1:1935/stream/ instead of rtmp://127.0.0.1:1935/live.....on top of these 2 files, whereas should I edit to synchronize the change?

Meanwhile, I will try to change it back to rtmp://127.0.0.1:1935/live.
 

Max

Administrator
Staff member
It seems you do something incorrect.

Try this way:

1. Publish stream1 using WebRTC Two Way Streaming demo sample.

wss://127.0.0.1:8443
stream1

2. Capture (play) the stream using FFMPEG over RTMP, process it and publish directly to Facebook using RTMPS
Code:
ffmpeg -i rtmp://127.0.0.1:1935/live/stream1 -f rtmps://live-api-s.facebook.com:443/rtmp/182175200247613
That's all.

So you don't need WebRTC as RTMP re-publishing feature if you publish to Facebook directly using FFMPEG.
 

jasonkc

Member
the reason of republish is that i need to add overlays into the original rtmp stream captured from browser via WebRTC using ffmpeg, then re-publish it using a new stream name..however when i did that, it seems the demo Player could not recognize the new stream name...I suspect its due to the fact that this new stream name is not registered.
 

jasonkc

Member
and on top of sending the edited stream to FB, I intend to create a new RTMP stream using a new stream name, so that i can embed a iframe into our website to play the video (don't want to use FB for that).
 

jasonkc

Member
Have a new discovery....i installed another instance of Flashphoner in another server...didn't change any code, and when I tried started a stream in WEBRTC as RTMP demo page, I could not start the stream till I change the URL in RTMP URL from rtmp://localhost:1935/live to rtmp://localhost:1935/stream
 

Max

Administrator
Staff member
This is what you do if you want to play modified stream from WCS server and Facebook simultaneously

1. Publish stream1 using WebRTC Two Way Streaming demo sample.
Code:
wss://127.0.0.1:8443
stream1
2. Capture (play) the stream using FFMPEG over RTMP, process it and publish using another streamName.
Code:
ffmpeg -i rtmp://127.0.0.1:1935/live/stream1 -f rtmp://127.0.0.1:1935/live/stream1-modified
3. Re-publish modified stream to Facebook using REST API
Code:
POST /rest-api/push/startup HTTP/1.1
Host: 192.168.1.101:8081
Content-Type: application/json
{
    "streamName": "stream1-modified",
    "rtmpUrl":"rtmps://live-api-s.facebook.com:443/rtmp/facebook_stream_key"
}
Important!
Configure flashphoner.properties file to get this working:
Code:
rtmp_transponder_stream_name_prefix=
rtmp_transponder_full_url=true
As a result, stream1-modified will be re-published to facebook exactly as full URL rtmps://live-api-s.facebook.com:443/rtmp/facebook_stream_key without additional prefixes.

Then you will be able to play stream1-modified either in Facebook or WCS Player Example.
 

jasonkc

Member
adding the suggested parameters in flashphone.properties file:


#websocket ports
ws.port =8080
wss.port =8443

#client_log_level=DEBUG
#pull_streams=rtmp://rtmp://localhost:1935/live
rtmp_transponder_stream_name_prefix=
rtmp_transponder_full_url=true
[root@ip-10-11-22-78 conf]#


But seeing error when executed ' ffmpeg -i rtmp://127.0.0.1:1935/live/bd96 -f flv rtmp://127.0.0.1:1935/live/rpbd96':

[root@ip-10-11-22-78 conf]# ffmpeg -i rtmp://127.0.0.1:1935/live/bd96 -f flv rtmp://127.0.0.1:1935/live/rpbd96
Error: unable to open display
ffmpeg version n4.1.4 Copyright (c) 2000-2019 the FFmpeg developers
built with gcc 7 (Ubuntu 7.4.0-1ubuntu1~18.04.1)
configuration: --prefix= --prefix=/usr --disable-debug --disable-doc --disable-static --enable-avisynth --enable-cuda --enable-cuvid --enable-libdrm --enable-ffplay --enable-gnutls --enable-gpl --enable-libass --enable-libfdk-aac --enable-libfontconfig --enable-libfreetype --enable-libmp3lame --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libopus --enable-libpulse --enable-sdl2 --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libv4l2 --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libxcb --enable-libxvid --enable-nonfree --enable-nvenc --enable-omx --enable-openal --enable-opencl --enable-runtime-cpudetect --enable-shared --enable-vaapi --enable-vdpau --enable-version3 --enable-xlib
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
libswscale 5. 3.100 / 5. 3.100
libswresample 3. 3.100 / 3. 3.100
libpostproc 55. 3.100 / 55. 3.100
rtmp://127.0.0.1:1935/live/bd96: Input/output error
 
Top