search

Home  >  Q&A  >  body text

python - Using ffmpeg to capture video, the process cannot be ended using terminate

I want to use ffmpeg to capture videos and the timing will end automatically. I am a novice and the command is not complicated. I just use subprocess.Popen to start the ffmpeng command to capture the video and save it as mp4. I have tested it under cmd. The command There is no problem, and the test can also be recorded using python. The problem is that it cannot be ended. . I used subprocess.kill to end the process, but it only ended cmd. ffmpeg started by cmd still continued to work. I don't know how to end the process it generated. . .

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()

You can’t end it with terminat or kill. You can only end the cmd process. The generated ffmpeg1.exe process cannot be stopped.
If there is a termination method that imitates ctrl c, please help.
I later tested ping 127.0.0.1 and found that cmd could be terminated but ping.exe could not be terminated

曾经蜡笔没有小新曾经蜡笔没有小新2765 days ago1170

reply all(1)I'll reply

  • 扔个三星炸死你

    扔个三星炸死你2017-06-14 10:53:23

    Um... I just saw a duplicate question, so I'll copy the answer...

    Try to kill directly using the windows command

    kill_command = 'taskkill -f ffmpeg1.exe'
    cc=subprocess.Popen(kill_command ,shell=True)
    ....(自己补充)

    reply
    0
  • Cancelreply