Skip to content

Instantly share code, notes, and snippets.

@mekya
Created November 18, 2020 11:32
Show Gist options
  • Save mekya/904890d4a9ce016fc7cfd405851d5d62 to your computer and use it in GitHub Desktop.
Save mekya/904890d4a9ce016fc7cfd405851d5d62 to your computer and use it in GitHub Desktop.
Multi Track Publish to the Server
#!/bin/bash
#login
echo "login"
SERVER_ADDR=172.16.110.178
APP_NAME=WebRTCAppEE
FILE_1=~/git/Ant-Media-Server/src/test/resources/test.flv #Clash_360z.mp4
FILE_2=~/git/Ant-Media-Server/src/test/resources/test_video_360p.flv #Carz.mp4
STREAM_ID_1=stream_multi_track
STREAM_ID_2=stream_subtrack
CHECK_STREAM_EXIST='curl -sb -i -X GET -H "Accept: Application/json" -H "Content-Type: application/json" http://$SERVER_ADDR:5080/$APP_NAME/rest/v2/broadcasts/$STREAM_ID_1'
STREAM_ID=$(eval $CHECK_STREAM_EXIST | jq --raw-output '.streamId')
if [[ $STREAM_ID != $STREAM_ID_1 ]];
then
echo "create"
CREATE_COMMAND1="curl -sb -i -X POST -H \"Accept: Application/json\" -H \"Content-Type: application/json\" http://$SERVER_ADDR:5080/$APP_NAME/rest/v2/broadcasts/create -d '{\"streamId\":\"$STREAM_ID_1\"}'"
#create stream1 and stream2
STREAM_ID_1=$(eval $CREATE_COMMAND1 | jq --raw-output '.streamId')
echo "stream 1:"$STREAM_ID_1
CREATE_COMMAND2="curl -sb -i -X POST -H \"Accept: Application/json\" -H \"Content-Type: application/json\" http://$SERVER_ADDR:5080/$APP_NAME/rest/v2/broadcasts/create -d '{\"streamId\":\"$STREAM_ID_2\"}'"
STREAM_ID_2=$(eval $CREATE_COMMAND2 | jq --raw-output '.streamId')
echo "stream 2:$STREAM_ID_2"
#add subtract
echo "subtrack"
curl -i -X POST -H "Accept: Application/json" -H "Content-Type: application/json" "http://$SERVER_ADDR:5080/$APP_NAME/rest/v2/broadcasts/$STREAM_ID_1/subtrack?id=$STREAM_ID_2"
fi
sleep 1
#start stream1
ffmpeg -re -i $FILE_1 -codec copy -f flv rtmp://$SERVER_ADDR/$APP_NAME/$STREAM_ID_1 &
sleep 3
#start stream2
ffmpeg -re -i $FILE_2 -codec copy -f flv rtmp://$SERVER_ADDR/$APP_NAME/$STREAM_ID_2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment