2

I have two av streams, one video and one audio, i'm trying to pipe both as inputs to ffmpeg

os.mkfifo(VIDEO_PIPE_NAME)
os.mkfifo(AUDIO_PIPE_NAME)

ffmpeg_process = subprocess.Popen([    "ffmpeg", "-i", VIDEO_PIPE_NAME, "-i", AUDIO_PIPE_NAME,
 "-listen", "1", "-c:v", "copy", "-c:a", "copy", "-f", "mp4", "-movflags", 
"frag_keyframe+empty_moov", "http://0.0.0.0:8081"], stdin=subprocess.PIPE)

pipe_video = open(VIDEO_PIPE_NAME,'wb')
pipe_audio = open(AUDIO_PIPE_NAME,'wb') #Code stuck here

The code stuck on pipe_audio = open(AUDIO_PIPE_NAME,'wb') line, I'm guessing it is happening because ffmpeg only reads the first/video input and ignore the second/audio input so the pipe is not being read.

If I use only pipe_video and removing -i AUDIO_PIPE_NAME flag from ffmpeg everything works fine, but i only get the video without the audio.

3
  • What happens when you swap the order of those two opens? Commented Apr 13 at 2:55
  • 1
    Can you make it work without Python? From the command line or as a shell script? If yes, then it is a Python question. Otherwise it is more likely a ffmpeg question. Commented Apr 13 at 7:39
  • 1
    My guess would rather be that it tries to read a bit of the video input (at least the header, if any) before even trying to open audio input (I can't tell why. But there is no reason why it shouldn't do that neither. There is no guarantee about the order of operations). So you need to feed both files. Either with a thread/process on python side to feed data to both audio and video as soon as you have some (and ffpmeg is ready to read it). Or with some python equivalent of select/poll (I suppose that exists. Never had to know so far. Last time I did such thing, it was in C) Commented Apr 13 at 10:35

1 Answer 1

1

I can confirm chrslg's comment under the OP. Placing each pipe's open() call in its own write thread should resolve your issue.

I'm nearing to release a new version of ffmpegio to introduce this exact feature, and it works well.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.