leandromoreira / ffmpeg-libav-tutorial

FFmpeg libav tutorial - learn how media works from basic to transmuxing, transcoding and more. Translations: πŸ‡ΊπŸ‡Έ πŸ‡¨πŸ‡³ πŸ‡°πŸ‡· πŸ‡ͺπŸ‡Έ πŸ‡»πŸ‡³ πŸ‡§πŸ‡·
https://github.com/leandromoreira/ffmpeg-libav-tutorial
BSD 3-Clause "New" or "Revised" License
9.78k stars 937 forks source link

"Broken pipe" on av_interleaved_write_frame when used to stream #119

Closed jimfcarroll closed 1 year ago

jimfcarroll commented 1 year ago

This example has been fantastic and I've used it as a guide to build a very robust system. The system decodes and remuxes almost anything to anything, including streaming rtmp to my server. I ran into an issue that I was hoping someone might point me in the right direction to resolve. My apologies if this is the wrong place for this.

I've recently been adding the ability to transcode/recode a stream of images when I ran across the problem described below. In order to see if it was something specific to my implementation I went back to this example and reproduced the issue using 3_transcode.c

I can transcode an mp4, minus audio, to an rtmp server, without a problem, using the following ffmpeg command line:

ffmpeg -i input.mp4 -vcodec libx264 -an -f flv "rtmp://localhost:1935/live/feedly-id"

However, when I do this with a modified 3_transcode.c I have a problem. I modified the code as follows:

  1. disabled the audio handling
  2. pass "flv" as the third parameter to avformat_alloc_output_context2
  3. set the StreamingParams to sp.video_codec = "libx264"; with no other parameters.

av_interleaved_write_frame eventually (a few frames seem to go) fails with a -32, Broken pipe.

If instead I set the destination to /tmp/out.flv it works and I can play the resulting file with VLC.

Also, I can THEN send /tmp/out.flv to the rtmp server using -vcodec copy and it ALSO works.

If anyone can point me to a resource that will allow me to get streaming to work, I'd greatly appreciate it. I'll also submit a PR with a fix so the example will work with a streaming endpoint.

Thanks

jimfcarroll commented 1 year ago

Here are the changes I mentioned: https://github.com/jimfcarroll/ffmpeg-libav-tutorial/commit/fb6d196916379a4da87e9dc07d94dfd03196cf41

jimfcarroll commented 1 year ago

This seems to have resolved my issue in my own code: https://stackoverflow.com/questions/48578088/streaming-flv-to-rtmp-with-ffmpeg-using-h264-codec-and-c-api-to-flv-js