5

In ffmpeg streamingGuide, it writes:

ffmpeg -re -f lavfi -i aevalsrc="sin(400*2*PI*t)" -ar 8000 -f mulaw -f rtp rtp://127.0.0.1:1234 &
ffplay rtp://127.0.0.1:1234

I want to use a real video file to replace the artificial signal. Then I write the below at terminal A:

ffmpeg -re -i outputFile.avi -f mulaw -f rtp rtp://127.0.0.1:1234

it seems it is working: The frame information is counting. Here are information on the terminal A at the end:

frame=  309 fps= 29 q=31.0 Lsize=     931kB time=00:00:10.30 bitrate= 740.8kbits/s     video:922kB audio:0kB subtitle:0 global headers:0kB muxing overhead 1.030813%

When the frame at terminal A is still counting (not finished), I type the below at terminal B:

ffplay rtp://127.0.0.1:1234

But it does not work: The error information is:

[udp @ 0x7fb370001500] bind failed: Address already in useB f=0/0   
rtp://127.0.0.1:1234: Input/output error

Why?

[Update 1] Following the instruction from Camille Goudeseune I used the foo.sdp
The input for the ffmpeg terminal is:

ffmpeg -re -i out.avi -f mulaw -f rtp rtp://127.0.0.1:1235

The terminal for ffplay is:

ffplay -i foo.sdp

The ffplay terminal shows a lot of error, without images.

  libpostproc    52.  2.100 / 52.  2.100
[sdp @ 0x7fafdc0008c0] Undefined type (30)    0KB sq=    0B f=0/0   
[sdp @ 0x7fafdc0008c0] nal size exceeds length: 25453 86 0B f=0/0   
[sdp @ 0x7fafdc0008c0] Consumed more bytes than we got! (-25367)
[sdp @ 0x7fafdc0008c0] nal size exceeds length: 25453 86
[sdp @ 0x7fafdc0008c0] Consumed more bytes than we got! (-25367)
[sdp @ 0x7fafdc0008c0] Unhandled type (27) (See RFC for implementation details
[sdp @ 0x7fafdc0008c0] Undefined type (31)    0KB sq=    0B f=0/0   
[sdp @ 0x7fafdc0008c0] Unhandled type (27) (See RFC for implementation details
[sdp @ 0x7fafdc0008c0] nal size exceeds length: 62414 6130B f=0/0   
[sdp @ 0x7fafdc0008c0] Consumed more bytes than we got! (-61801)
[sdp @ 0x7fafdc0008c0] nal size exceeds length: 62414 613
[sdp @ 0x7fafdc0008c0] Consumed more bytes than we got! (-61801)
[h264 @ 0x7fafdc003020] non-existing PPS referencedq=    0B f=0/0   
[h264 @ 0x7fafdc003020] non-existing PPS 0 referenced
[h264 @ 0x7fafdc003020] decode_slice_header error
[h264 @ 0x7fafdc003020] Invalid mix of idr and non-idr slices
[sdp @ 0x7fafdc0008c0] Undefined type (31)    0KB sq=    0B f=0/0   
[sdp @ 0x7fafdc0008c0] Unhandled type (29) (See RFC for implementation details
[sdp @ 0x7fafdc0008c0] Unhandled type (26) (See RFC for implementation details
[sdp @ 0x7fafdc0008c0] Unhandled type (27) (See RFC for implementation details
    Last message repeated 2 times  0KB vq=    0KB sq=    0B f=0/0   
[sdp @ 0x7fafdc0008c0] Undefined type (31)
[sdp @ 0x7fafdc0008c0] Unhandled type (26) (See RFC for implementation details
[sdp @ 0x7fafdc0008c0] Unhandled type (25) (See RFC for implementation details
[h264 @ 0x7fafdc003020] insane cropping not completely supported, this could look slightly wrong ... (left: 2, top: 2)
[h264 @ 0x7fafdc003020] illegal aspect ratio
[h264 @ 0x7fafdc003020] missing picture in access unit with size 84589
[h264 @ 0x7fafdc003020] Partitioned H.264 support is incomplete
[h264 @ 0x7fafdc003020] insane cropping not completely supported, this could look slightly wrong ... (left: 2, top: 2)
[h264 @ 0x7fafdc003020] illegal aspect ratio
[h264 @ 0x7fafdc003020] insane cropping not completely supported, this could look slightly wrong ... (left: 2, top: 2)
[h264 @ 0x7fafdc003020] illegal aspect ratio
[h264 @ 0x7fafdc003020] no frame!
[h264 @ 0x7fafdc003020] RTP: missed 2563 packetsB sq=    0B f=0/0   
[sdp @ 0x7fafdc0008c0] Undefined type (30)
    Last message repeated 1 times
[sdp @ 0x7fafdc0008c0] Undefined type (31)
user1914692
  • 3,033
  • 5
  • 36
  • 61

2 Answers2

17

Instead of ffplay rtp://127.0.0.1:1235, use ffplay -i foo.sdp.

Create the local file foo.sdp by pasting into it the text output from ffmpeg that follows the line SDP:, for example:

v=0
o=- 0 0 IN IP4 127.0.0.1
s=No Name
c=IN IP4 127.0.0.1
t=0 0
a=tool:libavformat 55.2.100
m=video 1235 RTP/AVP 96
a=rtpmap:96 H264/90000
a=fmtp:96 packetization-mode=1

The .sdp file includes the rtp address, so you need not specify rtp://... as well.

Camille Goudeseune
  • 2,934
  • 2
  • 35
  • 56
  • 1
    I used the foo.sdp The input for the ffmpeg terminal is: ffmpeg -re -i out.avi -f mulaw -f rtp rtp://127.0.0.1:1235 The terminal for ffplay is: ffplay -i foo.sdp The ffplay terminal shows a lot of error, without images. – user1914692 Jun 03 '14 at 22:30
  • [sdp @ 00000000003759c0] Could not find codec parameters for stream 0 (Video: h2 64, none): unspecified size Consider increasing the value for the 'analyzeduration' and 'probesize' options C:\rtp.sdp: could not find codec parameters nan : 0.000 fd= 0 aq= 0KB vq= 0KB sq= 0B f=0/0 – Dr.jacky Oct 05 '15 at 06:42
  • 2
    I got some `Protocol not on whitelist 'file'!`, so I just added `-protocol_whitelist file,udp,rtp`. – user276648 Dec 02 '16 at 07:12
4

ffplay rtp://127.0.0.1:1234 will start listening on UDP-port 1234 for incoming RTP-traffic.

only a single application can listen on any given port on a host at any given time.

the error "bind failed: Address already in use" indicates, that another application is already listening on port 1234. probably you are still running the script from your tests?

either stop the application that is blocking the port, or use a different port.

umläute
  • 28,885
  • 9
  • 68
  • 122
  • Hmm, if `SO_REUSEADDR` and or `SO_REUSEPORT` are set to true it is entirely possible to bind two different processes to same IP address and TCP port. – Fraser Aug 09 '13 at 14:43
  • 1
    yes, but it will most likely not do what you would like to do. when using `SO_REUSEPORT` a package received will *NOT* turn up at *all* listeners, but only at one (which one is decided by the operating system, e.g. using a round-robin algorithm). this is cool for building a load-balancer, but for few other things (i cannot think of any) – umläute Aug 12 '13 at 07:00