python - 用subprocess terminate沒法結束進程 求教
問題描述
我想用python采集視頻,打算用ffmpeng.exe 進行視頻錄制,然后定時自動結束,我是個小白,命令不復雜,就是用subprocess.Popen 啟動ffmpeng命令,進行視頻采集,保存為mp4,我在cmd下面已經測試好了,命令無問題,并且用python里面測試也可以錄制,問題就是沒法結束。。我用subprocess.kill結束了進程,但僅僅是結束了cmd進行,cmd開啟的ffmpeg還是在繼續工作,我不知道改怎么結束他產生的進程。。
cmd = ’’’ffmpeg1.exe -i 'rtmp://123.123.123.132/live/tv22 live=1' -acodec libmp3lame -vcodec libx264 -y 3.mkv’’’cc=subprocess.Popen(cmd2,shell=True)print(cc.pid)time.sleep(15)cc.terminate()
用terminat 或者kill都沒法結束進程,只能結束subprocess.Popen產生的cmd進程,cmd執行命令產生的ffmpeg1.exe進程沒法停止,如果有仿ctrl+c的終止方法也行,求大神幫忙看看,我后來測試了ping 127.0.0.1 ,同樣cmd可以結束,ping.exe無法結束
問題解答
回答1:其實你自身都已經得出結果, 當你殺掉subprocess.Popen只能殺死cmd, 卻不能殺死ffmpeg1, 所以試下直接用windows的命令去殺死吧
kill_command = ’taskkill -f ffmpeg1.exe’cc=subprocess.Popen(kill_command ,shell=True)....(自己補充)
相關文章:
1. python - 數據與循環次數對應不上2. python - 如何對列表中的列表進行頻率統計?3. thinkPHP5中獲取數據庫數據后默認選中下拉框的值,傳遞到后臺消失不見。有圖有代碼,希望有人幫忙4. python小白 關于類里面的方法獲取變量失敗的問題5. django - Python error: [Errno 99] Cannot assign requested address6. javascript - 如何用最快的速度C#或Python開發一個桌面應用程序來訪問我的網站?7. python - Scrapy如何得到原始的start_url8. python小白,關于函數問題9. linux運維 - python遠程控制windows如何實現10. 求救一下,用新版的phpstudy,數據庫過段時間會消失是什么情況?
