1- Mix . install ( [ :ex_rtmp , :ex_flv ] )
1+ Mix . install ( [ :ex_rtmp ] )
22
33defmodule Handler do
44 use ExRTMP.Server.Handler
@@ -13,27 +13,28 @@ defmodule Handler do
1313 end
1414
1515 @ impl true
16- def handle_publish ( _stream_id , stream_key , state ) do
16+ def handle_publish ( stream_key , state ) do
1717 file = File . open! ( "output_#{ state . app } _#{ stream_key } .flv" , [ :write , :binary , :raw ] )
1818 IO . binwrite ( file , [ ExFLV.Header . serialize ( ExFLV.Header . new ( 1 , true , true ) ) , << 0 :: 32 >> ] )
1919 { :ok , % { state | file: file } }
2020 end
2121
2222 @ impl true
23- def handle_audio_data ( _stream_id , timestamp , payload , state ) do
24- tag = % ExFLV.Tag { type: :audio , timestamp: timestamp , data: iodata }
23+ def handle_audio_data ( timestamp , payload , state ) do
24+ tag = % ExFLV.Tag { type: :audio , timestamp: timestamp , data: payload }
2525 write_tag ( tag , state )
2626 end
2727
2828 @ impl true
29- def handle_video_data ( _stream_id , timestamp , iodata , state ) do
29+ def handle_video_data ( timestamp , iodata , state ) do
3030 tag = % ExFLV.Tag { type: :video , timestamp: timestamp , data: iodata }
3131 write_tag ( tag , state )
3232 end
3333
3434 @ impl true
35- def handle_delete_stream ( _stream_id , state ) do
35+ def handle_delete_stream ( state ) do
3636 File . close ( state . file )
37+ :close
3738 end
3839
3940 defp write_tag ( tag , state ) do
@@ -43,7 +44,7 @@ defmodule Handler do
4344 end
4445end
4546
46- { :ok , pid } = ExRTMP.Server . start_link ( port: 1935 , handler: Handler )
47+ { :ok , pid } = ExRTMP.Server . start_link ( port: 1935 , handler: Handler , demux: false )
4748Process . monitor ( pid )
4849
4950receive do
0 commit comments