I'm trying to use python to feed the results of ffmpeg into a pipeline, and then I can use this pipeline for subsequent operations (such as rtmp streaming). I've written the correct command, but I don't know how to accomplish this with Python.
I wrote the following code in the Shell, it can run correctly.
ffmpeg -re -i '2023-02-16_21:02:50.mp4' -f mpegts -c:v copy -c:a aac -vbsf h264_mp4toannexb pipe:1.ts | cat >> push
When I'm trying to do the above in Python, I'm getting an error.
cat: '>>': No such file or directory
Here is my python code.
command = [
'docker',
'run',
'-v',
f'{cwd}:{cwd}',
'-w',
f'{cwd}',
'jrottenberg/ffmpeg',
'-re',
'-i', f'{video_path}',
'-f', 'mpegts',
'-c:v', 'copy',
'-c:a', 'aac',
'-vbsf', 'h264_mp4toannexb',
'pipe:1.ts',
]
pa = subprocess.Popen(
command,
stdout = subprocess.PIPE,
stderr = error_file
)
command = [
'cat',
'>>',
f'{pipe_name}'
]
with pa.stdout:
pb = subprocess.Popen(
command,
stdin = pa.stdout,
stdout = error_file,
stderr = error_file
)