SlideShare a Scribd company logo
1 of 18
Live Streaming in Android
Ahmet Oğuz Mermerkaya
Software Developer
Aselsan
@mekya84
ahmetmermerkaya@gmail.com
*
Ahmet Oğuz Mermerkaya
● Writer of an Android Application Programming book,
Merhaba Android, in Turkish
● Member of GDG Ankara
● Software Developer in Aselsan, Defense Industry
Company in Turkiye
*
Outline
● How live streaming works
● Building FFmpeg(with x264 and fdk-aac)
● Using Vitamio MediaPlayer
● Implementing a RTSP Server
● Sending Previews and Audio From RTSP Server
● Receiving and Playing Audio On Client
*
How live streaming works
● RTSP (Real Time Streaming Protocol)
● RTP (Real Time Protocol)
*
How live streaming works
● RTSP (Real Time Streaming Protocol)
● RTP (Real Time Protocol)
This is the
part FFmpeg
takes place
*
What is FFmpeg?
● Open-source, cross-platform multimedia framework
● Supports almost all codecs and formats(H264, H263,
AAC, AMR, MP4, MP3, AVI)
● Streams Audio and Video
ffmpeg.org
*
Building FFmpeg
● Download
o FFmpeg (http://fmpeg.org)
o fdk_aac for using AAC encoder
(http://sourceforge.net/projects/opencore-amr/files/fdk-aac/)
o libx264 source code for H264 encoder
(http://www.videolan.org/developers/x264.html)
o Android NDK for cross compiling(http://developer.android.com)
● Configure & Make
*
Building FFmpeg - Configure & Make
export PATH=ANDROID_NDK/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin:$PATH
#libx264
./configure --cross-prefix=arm-linux-androideabi- enable-pic --disable-cli -enable-static --disable-shared -
-host=arm-linux --extra-cflags="-march=armv7-a -mfloat-abi=softfp" --sysroot=/path/to/android-
ndk/platforms/android-87arch-arm/
make
#fdk-aac
./configure --host=arm-android-eabi-linux --enable-static --prefix=/path/to/fdk-aac/ --disable-shared
make
#ffmpeg
./configure --disable-everything --enable-gpl --enable-libx264 --enable-libfdk-aac --enable-nonfree --
enable-pthreads --cross-prefix=arm-linux-androideabi- --arch=arm --sysroot=/path/to/android-
ndk/platforms/android-8/arch/arm/ --extra-cflags="-march=armv7-a -mfloat-abi=softfp" --extra-cflags="-
I./x264" --extra-cflags="-I./fdk-aac/include/" --extra-ldflags="-L./x264" --extra-ldflags="-L./fdk-aac/lib"
--datadir="/data/ffmpeg/bin/ffpresets" --enable-version3 --enable-decoder=rawvideo --enable-demuxer=rawvideo
--enable-decoder=aarc --enable-demuxer=aac --enable-muxer=h264 --enable-encoder=pcm_s16le --enable-
protocol=rtp --enable-protocol=udp --enable-muxer?rtp --enable-demuxer=image2pipe --enable-muzer=adts --
enable-muxer=pcm_s16le --enable-demuxer=pcm_s16le --enable-demuxer=h264 --enable-filter=scale --enable-
encoder=libx264 --enable-encoder=libfdk_aac -enable-protocol=pipe --enable-decoder=pcm_s16le --enable-
filter=aresample
make
*
Using Vitamio Player
● Get it from vitamio.org and extract
Line 1 VideoView videoView = (VideoView) findViewById(R.id.videoView);
Line 2 videoView.setVideoPath("rtsp://IP_OF_ANDROID_STREAM_SERVER:PORT/live.ts");
● To start vitamio play with partial buffer, follow the instructions on http://vitamio.org/topics/104?locale=en
Then we need a RTSP server
*
Implementing a RTSP Server
Client (MediaPlayer - Vitamio) RTSP Server
*
Sending Previews From RTSP Server
Line 1 public void startVideo(String address, int port) {
Line 2 String videoCommand = "path/to/ffmpeg -analyzeduration 0 -pix_fmt nv21
Line 3 -s 480x360 -vcodec rawvideo -f image2pipe -i - -s 320x240 -crf
18
Line 4 -preset ultrafast -vcodec libx264 -f rtp
rtp://"+address+":"+port;
Line 5 Process ffmpegVideoProcess = Runtime.getRuntime().exec(videoCommand);
Line 6 OutputStream ostream = ffmpegVideoProcess.getOutputStream();
Line 7
Line 8 getCamera().setPreviewCallback(new PreviewCallback(){
Line 9 public void onPreviewFrame(byte[] buffer, Camera cam) {
Line 10 ostream.write(buffer);
Line 11 ostream.flush();
Line 12 }
Line 13 });
Line 14 }
*
Sending Audio From RTSP Server
Line 1 public void startAudio(String address, int port) {
Line 2 String audioCommand = "path/to/ffmpeg -analyzeduration 0 -f s16le -ac
Line 3 44100 -ac 1 -i - -ac 1 -acodec libfdk_aac -f adts -vbr
3
Line 4 udp://"+address+ ":" + port +"/";
Line 5 Process ffmpegAudioProcess = Runtime.getRuntime().exec(audioCommand);
Line 6 OutputStream ostream = ffmpegAudioProcess.getOutputStream();
Line 7 prepareAudioRecord();
Line 8 new Thread(){ public void run(){
Line 9 while(true) {
Line 10 int len = audioRecord.read(audioBuffer, 0,
audioBuffer.length);
Line 11 ostream.write(audioBuffer, 0, len);
Line 12 ostream.flush()
Line 13 }
Line 14 }}.start();
*
Receiving Audio On Client
Line 1 public void receiveAudio() {
Line 2 String audioCommand = "path/to/ffmpeg -analyzeduration 0 -f aac -strict -2 -
acodec
Line 3 aac -b:a 120k -ac 1 -i - -ac 1 -acodec pcm_s16le -ar 44100 -f s16le -";
Line 5 Process ffmpegAudioProcess = Runtime.getRuntime().exec(audioCommand);
Line 6 OutputStream ostream = ffmpegAudioProcess.getOutputStream();
Line 7 DatagramSocket udpsocket = new DatagramSocket(PORT);
Line 8 DatagramPacket packet = new DatagramPacket(new byte[2048], 2048);
Line 9 new Thread(){ public void run(){
while(true) {
Line 10 udpsocket.receive(packet);
Line 11 ostream.write(datagramPacket.getData(), 0,
datagram.getLength());
Line 12 ostream.flush();
Line 13 }}}.start();
*
Playing Audio On Client
Line 1 public void playAudio(final InputStream istream) {
Line 2 byte[] buffer = new byte[2048];
Line 3 int bufferSize = AudioTrack.getMinBufferSize(44100,...);
Line 5 audioTrack = new AudioTrack(AudioManager.STREAM_MUSIC,44100,
Line 6 AudioFormat.CHANNEL_OUT_MONO,
AudioFormat.ENCODING_PCM_16BIT,
Line 7 bufferSize, AudioTrack.MODE_STREAM);
Line 8 audioTrack.play();
Line 9 while (true) {
Line 10 int len = istream.read(buffer, 0, buffer.length);
Line 11 audioTrack.write(buffer, 0, len);
Line 12 audioTrack.flush()
Line 13 }
Line 14 }
Demo
*
Android Developer Days
● Expected 1500~ participants
● Partner of Droidcon.com
● 15 co-organizers from 7 countries
● Free of charge
● This year more inspiration, more
networking and more fun
● ADD 2012 web site ->
www.androiddeveloperdays.com/2012
Date: June 14, 15 2013
Venue: METU, Ankara, Turkiye
www.androiddeveloperdays.com
Thank you for listening
Live Streaming in Android
Ahmet Oğuz Mermerkaya
@mekya84
ahmetmermerkaya@gmail.com

More Related Content

What's hot

Audio and Video streaming.ppt
Audio and Video streaming.pptAudio and Video streaming.ppt
Audio and Video streaming.pptVideoguy
 
Mag 322 w1 iptv set top box - newtech.co.uk
Mag 322 w1 iptv set top box - newtech.co.ukMag 322 w1 iptv set top box - newtech.co.uk
Mag 322 w1 iptv set top box - newtech.co.ukNewtech Store Limited
 
【Specification】Geniatech Atv1960 AmLogic S912 Octa-core Android TV Box Comes ...
【Specification】Geniatech Atv1960 AmLogic S912 Octa-core Android TV Box Comes ...【Specification】Geniatech Atv1960 AmLogic S912 Octa-core Android TV Box Comes ...
【Specification】Geniatech Atv1960 AmLogic S912 Octa-core Android TV Box Comes ...Geniatech
 
STATUS UPDATE OF COLO PROJECT XIAOWEI YANG, HUAWEI AND WILL AULD, INTEL
STATUS UPDATE OF COLO PROJECT XIAOWEI YANG, HUAWEI AND WILL AULD, INTELSTATUS UPDATE OF COLO PROJECT XIAOWEI YANG, HUAWEI AND WILL AULD, INTEL
STATUS UPDATE OF COLO PROJECT XIAOWEI YANG, HUAWEI AND WILL AULD, INTELThe Linux Foundation
 
Audio and video streaming
Audio and video streamingAudio and video streaming
Audio and video streamingRohan Bhatkar
 
Live Streaming from A-Z
Live Streaming from A-ZLive Streaming from A-Z
Live Streaming from A-ZBrightcove
 
Streaming Overview Final.ppt
Streaming Overview Final.pptStreaming Overview Final.ppt
Streaming Overview Final.pptVideoguy
 
Issues of added_ip_devices
Issues of added_ip_devicesIssues of added_ip_devices
Issues of added_ip_devicesTSOLUTIONS
 
XPDS13: Performance Optimization on Xen-based Android Device - Jack Ren, Inte...
XPDS13: Performance Optimization on Xen-based Android Device - Jack Ren, Inte...XPDS13: Performance Optimization on Xen-based Android Device - Jack Ren, Inte...
XPDS13: Performance Optimization on Xen-based Android Device - Jack Ren, Inte...The Linux Foundation
 
Video and Audio Streaming
Video and Audio StreamingVideo and Audio Streaming
Video and Audio StreamingKarthick Kumar
 
SR-IOV, KVM and Intel X520 10Gbps cards on Debian/Stable
SR-IOV, KVM and Intel X520 10Gbps cards on Debian/StableSR-IOV, KVM and Intel X520 10Gbps cards on Debian/Stable
SR-IOV, KVM and Intel X520 10Gbps cards on Debian/Stablejuet-y
 
Embedded Recipes 2019 - RT is about to make it to mainline. Now what?
Embedded Recipes 2019 - RT is about to make it to mainline. Now what?Embedded Recipes 2019 - RT is about to make it to mainline. Now what?
Embedded Recipes 2019 - RT is about to make it to mainline. Now what?Anne Nicolas
 
H 264 Pc Based Dvr
H 264 Pc Based DvrH 264 Pc Based Dvr
H 264 Pc Based Dvrandy
 
vPoint HD briefing.ppt
vPoint HD briefing.pptvPoint HD briefing.ppt
vPoint HD briefing.pptVideoguy
 
Embedded Recipes 2018 - SoC+FPGA update in 2018 - Marek Vasut
Embedded Recipes 2018 - SoC+FPGA update in 2018 - Marek VasutEmbedded Recipes 2018 - SoC+FPGA update in 2018 - Marek Vasut
Embedded Recipes 2018 - SoC+FPGA update in 2018 - Marek VasutAnne Nicolas
 

What's hot (18)

Audio and Video streaming.ppt
Audio and Video streaming.pptAudio and Video streaming.ppt
Audio and Video streaming.ppt
 
Mag 322 w1 iptv set top box - newtech.co.uk
Mag 322 w1 iptv set top box - newtech.co.ukMag 322 w1 iptv set top box - newtech.co.uk
Mag 322 w1 iptv set top box - newtech.co.uk
 
Streaming Video Techniques
Streaming Video TechniquesStreaming Video Techniques
Streaming Video Techniques
 
【Specification】Geniatech Atv1960 AmLogic S912 Octa-core Android TV Box Comes ...
【Specification】Geniatech Atv1960 AmLogic S912 Octa-core Android TV Box Comes ...【Specification】Geniatech Atv1960 AmLogic S912 Octa-core Android TV Box Comes ...
【Specification】Geniatech Atv1960 AmLogic S912 Octa-core Android TV Box Comes ...
 
STATUS UPDATE OF COLO PROJECT XIAOWEI YANG, HUAWEI AND WILL AULD, INTEL
STATUS UPDATE OF COLO PROJECT XIAOWEI YANG, HUAWEI AND WILL AULD, INTELSTATUS UPDATE OF COLO PROJECT XIAOWEI YANG, HUAWEI AND WILL AULD, INTEL
STATUS UPDATE OF COLO PROJECT XIAOWEI YANG, HUAWEI AND WILL AULD, INTEL
 
Audio and video streaming
Audio and video streamingAudio and video streaming
Audio and video streaming
 
Mips track a
Mips   track aMips   track a
Mips track a
 
Live Streaming from A-Z
Live Streaming from A-ZLive Streaming from A-Z
Live Streaming from A-Z
 
Streaming Overview Final.ppt
Streaming Overview Final.pptStreaming Overview Final.ppt
Streaming Overview Final.ppt
 
At 0408 v-h9d-hybrid-video-recorder
At 0408 v-h9d-hybrid-video-recorderAt 0408 v-h9d-hybrid-video-recorder
At 0408 v-h9d-hybrid-video-recorder
 
Issues of added_ip_devices
Issues of added_ip_devicesIssues of added_ip_devices
Issues of added_ip_devices
 
XPDS13: Performance Optimization on Xen-based Android Device - Jack Ren, Inte...
XPDS13: Performance Optimization on Xen-based Android Device - Jack Ren, Inte...XPDS13: Performance Optimization on Xen-based Android Device - Jack Ren, Inte...
XPDS13: Performance Optimization on Xen-based Android Device - Jack Ren, Inte...
 
Video and Audio Streaming
Video and Audio StreamingVideo and Audio Streaming
Video and Audio Streaming
 
SR-IOV, KVM and Intel X520 10Gbps cards on Debian/Stable
SR-IOV, KVM and Intel X520 10Gbps cards on Debian/StableSR-IOV, KVM and Intel X520 10Gbps cards on Debian/Stable
SR-IOV, KVM and Intel X520 10Gbps cards on Debian/Stable
 
Embedded Recipes 2019 - RT is about to make it to mainline. Now what?
Embedded Recipes 2019 - RT is about to make it to mainline. Now what?Embedded Recipes 2019 - RT is about to make it to mainline. Now what?
Embedded Recipes 2019 - RT is about to make it to mainline. Now what?
 
H 264 Pc Based Dvr
H 264 Pc Based DvrH 264 Pc Based Dvr
H 264 Pc Based Dvr
 
vPoint HD briefing.ppt
vPoint HD briefing.pptvPoint HD briefing.ppt
vPoint HD briefing.ppt
 
Embedded Recipes 2018 - SoC+FPGA update in 2018 - Marek Vasut
Embedded Recipes 2018 - SoC+FPGA update in 2018 - Marek VasutEmbedded Recipes 2018 - SoC+FPGA update in 2018 - Marek Vasut
Embedded Recipes 2018 - SoC+FPGA update in 2018 - Marek Vasut
 

Similar to Live streaming in Android

2015.7.17 JANOG36 BGP Flowspec Interoperability Test @ Interop Tokyo 2015 Sho...
2015.7.17 JANOG36 BGP Flowspec Interoperability Test @ Interop Tokyo 2015 Sho...2015.7.17 JANOG36 BGP Flowspec Interoperability Test @ Interop Tokyo 2015 Sho...
2015.7.17 JANOG36 BGP Flowspec Interoperability Test @ Interop Tokyo 2015 Sho...Shuichi Ohkubo
 
PLNOG 13: P. Kupisiewicz, O. Pelerin: Make IOS-XE Troubleshooting Easy – Pack...
PLNOG 13: P. Kupisiewicz, O. Pelerin: Make IOS-XE Troubleshooting Easy – Pack...PLNOG 13: P. Kupisiewicz, O. Pelerin: Make IOS-XE Troubleshooting Easy – Pack...
PLNOG 13: P. Kupisiewicz, O. Pelerin: Make IOS-XE Troubleshooting Easy – Pack...PROIDEA
 
Gameboy emulator in rust and web assembly
Gameboy emulator in rust and web assemblyGameboy emulator in rust and web assembly
Gameboy emulator in rust and web assemblyYodalee
 
RTSP Protocol - Explanation to develop API of RTSP Protocol
RTSP Protocol - Explanation to develop API of RTSP ProtocolRTSP Protocol - Explanation to develop API of RTSP Protocol
RTSP Protocol - Explanation to develop API of RTSP ProtocolFranZEast
 
HKG15-311: OP-TEE for Beginners and Porting Review
HKG15-311: OP-TEE for Beginners and Porting ReviewHKG15-311: OP-TEE for Beginners and Porting Review
HKG15-311: OP-TEE for Beginners and Porting ReviewLinaro
 
Robotix Tutorial 9
Robotix Tutorial 9Robotix Tutorial 9
Robotix Tutorial 9ankuredkie
 
Asa pixfwsm multicast tips and common problems
Asa pixfwsm multicast tips and common problemsAsa pixfwsm multicast tips and common problems
Asa pixfwsm multicast tips and common problemsIT Tech
 
Setup VoIP System and Interconnection with LTE network
Setup VoIP System and Interconnection with LTE networkSetup VoIP System and Interconnection with LTE network
Setup VoIP System and Interconnection with LTE networkNazmul Hossain Rakib
 
Howto ethereal-wireshark-trace en
Howto ethereal-wireshark-trace enHowto ethereal-wireshark-trace en
Howto ethereal-wireshark-trace enJORGE GOMEZ
 
Talk@JanusCon2019: Janus, WebRTC and ML - Fantastic technologies and how to m...
Talk@JanusCon2019: Janus, WebRTC and ML - Fantastic technologies and how to m...Talk@JanusCon2019: Janus, WebRTC and ML - Fantastic technologies and how to m...
Talk@JanusCon2019: Janus, WebRTC and ML - Fantastic technologies and how to m...Paolo Saviano
 
managing your network environment
managing your network environmentmanaging your network environment
managing your network environmentscooby_doo
 
Trash Robotic Router Platform - David Melendez - Codemotion Rome 2015
Trash Robotic Router Platform - David Melendez - Codemotion Rome 2015Trash Robotic Router Platform - David Melendez - Codemotion Rome 2015
Trash Robotic Router Platform - David Melendez - Codemotion Rome 2015Codemotion
 
BIRD Routing Daemon
BIRD Routing DaemonBIRD Routing Daemon
BIRD Routing DaemonAPNIC
 
Live Streaming with Receiver-based Peer-division Multiplexing
Live Streaming with Receiver-based Peer-division Multiplexing Live Streaming with Receiver-based Peer-division Multiplexing
Live Streaming with Receiver-based Peer-division Multiplexing Vamsi IV
 
Krzysztof Mazepa - Netflow/cflow - ulubionym narzędziem operatorów SP
Krzysztof Mazepa - Netflow/cflow - ulubionym narzędziem operatorów SPKrzysztof Mazepa - Netflow/cflow - ulubionym narzędziem operatorów SP
Krzysztof Mazepa - Netflow/cflow - ulubionym narzędziem operatorów SPPROIDEA
 
PLNOG15: VidMon - monitoring video signal quality in Service Provider IP netw...
PLNOG15: VidMon - monitoring video signal quality in Service Provider IP netw...PLNOG15: VidMon - monitoring video signal quality in Service Provider IP netw...
PLNOG15: VidMon - monitoring video signal quality in Service Provider IP netw...PROIDEA
 
HTTP and 5G (fixed1)
HTTP and 5G (fixed1)HTTP and 5G (fixed1)
HTTP and 5G (fixed1)dynamis
 

Similar to Live streaming in Android (20)

2015.7.17 JANOG36 BGP Flowspec Interoperability Test @ Interop Tokyo 2015 Sho...
2015.7.17 JANOG36 BGP Flowspec Interoperability Test @ Interop Tokyo 2015 Sho...2015.7.17 JANOG36 BGP Flowspec Interoperability Test @ Interop Tokyo 2015 Sho...
2015.7.17 JANOG36 BGP Flowspec Interoperability Test @ Interop Tokyo 2015 Sho...
 
PLNOG 13: P. Kupisiewicz, O. Pelerin: Make IOS-XE Troubleshooting Easy – Pack...
PLNOG 13: P. Kupisiewicz, O. Pelerin: Make IOS-XE Troubleshooting Easy – Pack...PLNOG 13: P. Kupisiewicz, O. Pelerin: Make IOS-XE Troubleshooting Easy – Pack...
PLNOG 13: P. Kupisiewicz, O. Pelerin: Make IOS-XE Troubleshooting Easy – Pack...
 
Gameboy emulator in rust and web assembly
Gameboy emulator in rust and web assemblyGameboy emulator in rust and web assembly
Gameboy emulator in rust and web assembly
 
RTSP Protocol - Explanation to develop API of RTSP Protocol
RTSP Protocol - Explanation to develop API of RTSP ProtocolRTSP Protocol - Explanation to develop API of RTSP Protocol
RTSP Protocol - Explanation to develop API of RTSP Protocol
 
HKG15-311: OP-TEE for Beginners and Porting Review
HKG15-311: OP-TEE for Beginners and Porting ReviewHKG15-311: OP-TEE for Beginners and Porting Review
HKG15-311: OP-TEE for Beginners and Porting Review
 
Robotix Tutorial 9
Robotix Tutorial 9Robotix Tutorial 9
Robotix Tutorial 9
 
Asa pixfwsm multicast tips and common problems
Asa pixfwsm multicast tips and common problemsAsa pixfwsm multicast tips and common problems
Asa pixfwsm multicast tips and common problems
 
Setup VoIP System and Interconnection with LTE network
Setup VoIP System and Interconnection with LTE networkSetup VoIP System and Interconnection with LTE network
Setup VoIP System and Interconnection with LTE network
 
Howto ethereal-wireshark-trace en
Howto ethereal-wireshark-trace enHowto ethereal-wireshark-trace en
Howto ethereal-wireshark-trace en
 
Talk@JanusCon2019: Janus, WebRTC and ML - Fantastic technologies and how to m...
Talk@JanusCon2019: Janus, WebRTC and ML - Fantastic technologies and how to m...Talk@JanusCon2019: Janus, WebRTC and ML - Fantastic technologies and how to m...
Talk@JanusCon2019: Janus, WebRTC and ML - Fantastic technologies and how to m...
 
Network Docs
Network DocsNetwork Docs
Network Docs
 
managing your network environment
managing your network environmentmanaging your network environment
managing your network environment
 
Trash Robotic Router Platform - David Melendez - Codemotion Rome 2015
Trash Robotic Router Platform - David Melendez - Codemotion Rome 2015Trash Robotic Router Platform - David Melendez - Codemotion Rome 2015
Trash Robotic Router Platform - David Melendez - Codemotion Rome 2015
 
BIRD Routing Daemon
BIRD Routing DaemonBIRD Routing Daemon
BIRD Routing Daemon
 
Live Streaming with Receiver-based Peer-division Multiplexing
Live Streaming with Receiver-based Peer-division Multiplexing Live Streaming with Receiver-based Peer-division Multiplexing
Live Streaming with Receiver-based Peer-division Multiplexing
 
netLec5.pdf
netLec5.pdfnetLec5.pdf
netLec5.pdf
 
Krzysztof Mazepa - Netflow/cflow - ulubionym narzędziem operatorów SP
Krzysztof Mazepa - Netflow/cflow - ulubionym narzędziem operatorów SPKrzysztof Mazepa - Netflow/cflow - ulubionym narzędziem operatorów SP
Krzysztof Mazepa - Netflow/cflow - ulubionym narzędziem operatorów SP
 
PLNOG15: VidMon - monitoring video signal quality in Service Provider IP netw...
PLNOG15: VidMon - monitoring video signal quality in Service Provider IP netw...PLNOG15: VidMon - monitoring video signal quality in Service Provider IP netw...
PLNOG15: VidMon - monitoring video signal quality in Service Provider IP netw...
 
Hexapod ppt
Hexapod pptHexapod ppt
Hexapod ppt
 
HTTP and 5G (fixed1)
HTTP and 5G (fixed1)HTTP and 5G (fixed1)
HTTP and 5G (fixed1)
 

Recently uploaded

Ronisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited CatalogueRonisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited Catalogueitservices996
 
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdfAndrey Devyatkin
 
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...OnePlan Solutions
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxAndreas Kunz
 
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...Bert Jan Schrijver
 
Effectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorEffectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorTier1 app
 
Best Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh ITBest Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh ITmanoharjgpsolutions
 
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdfEnhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdfRTS corp
 
Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZABSYZ Inc
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringHironori Washizaki
 
Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Rob Geurden
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identityteam-WIBU
 
Introduction to Firebase Workshop Slides
Introduction to Firebase Workshop SlidesIntroduction to Firebase Workshop Slides
Introduction to Firebase Workshop Slidesvaideheekore1
 
Strategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero resultsStrategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero resultsJean Silva
 
eSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolseSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolsosttopstonverter
 
What’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 UpdatesWhat’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 UpdatesVictoriaMetrics
 
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...OnePlan Solutions
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalLionel Briand
 
Keeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository worldKeeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository worldRoberto Pérez Alcolea
 
Zer0con 2024 final share short version.pdf
Zer0con 2024 final share short version.pdfZer0con 2024 final share short version.pdf
Zer0con 2024 final share short version.pdfmaor17
 

Recently uploaded (20)

Ronisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited CatalogueRonisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited Catalogue
 
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf
 
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
 
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
 
Effectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorEffectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryError
 
Best Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh ITBest Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh IT
 
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdfEnhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
 
Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZ
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their Engineering
 
Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identity
 
Introduction to Firebase Workshop Slides
Introduction to Firebase Workshop SlidesIntroduction to Firebase Workshop Slides
Introduction to Firebase Workshop Slides
 
Strategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero resultsStrategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero results
 
eSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolseSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration tools
 
What’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 UpdatesWhat’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 Updates
 
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive Goal
 
Keeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository worldKeeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository world
 
Zer0con 2024 final share short version.pdf
Zer0con 2024 final share short version.pdfZer0con 2024 final share short version.pdf
Zer0con 2024 final share short version.pdf
 

Live streaming in Android

  • 1.
  • 2. Live Streaming in Android Ahmet Oğuz Mermerkaya Software Developer Aselsan @mekya84 ahmetmermerkaya@gmail.com
  • 3. * Ahmet Oğuz Mermerkaya ● Writer of an Android Application Programming book, Merhaba Android, in Turkish ● Member of GDG Ankara ● Software Developer in Aselsan, Defense Industry Company in Turkiye
  • 4. * Outline ● How live streaming works ● Building FFmpeg(with x264 and fdk-aac) ● Using Vitamio MediaPlayer ● Implementing a RTSP Server ● Sending Previews and Audio From RTSP Server ● Receiving and Playing Audio On Client
  • 5. * How live streaming works ● RTSP (Real Time Streaming Protocol) ● RTP (Real Time Protocol)
  • 6. * How live streaming works ● RTSP (Real Time Streaming Protocol) ● RTP (Real Time Protocol) This is the part FFmpeg takes place
  • 7. * What is FFmpeg? ● Open-source, cross-platform multimedia framework ● Supports almost all codecs and formats(H264, H263, AAC, AMR, MP4, MP3, AVI) ● Streams Audio and Video ffmpeg.org
  • 8. * Building FFmpeg ● Download o FFmpeg (http://fmpeg.org) o fdk_aac for using AAC encoder (http://sourceforge.net/projects/opencore-amr/files/fdk-aac/) o libx264 source code for H264 encoder (http://www.videolan.org/developers/x264.html) o Android NDK for cross compiling(http://developer.android.com) ● Configure & Make
  • 9. * Building FFmpeg - Configure & Make export PATH=ANDROID_NDK/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin:$PATH #libx264 ./configure --cross-prefix=arm-linux-androideabi- enable-pic --disable-cli -enable-static --disable-shared - -host=arm-linux --extra-cflags="-march=armv7-a -mfloat-abi=softfp" --sysroot=/path/to/android- ndk/platforms/android-87arch-arm/ make #fdk-aac ./configure --host=arm-android-eabi-linux --enable-static --prefix=/path/to/fdk-aac/ --disable-shared make #ffmpeg ./configure --disable-everything --enable-gpl --enable-libx264 --enable-libfdk-aac --enable-nonfree -- enable-pthreads --cross-prefix=arm-linux-androideabi- --arch=arm --sysroot=/path/to/android- ndk/platforms/android-8/arch/arm/ --extra-cflags="-march=armv7-a -mfloat-abi=softfp" --extra-cflags="- I./x264" --extra-cflags="-I./fdk-aac/include/" --extra-ldflags="-L./x264" --extra-ldflags="-L./fdk-aac/lib" --datadir="/data/ffmpeg/bin/ffpresets" --enable-version3 --enable-decoder=rawvideo --enable-demuxer=rawvideo --enable-decoder=aarc --enable-demuxer=aac --enable-muxer=h264 --enable-encoder=pcm_s16le --enable- protocol=rtp --enable-protocol=udp --enable-muxer?rtp --enable-demuxer=image2pipe --enable-muzer=adts -- enable-muxer=pcm_s16le --enable-demuxer=pcm_s16le --enable-demuxer=h264 --enable-filter=scale --enable- encoder=libx264 --enable-encoder=libfdk_aac -enable-protocol=pipe --enable-decoder=pcm_s16le --enable- filter=aresample make
  • 10. * Using Vitamio Player ● Get it from vitamio.org and extract Line 1 VideoView videoView = (VideoView) findViewById(R.id.videoView); Line 2 videoView.setVideoPath("rtsp://IP_OF_ANDROID_STREAM_SERVER:PORT/live.ts"); ● To start vitamio play with partial buffer, follow the instructions on http://vitamio.org/topics/104?locale=en Then we need a RTSP server
  • 11. * Implementing a RTSP Server Client (MediaPlayer - Vitamio) RTSP Server
  • 12. * Sending Previews From RTSP Server Line 1 public void startVideo(String address, int port) { Line 2 String videoCommand = "path/to/ffmpeg -analyzeduration 0 -pix_fmt nv21 Line 3 -s 480x360 -vcodec rawvideo -f image2pipe -i - -s 320x240 -crf 18 Line 4 -preset ultrafast -vcodec libx264 -f rtp rtp://"+address+":"+port; Line 5 Process ffmpegVideoProcess = Runtime.getRuntime().exec(videoCommand); Line 6 OutputStream ostream = ffmpegVideoProcess.getOutputStream(); Line 7 Line 8 getCamera().setPreviewCallback(new PreviewCallback(){ Line 9 public void onPreviewFrame(byte[] buffer, Camera cam) { Line 10 ostream.write(buffer); Line 11 ostream.flush(); Line 12 } Line 13 }); Line 14 }
  • 13. * Sending Audio From RTSP Server Line 1 public void startAudio(String address, int port) { Line 2 String audioCommand = "path/to/ffmpeg -analyzeduration 0 -f s16le -ac Line 3 44100 -ac 1 -i - -ac 1 -acodec libfdk_aac -f adts -vbr 3 Line 4 udp://"+address+ ":" + port +"/"; Line 5 Process ffmpegAudioProcess = Runtime.getRuntime().exec(audioCommand); Line 6 OutputStream ostream = ffmpegAudioProcess.getOutputStream(); Line 7 prepareAudioRecord(); Line 8 new Thread(){ public void run(){ Line 9 while(true) { Line 10 int len = audioRecord.read(audioBuffer, 0, audioBuffer.length); Line 11 ostream.write(audioBuffer, 0, len); Line 12 ostream.flush() Line 13 } Line 14 }}.start();
  • 14. * Receiving Audio On Client Line 1 public void receiveAudio() { Line 2 String audioCommand = "path/to/ffmpeg -analyzeduration 0 -f aac -strict -2 - acodec Line 3 aac -b:a 120k -ac 1 -i - -ac 1 -acodec pcm_s16le -ar 44100 -f s16le -"; Line 5 Process ffmpegAudioProcess = Runtime.getRuntime().exec(audioCommand); Line 6 OutputStream ostream = ffmpegAudioProcess.getOutputStream(); Line 7 DatagramSocket udpsocket = new DatagramSocket(PORT); Line 8 DatagramPacket packet = new DatagramPacket(new byte[2048], 2048); Line 9 new Thread(){ public void run(){ while(true) { Line 10 udpsocket.receive(packet); Line 11 ostream.write(datagramPacket.getData(), 0, datagram.getLength()); Line 12 ostream.flush(); Line 13 }}}.start();
  • 15. * Playing Audio On Client Line 1 public void playAudio(final InputStream istream) { Line 2 byte[] buffer = new byte[2048]; Line 3 int bufferSize = AudioTrack.getMinBufferSize(44100,...); Line 5 audioTrack = new AudioTrack(AudioManager.STREAM_MUSIC,44100, Line 6 AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_16BIT, Line 7 bufferSize, AudioTrack.MODE_STREAM); Line 8 audioTrack.play(); Line 9 while (true) { Line 10 int len = istream.read(buffer, 0, buffer.length); Line 11 audioTrack.write(buffer, 0, len); Line 12 audioTrack.flush() Line 13 } Line 14 }
  • 16. Demo
  • 17. * Android Developer Days ● Expected 1500~ participants ● Partner of Droidcon.com ● 15 co-organizers from 7 countries ● Free of charge ● This year more inspiration, more networking and more fun ● ADD 2012 web site -> www.androiddeveloperdays.com/2012 Date: June 14, 15 2013 Venue: METU, Ankara, Turkiye www.androiddeveloperdays.com
  • 18. Thank you for listening Live Streaming in Android Ahmet Oğuz Mermerkaya @mekya84 ahmetmermerkaya@gmail.com