ffmpeg linux后臺(tái)運(yùn)行
前臺(tái)運(yùn)行ffmpge就不說,指令一敲ok瑞信。但是如果給指令加上nohup厉颤,后面加&號(hào)碼,例如
nohup ./ffmpeg -re -rtsp_transport tcp -i "rtsp://admin:123456@99.99.99.75:554/h264/ch1/main/av_stream?videoCodecType=H.264" -vcodec copy -acodec aac -f flv -y rtmp://122.51.252.37/live/livestream &
ffmpg就會(huì)自動(dòng)掛起凡简。
原因:
It hangs because after a certain point it can not write to it's output pipe any longer.
When you run a process it has 3 opened pipes for: stdin, stdout and stderr. A pipe has a memory buffer ( 4KB on Linux ) that can hold up to a certain amount of data and the next write operation will pause until some data is read from the other side of the pipe.
Since you never read from stdout and stderr of your child process and FFMpeg outputs quite a lot it will hang at some point.
(掛起是因?yàn)樵谀骋稽c(diǎn)之后逼友,它不能再寫入它的輸出管道了。 當(dāng)你運(yùn)行一個(gè)進(jìn)程時(shí)秤涩,它有3個(gè)打開的管道:stdin帜乞,stdout和stderr。管道具有內(nèi)存緩沖區(qū)(Linux上4KB)筐眷,可以容納一定量的數(shù)據(jù)黎烈,下一個(gè)寫操作將暫停,直到從管道的另一側(cè)讀取一些數(shù)據(jù)匀谣。 因?yàn)槟銖奈磸膕tdout和stderr讀取你的子進(jìn)程和FFMpeg輸出相當(dāng)多照棋,它會(huì)掛起)
解決方式
nohup ./ffmpeg -re -rtsp_transport tcp -i "rtsp://admin:123456@99.99.99.75:554/h264/ch1/main/av_stream?videoCodecType=H.264" -vcodec copy -acodec aac -f flv -y rtmp://122.51.252.37/live/livestream 1>/dev/null 2>&1 &
1 代表標(biāo)準(zhǔn)輸出
2 代表標(biāo)準(zhǔn)錯(cuò)誤
1>/dev/null 把標(biāo)準(zhǔn)輸出導(dǎo)入到null設(shè)備,也就是消失不見,如果要重定向到某個(gè)文件武翎,可以1>1.txt
2>&1 把標(biāo)準(zhǔn)錯(cuò)誤也導(dǎo)入到標(biāo)準(zhǔn)輸出同樣的地方