arut / nginx-rtmp-module

NGINX-based Media Streaming Server
http://nginx-rtmp.blogspot.com
BSD 2-Clause "Simplified" License
13.45k stars 3.51k forks source link

transcoding rtmp to file? #460

Open JulianZhao opened 10 years ago

JulianZhao commented 10 years ago

Sorry for my poor english, I'm newbie for streaming and rtmp, I'm using the RtmpPublisher.swf (in rtmp-module src) to publish the stream, and the input stream is h264 & speex. I want to get stream recorded in MP4 format file (h264 & aac). I know that I can use "record all" then I get one FLV file, then I can use "exec_record_done" to transcode this FLV into MP4. I tried this and it's worked. The question is : The time spent is more longer when the flv file is more larger, I want to get the MP4 file quickly, so I think if I can use exec (exec_push) to do this, I use commands like this: exec /usr/local/bin/ffmpeg -i rtmp://localhost/live/$name -vcodec copy -acodec libfaac -ar 44100 -ac 1 /tmp/hls/$name.mp4 2>>/tmp/hls/ffmpeg-push.log;

I can see the MP4 file generated, but it's a wrong file and can't be played. The output is :

[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7fb08c01f400] moov atom not found0/0 test.mp4: Invalid data found when processing input

Can exec_push do this for me? What's wrong there?

arut commented 10 years ago

exec_push terminates the child process when stream ends. With mp4 that can be a problem since ffmpeg needs to write mp4 metadata after it's done writing frames. Default signal sent to the process is SIGKILL. Please try other signals which do not actually kill ffmpeg. https://github.com/arut/nginx-rtmp-module/wiki/Directives#exec_kill_signal

JulianZhao commented 10 years ago

Great thanks to you!

I searched the web and know I can use SIGINT, I tried and it's worked. The mp4 file can be played now.

another problem: the ffmpeg process is not terminated quickly, it takes a little time (30 seconds I guess) after I stop publishing. I guess it depends on the machine performance and transcoding parameters, I need to do more research and try (I really do not quite familiar with this).

If you can give suggestions points better. Thanks again.