简体   繁体   中英

Python subprocess.Popen + ffmpeg breaks terminal input

I was writing a module to create random screenshots from a video and used subprocess.Popen to run multiple commands in parallel but this leads to terminal refusing from showing any input once the python program is finished running. But it still accepts most inputs given from the keyboard it just doesn't display it.

Only if I type the reset command terminal starts working fine This happened on ssh with putty and other ssh clients even ssh with powershell on windows and directly running on terminal with VNC

But without ssh directly running the same command on windows ssh works fine and and inputs are visible

here's a gif example for whats happening在此处输入图像描述

and code to replicate it

#!/usr/bin/env python3.8
from subprocess import Popen

def create_screenshots():

    commands = ['ffmpeg -hide_banner -loglevel panic -ss 329  -i "/home/user/file.mkv" -y -vframes 1   "/home/user/file.329.frame.png"',
                'ffmpeg -hide_banner -loglevel panic -ss 312  -i "/home/user/file.mkv" -y -vframes 1   "/home/user/file.312.frame.png"',
                'ffmpeg -hide_banner -loglevel panic -ss 533  -i "/home/user/file.mkv" -y -vframes 1   "/home/user/file.533.frame.png"',
                'ffmpeg -hide_banner -loglevel panic -ss 444  -i "/home/user/file.mkv" -y -vframes 1   "/home/user/file.444.frame.png"',
                'ffmpeg -hide_banner -loglevel panic -ss 411  -i "/home/user/file.mkv" -y -vframes 1   "/home/user/file.411.frame.png"',
                'ffmpeg -hide_banner -loglevel panic -ss 413  -i "/home/user/file.mkv" -y -vframes 1   "/home/user/file.413.frame.png"']
    screenshot_files = []
    processes = [Popen(command, shell=True) for command in commands]
    for process in processes:
        process.wait()
    
    return screenshot_files


create_screenshots()

After weeks of searching finally found the answer to this right after I posted the question

this answer is what I was looking for https://stackoverflow.com/a/59148094

not sure if there is a better way to handle this with Popen but adding -nostdin flag to ffmpeg command fixed the issue I was having

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM