Quantcast

FFMpeg Streaming via UDP

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

FFMpeg Streaming via UDP

Bogdan Mariesan
Hi everyone,

I am trying to achieve a *P2P *connection via *UDP *and for that I'm
following the wiki guide.

On my server I am using:

*ffmpeg -f dshow -video_size 640x360 -rtbufsize 702000k -framerate 30 -i
video="Integrated Camera":audio="Microphone (5- Logitech USB Headset H340)"
-r 30 -threads 4 -vcodec libx264 -pix_fmt yuv420p -tune zerolatency -preset
ultrafast -f mpegts udp:/10.166.141.198:23202 <http://10.166.141.198:23202>*

Where *10.166.141.198 *is the IP of an Android device and *23202 *is the
UDP port opened by the NAT after doing UDP hole punching.

Based on the example in the guide (
https://trac.ffmpeg.org/wiki/StreamingGuide) I assume on the client I have
to connect to the client in a similar manner. I might be wrong here since
the guide uses the same IP address for both client and server.

So on the client I am connection the URL *udp://5.2.55.19:51810?localport=50341
<http://5.2.55.19:51810?localport=50341>*.
Where *5.2.55.19 *is the IP of the serverm *51810 *is the public port and
*50341* is the private port obtained after doing UDP hole punching.
On the client side the stream seems to work but on my mobile device the app
i have built using IJKPlayer (https://github.com/Bilibili/ijkplayer)
doesn't display my stream. So is it due to the way I am listening for the
UDP stream?


Client side log:

ffmpeg version N-79630-g9ac154d Copyright (c) 2000-2016 the FFmpeg
developers
  built with gcc 5.3.0 (GCC)
  configuration: --enable-gpl --enable-version3 --disable-w32threads
--enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r
--enable-gnutls --enable-iconv --enable-libass --enable-libbluray
--enable-libbs2b --enable-libcaca --enable-libfreetype --enable-libgme
--enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmfx
--enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb
--enable-libopenjpeg --enable-libopus --enable-librtmp
--enable-libschroedinger --enable-libsnappy --enable-libsoxr
--enable-libspeex --enable-libtheora --enable-libtwolame
--enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis
--enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264
--enable-libx265 --enable-libxavs --enable-libxvid --enable-libzimg
--enable-lzma --enable-decklink --enable-zlib
  libavutil      55. 22.101 / 55. 22.101
  libavcodec     57. 38.100 / 57. 38.100
  libavformat    57. 34.103 / 57. 34.103
  libavdevice    57.  0.101 / 57.  0.101
  libavfilter     6. 44.100 /  6. 44.100
  libswscale      4.  1.100 /  4.  1.100
  libswresample   2.  0.101 /  2.  0.101
  libpostproc    54.  0.100 / 54.  0.100
Guessed Channel Layout for  Input Stream #0.1 : stereo
Input #0, dshow, from 'video=Integrated Camera:audio=Microphone (5-
Logitech USB Headset H340)':
  Duration: N/A, start: 1386931.560000, bitrate: N/A
    Stream #0:0: Video: rawvideo, bgr24, 640x360, 30 fps, 31 tbr, 10000k tbn
    Stream #0:1: Audio: pcm_s16le, 44100 Hz, 2 channels, s16, 1411 kb/s
[libx264 @ 0000000008a4be20] using cpu capabilities: MMX2 SSE2Fast SSSE3
SSE4.2 AVX FMA3 AVX2 LZCNT BMI2
[libx264 @ 0000000008a4be20] profile Constrained Baseline, level 3.0
[mpegts @ 00000000086fd880] Using AVStream.codec to pass codec parameters
to muxers is deprecated, use AVStream.codecpar instead.
    Last message repeated 1 times
Output #0, mpegts, to 'udp://109.166.141.198:61623?localport=53366':
  Metadata:
    encoder         : Lavf57.34.103
    Stream #0:0: Video: h264, yuv420p, 640x360, q=2-31, 30 fps, 90k tbn
    Metadata:
      encoder         : Lavc57.38.100 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
    Stream #0:1: Audio: mp2, 44100 Hz, stereo, s16, 384 kb/s
    Metadata:
      encoder         : Lavc57.38.100 mp2
Stream mapping:
  Stream #0:0 -> #0:0 (rawvideo (native) -> h264 (libx264))
  Stream #0:1 -> #0:1 (pcm_s16le (native) -> mp2 (native))
Press [q] to stop, [?] for help
Past duration 0.659996 too large
Past duration 0.699989 too large
Past duration 0.739998 too large
Past duration 0.779991 too large
Past duration 0.619987 too large
Past duration 0.659996 too large
Past duration 0.699989 too large
frame=   23 fps=0.0 q=22.0 size=     122kB time=00:00:01.13 bitrate=
878.5kbits/s speed=2.26x
Past duration 0.739998 too large
Past duration 0.779991 too large
Past duration 0.619987 too large
Past duration 0.629997 too large
Past duration 0.669991 too large
Past duration 0.679985 too large
Past duration 0.689995 too large
frame=   37 fps= 37 q=22.0 size=     201kB time=00:00:01.60
bitrate=1031.2kbits/s speed= 1.6x
Past duration 0.699989 too large
Past duration 0.739998 too large
Past duration 0.749992 too large
frame=   53 fps= 35 q=22.0 size=     275kB time=00:00:02.13
bitrate=1054.7kbits/s speed=1.42x

Kind regards,

*Bogdan Emil Mariesan*
Senior Software Engineer

*BuddyGuard UG* (haftungsbeschränkt)
Dircksenstr. 40
10178 Berlin

m:         +40 743 901 331
w.           www.buddyguard.io
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: FFMpeg Streaming via UDP

Andy Furniss-2
Bogdan Mariesan wrote:

> Hi everyone,
>
> I am trying to achieve a *P2P *connection via *UDP *and for that I'm
> following the wiki guide.
>
> On my server I am using:
>
> *ffmpeg -f dshow -video_size 640x360 -rtbufsize 702000k -framerate 30 -i
> video="Integrated Camera":audio="Microphone (5- Logitech USB Headset H340)"
> -r 30 -threads 4 -vcodec libx264 -pix_fmt yuv420p -tune zerolatency -preset
> ultrafast -f mpegts udp:/10.166.141.198:23202 <http://10.166.141.198:23202>*

Well I'm lost already as 10/8 is a local address, plus what's the http bit?

>
> Where *10.166.141.198 *is the IP of an Android device and *23202 *is the
> UDP port opened by the NAT after doing UDP hole punching.

What is this udp hole punching (and why do you need it with a local
address)?

>
> Based on the example in the guide (
> https://trac.ffmpeg.org/wiki/StreamingGuide) I assume on the client I have
> to connect to the client in a similar manner. I might be wrong here since
> the guide uses the same IP address for both client and server.
>
> So on the client I am connection the URL *udp://5.2.55.19:51810?localport=50341
> <http://5.2.55.19:51810?localport=50341>*.
> Where *5.2.55.19 *is the IP of the serverm *51810 *is the public port and
> *50341* is the private port obtained after doing UDP hole punching.
> On the client side the stream seems to work but on my mobile device the app
> i have built using IJKPlayer (https://github.com/Bilibili/ijkplayer)
> doesn't display my stream. So is it due to the way I am listening for the
> UDP stream?
>
>
> Client side log:
>
> ffmpeg version N-79630-g9ac154d Copyright (c) 2000-2016 the FFmpeg
> developers
>    built with gcc 5.3.0 (GCC)
>    configuration: --enable-gpl --enable-version3 --disable-w32threads
> --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r
> --enable-gnutls --enable-iconv --enable-libass --enable-libbluray
> --enable-libbs2b --enable-libcaca --enable-libfreetype --enable-libgme
> --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmfx
> --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb
> --enable-libopenjpeg --enable-libopus --enable-librtmp
> --enable-libschroedinger --enable-libsnappy --enable-libsoxr
> --enable-libspeex --enable-libtheora --enable-libtwolame
> --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis
> --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264
> --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzimg
> --enable-lzma --enable-decklink --enable-zlib
>    libavutil      55. 22.101 / 55. 22.101
>    libavcodec     57. 38.100 / 57. 38.100
>    libavformat    57. 34.103 / 57. 34.103
>    libavdevice    57.  0.101 / 57.  0.101
>    libavfilter     6. 44.100 /  6. 44.100
>    libswscale      4.  1.100 /  4.  1.100
>    libswresample   2.  0.101 /  2.  0.101
>    libpostproc    54.  0.100 / 54.  0.100
> Guessed Channel Layout for  Input Stream #0.1 : stereo
> Input #0, dshow, from 'video=Integrated Camera:audio=Microphone (5-
> Logitech USB Headset H340)':
>    Duration: N/A, start: 1386931.560000, bitrate: N/A
>      Stream #0:0: Video: rawvideo, bgr24, 640x360, 30 fps, 31 tbr, 10000k tbn
>      Stream #0:1: Audio: pcm_s16le, 44100 Hz, 2 channels, s16, 1411 kb/s
> [libx264 @ 0000000008a4be20] using cpu capabilities: MMX2 SSE2Fast SSSE3
> SSE4.2 AVX FMA3 AVX2 LZCNT BMI2
> [libx264 @ 0000000008a4be20] profile Constrained Baseline, level 3.0
> [mpegts @ 00000000086fd880] Using AVStream.codec to pass codec parameters
> to muxers is deprecated, use AVStream.codecpar instead.
>      Last message repeated 1 times
> Output #0, mpegts, to 'udp://109.166.141.198:61623?localport=53366':
>    Metadata:
>      encoder         : Lavf57.34.103
>      Stream #0:0: Video: h264, yuv420p, 640x360, q=2-31, 30 fps, 90k tbn
>      Metadata:
>        encoder         : Lavc57.38.100 libx264
>      Side data:
>        cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
>      Stream #0:1: Audio: mp2, 44100 Hz, stereo, s16, 384 kb/s
>      Metadata:
>        encoder         : Lavc57.38.100 mp2
> Stream mapping:
>    Stream #0:0 -> #0:0 (rawvideo (native) -> h264 (libx264))
>    Stream #0:1 -> #0:1 (pcm_s16le (native) -> mp2 (native))
> Press [q] to stop, [?] for help
> Past duration 0.659996 too large
> Past duration 0.699989 too large
> Past duration 0.739998 too large
> Past duration 0.779991 too large
> Past duration 0.619987 too large
> Past duration 0.659996 too large
> Past duration 0.699989 too large
> frame=   23 fps=0.0 q=22.0 size=     122kB time=00:00:01.13 bitrate=
> 878.5kbits/s speed=2.26x
> Past duration 0.739998 too large
> Past duration 0.779991 too large
> Past duration 0.619987 too large
> Past duration 0.629997 too large
> Past duration 0.669991 too large
> Past duration 0.679985 too large
> Past duration 0.689995 too large
> frame=   37 fps= 37 q=22.0 size=     201kB time=00:00:01.60
> bitrate=1031.2kbits/s speed= 1.6x
> Past duration 0.699989 too large
> Past duration 0.739998 too large
> Past duration 0.749992 too large
> frame=   53 fps= 35 q=22.0 size=     275kB time=00:00:02.13
> bitrate=1054.7kbits/s speed=1.42x
>
> Kind regards,
>
> *Bogdan Emil Mariesan*
> Senior Software Engineer
>
> *BuddyGuard UG* (haftungsbeschränkt)
> Dircksenstr. 40
> 10178 Berlin
>
> m:         +40 743 901 331
> w.           www.buddyguard.io
> _______________________________________________
> ffmpeg-user mailing list
> [hidden email]
> http://ffmpeg.org/mailman/listinfo/ffmpeg-user
>
> To unsubscribe, visit link above, or email
> [hidden email] with subject "unsubscribe".
>

_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: FFMpeg Streaming via UDP

Bogdan Mariesan
Hi Andy,

Sorry for the fuss, my email client added the http part... that was not
intended there.
On the client side I am using Java to run the FFMpeg process and in Android
using IJKPlayer to play the stream. I've added pastebin links since it
keeps the code well formatted.
Client side - http://pastebin.com/bkajPR5Q
Server used to achieve the UDP hole punching - http://pastebin.com/vEGdw3QF
Android - http://pastebin.com/gpUUQyjG

UDP hole punching is the mechanism through which you can establish P2P
connections when your devices are behind routers, secure NATs etc. where a
direct connection between the devices would be impossible. This can be
achieved by having both devices connect to a public ip server via UDP. When
the connection is to the server is done, on both devices public and private
UDP ports are open by the NAT. Then a direct connection can be established
using the public IPs of the routers of the two devices by specifying the
public and private(local) ports on both sides. Hope i made it clear.

So basically I'm opening a P2P connection between the two devices.

The IPs reported by my UDP hole punching server are below (i've changed
them a bit for security reasons):

My laptop running FFMpeg which sits behind a router
5.2.66.19-56190

My Android phone using 3G/4G
109.55.132.187-52547

And the log generated by FFMpeg is:
http://pastebin.com/fyzyk9X1

Hope it makes more sense now.

Kind regards,
Bogdan




*Bogdan Emil Mariesan*
Senior Software Engineer

*BuddyGuard UG* (haftungsbeschränkt)
Dircksenstr. 40
10178 Berlin

m:         +40 743 901 331
w.           www.buddyguard.io

On Thu, May 5, 2016 at 2:33 AM, Andy Furniss <[hidden email]> wrote:

> Bogdan Mariesan wrote:
>
>> Hi everyone,
>>
>> I am trying to achieve a *P2P *connection via *UDP *and for that I'm
>> following the wiki guide.
>>
>> On my server I am using:
>>
>> *ffmpeg -f dshow -video_size 640x360 -rtbufsize 702000k -framerate 30 -i
>> video="Integrated Camera":audio="Microphone (5- Logitech USB Headset
>> H340)"
>> -r 30 -threads 4 -vcodec libx264 -pix_fmt yuv420p -tune zerolatency
>> -preset
>> ultrafast -f mpegts udp:/10.166.141.198:23202 <
>> http://10.166.141.198:23202>*
>>
>
> Well I'm lost already as 10/8 is a local address, plus what's the http bit?
>
>
>> Where *10.166.141.198 *is the IP of an Android device and *23202 *is the
>> UDP port opened by the NAT after doing UDP hole punching.
>>
>
> What is this udp hole punching (and why do you need it with a local
> address)?
>
>
>> Based on the example in the guide (
>> https://trac.ffmpeg.org/wiki/StreamingGuide) I assume on the client I
>> have
>> to connect to the client in a similar manner. I might be wrong here since
>> the guide uses the same IP address for both client and server.
>>
>> So on the client I am connection the URL *udp://
>> 5.2.55.19:51810?localport=50341
>> <http://5.2.55.19:51810?localport=50341>*.
>> Where *5.2.55.19 *is the IP of the serverm *51810 *is the public port and
>> *50341* is the private port obtained after doing UDP hole punching.
>>
>> On the client side the stream seems to work but on my mobile device the
>> app
>> i have built using IJKPlayer (https://github.com/Bilibili/ijkplayer)
>> doesn't display my stream. So is it due to the way I am listening for the
>> UDP stream?
>>
>>
>> Client side log:
>>
>> ffmpeg version N-79630-g9ac154d Copyright (c) 2000-2016 the FFmpeg
>> developers
>>    built with gcc 5.3.0 (GCC)
>>    configuration: --enable-gpl --enable-version3 --disable-w32threads
>> --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r
>> --enable-gnutls --enable-iconv --enable-libass --enable-libbluray
>> --enable-libbs2b --enable-libcaca --enable-libfreetype --enable-libgme
>> --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmfx
>> --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb
>> --enable-libopenjpeg --enable-libopus --enable-librtmp
>> --enable-libschroedinger --enable-libsnappy --enable-libsoxr
>> --enable-libspeex --enable-libtheora --enable-libtwolame
>> --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis
>> --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264
>> --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzimg
>> --enable-lzma --enable-decklink --enable-zlib
>>    libavutil      55. 22.101 / 55. 22.101
>>    libavcodec     57. 38.100 / 57. 38.100
>>    libavformat    57. 34.103 / 57. 34.103
>>    libavdevice    57.  0.101 / 57.  0.101
>>    libavfilter     6. 44.100 /  6. 44.100
>>    libswscale      4.  1.100 /  4.  1.100
>>    libswresample   2.  0.101 /  2.  0.101
>>    libpostproc    54.  0.100 / 54.  0.100
>> Guessed Channel Layout for  Input Stream #0.1 : stereo
>> Input #0, dshow, from 'video=Integrated Camera:audio=Microphone (5-
>> Logitech USB Headset H340)':
>>    Duration: N/A, start: 1386931.560000, bitrate: N/A
>>      Stream #0:0: Video: rawvideo, bgr24, 640x360, 30 fps, 31 tbr, 10000k
>> tbn
>>      Stream #0:1: Audio: pcm_s16le, 44100 Hz, 2 channels, s16, 1411 kb/s
>> [libx264 @ 0000000008a4be20] using cpu capabilities: MMX2 SSE2Fast SSSE3
>> SSE4.2 AVX FMA3 AVX2 LZCNT BMI2
>> [libx264 @ 0000000008a4be20] profile Constrained Baseline, level 3.0
>> [mpegts @ 00000000086fd880] Using AVStream.codec to pass codec parameters
>> to muxers is deprecated, use AVStream.codecpar instead.
>>      Last message repeated 1 times
>> Output #0, mpegts, to 'udp://109.166.141.198:61623?localport=53366':
>>    Metadata:
>>      encoder         : Lavf57.34.103
>>      Stream #0:0: Video: h264, yuv420p, 640x360, q=2-31, 30 fps, 90k tbn
>>      Metadata:
>>        encoder         : Lavc57.38.100 libx264
>>      Side data:
>>        cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
>>      Stream #0:1: Audio: mp2, 44100 Hz, stereo, s16, 384 kb/s
>>      Metadata:
>>        encoder         : Lavc57.38.100 mp2
>> Stream mapping:
>>    Stream #0:0 -> #0:0 (rawvideo (native) -> h264 (libx264))
>>    Stream #0:1 -> #0:1 (pcm_s16le (native) -> mp2 (native))
>> Press [q] to stop, [?] for help
>> Past duration 0.659996 too large
>> Past duration 0.699989 too large
>> Past duration 0.739998 too large
>> Past duration 0.779991 too large
>> Past duration 0.619987 too large
>> Past duration 0.659996 too large
>> Past duration 0.699989 too large
>> frame=   23 fps=0.0 q=22.0 size=     122kB time=00:00:01.13 bitrate=
>> 878.5kbits/s speed=2.26x
>> Past duration 0.739998 too large
>> Past duration 0.779991 too large
>> Past duration 0.619987 too large
>> Past duration 0.629997 too large
>> Past duration 0.669991 too large
>> Past duration 0.679985 too large
>> Past duration 0.689995 too large
>> frame=   37 fps= 37 q=22.0 size=     201kB time=00:00:01.60
>> bitrate=1031.2kbits/s speed= 1.6x
>> Past duration 0.699989 too large
>> Past duration 0.739998 too large
>> Past duration 0.749992 too large
>> frame=   53 fps= 35 q=22.0 size=     275kB time=00:00:02.13
>> bitrate=1054.7kbits/s speed=1.42x
>>
>> Kind regards,
>>
>> *Bogdan Emil Mariesan*
>> Senior Software Engineer
>>
>> *BuddyGuard UG* (haftungsbeschränkt)
>> Dircksenstr. 40
>> 10178 Berlin
>>
>> m:         +40 743 901 331
>> w.           www.buddyguard.io
>> _______________________________________________
>> ffmpeg-user mailing list
>> [hidden email]
>> http://ffmpeg.org/mailman/listinfo/ffmpeg-user
>>
>> To unsubscribe, visit link above, or email
>> [hidden email] with subject "unsubscribe".
>>
>>
> _______________________________________________
> ffmpeg-user mailing list
> [hidden email]
> http://ffmpeg.org/mailman/listinfo/ffmpeg-user
>
> To unsubscribe, visit link above, or email
> [hidden email] with subject "unsubscribe".
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: FFMpeg Streaming via UDP

Andy Furniss-2
Bogdan Mariesan wrote:
> Hi Andy,
>
> Sorry for the fuss, my email client added the http part... that was
> not intended there.

OK, maybe from an ffmpeg users pov it would be best to test on a lan
without the hole punching code just to see if that part works.

> On the client side I am using Java to run the FFMpeg process and in
> Android using IJKPlayer to play the stream. I've added pastebin links
> since it keeps the code well formatted. Client side -
> http://pastebin.com/bkajPR5Q Server used to achieve the UDP hole
> punching - http://pastebin.com/vEGdw3QF Android -
> http://pastebin.com/gpUUQyjG

Missing / on line 38.

I am far too lazy to check if the ports are reversed properly etc - If I
were doing this I would be looking at tcpdumps to check.


> UDP hole punching is the mechanism through which you can establish
> P2P connections when your devices are behind routers, secure NATs
> etc. where a direct connection between the devices would be
> impossible. This can be achieved by having both devices connect to a
> public ip server via UDP. When the connection is to the server is
> done, on both devices public and private UDP ports are open by the
> NAT. Then a direct connection can be established using the public IPs
> of the routers of the two devices by specifying the public and
> private(local) ports on both sides. Hope i made it clear.
>
> So basically I'm opening a P2P connection between the two devices.
>
> The IPs reported by my UDP hole punching server are below (i've
> changed them a bit for security reasons):

OK, maybe it should work "normally" though I don't think it would be
robust with multiple clients behind the same nat as the ffmpeg server is
a different connection from the middle server so the sports could in
theory get changed.

In the UK I think 3g/4g providers do carrier grade nat - I don't know
if/how that would affect things.

>
> My laptop running FFMpeg which sits behind a router 5.2.66.19-56190
>
> My Android phone using 3G/4G 109.55.132.187-52547
>
> And the log generated by FFMpeg is: http://pastebin.com/fyzyk9X1
>
> Hope it makes more sense now.
>
> Kind regards, Bogdan
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Loading...