0

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
    )
  • 2
    `>>` in the shell command `cat >>filename` isn't an argument to `cat`; instead, it's an instruction to the shell about where to direct `cat`'s stdout. You should just have `command = [ 'cat' ]` with `stdout = open(pipe_name, 'a')`, instead of `command = ['cat', '>>', pipe_name]` – Charles Duffy Feb 16 '23 at 13:18
  • @CharlesDuffy Thanks for your answer, you helped me solve this problem. – Eric Palmer Feb 16 '23 at 13:23
  • (Of course, you could also have ffmpeg's stdout go direct to the pipe too, via the same mechanism; I'm not sure that `cat` is serving much of a useful purpose here) – Charles Duffy Feb 16 '23 at 13:24

0 Answers0