does anybody know how to send a video data stream from one side written by java to another side written by flex and then display it? I just know that on flex one method is to use netstream class get the real-time video stream and bind with a videodisplay to display it. But which class I should use to send this video stream in java and which class I need to use in flex to receive this flow and pass it to the NetStream class?
Does anybody have any ideas about that?
Thanks!
Check out Red5 - http://www.red5.org/
It's a free open source platform for streaming media to flash / flex. It's been around for years and quite mature.
Telling you how to implement it for your particular situation is out of scope of a Q&A format, but I can tell you from experience that red5 is an easy to implement solution relative to rolling your own or flash media server (which is pricey!)
More tutorials and examples here:
http://trac.red5.org/wiki/Documentation
If you decide to write your own (why?) - check out Java Media Framework (JMF) - http://www.oracle.com/technetwork/java/javase/specdownload-136569.html
For android - you're going to want to take a look at :
android.hardware.Camera;
android.media.MediaRecorder;
then something along the lines of :
recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
recorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264); // might try MPEG_4_SP as well
recorder.start();
I specified in the above codecs that are in a format that is friendly to flash.
Related
I'm trying to build showcase video streaming from a server to a client, but I need to process the stream before sending. I like to do all in java, and client be an Android device.
I just heard about a library called Xuggler which is Java-based and looks promising. Does it provide any functionalities to access the video streams and do some image processing on them before transmission?
Please introduce any other Java-based media streaming / processing libraries if you know of.
For Java video processing, despite being long deprecated, Xuggler has been the best solution that I've found, someone else might know of an alternative.
Since it's not supported anymore you have to do a few things to get started. First find a Xuggler-5.4.jar, Also you need the Java 7 Jdk to run it, it will not work with Java 8, then you need the sl4j-api and sl4j-simple Jars.
It has a complicated but well documented api, but the main gist is you use the MediaToolAdapter interface, create an IMedia Reader and Writer, add something implementing the interface to the reader as a listener, and in the implemented methods for audio and video you can process the data in each frame and pass it to the writer.
This example is a good place to start:
https://github.com/artclarke/xuggle-xuggler/blob/master/src/com/xuggle/mediatool/demos/ModifyAudioAndVideo.java
We a have jboss server running and have a basic web setup using Spring but now I would like to stream video into the browser. I am trying to use xuggle but then I read on their website that you can't put it into an Applet or use it with java webstart, so I'm assuming that means I can stream to a browser, is this assumption correct? If so does anyone else know any libraries or how I should go about doing this? If you need any more info or have questions I'll be happy to answer although I'm very new to streaming video and relatively knew to Spring.
UPDATE: So I'm able to generate a video using xuggle, and then I can embed that video in my html code... but I can't generate and stream at the same time. Does anyone have any ideas how to make xuggle push date out to my tomcat server?
You may want to look at Red5 media server.
Since you are doing jsp, just have your code write out the HTML 5 video element. That will provide basic video functionality. This will work in all HTML 5 compliant browsers as well as all mobile devices.
This may or may not even be possible, but here's the situation: I want to use the ActionScript 3 Camera class to capture a video from a local camera (webcam, built-in camera, etc) and then play that video back within the flash application.
I'm considering the possibility of sending it to a Flash Media Server and then streaming it back as an on-demand video, but I would ideally like to keep the whole thing client-side for best performance.
I'm open to the idea of using a different platform (Java was one consideration) as long as it can be embedded in a web page, but I would like to keep development as straightforward as possible and make the process of accessing the application as easy as possible for the end user, which is why I chose Flash initially.
If anyone knows of a way to do this I welcome any input.
Okay, here's an update for anyone else who might be up against the same hurdle I was. I was able to accomplish what I wanted — to record a video, allow the user to preview it, then upload it from one flash application — by utilizing a utility written by Lee Felarca (zeropointnine — http://www.zeropointnine.com/ ) called flvEncoder.
The concept is as such:
Record audio and video data to raw format (much like Valentin Simonov suggested)
Pass the data to flvEncoder for encoding in Flash FLV format and get a ByteArray back. I know it seems redundant to say Flash FLV, but I word it that way because Flash and Adobe Media Player appear to be the only things capable of interpreting the result.
Create a NetStream instance and put it in Data Generation Mode, use the appendBytes() method to pass the encoded data to a Video object linked to an input NetStream.
Use FileReference.upload() to send the data to the server in an HTTP request.
It could potentially eat a lot of memory, but I only needed to record short videos anyway. I won't post the code here because it's messy and tied to a proprietary project, but I hope this information is helpful to someone. Thanks for the responses!
The easiest way would be to use FMS, Wowza or Red5 media servers. You just use NetStream to send data to your server, save movies there and stream back.
Also I suppose it is the only reliable way of doing it. Camera, Video or NetStream objects don't have access to actual video bytes. What you could do is to add an instance of Video to your Camera and draw it into a bitmap every 1/24th a second. After that you will still have to encode data or you'll run out ouf memory very fast. Here I'm not sure if there are any flv/h264 codecs made with as3 available. But anyway I bet it will be slow.
This could be quite an intresting topic for people who are intrested in livestreaming from your device to a webserver. (Primary Android/Java)
I have finally found a way on how to livestream from my device's camera to my webserver (website). On a wifi network it takes approx. 1 frame/ second to show on a wifi network, It also works on EDGE/3G network. In this topic/question, I want to discuss new techniques, improvements, ideas about livestreaming as I will share mine with yours (codes are appreciated too.)
My code repeatedly takes a snapshot from the camera preview using setOneShotPreviewCallback() to call onPreviewFrame(). The frame is delivered in YUV format so raw2jpg() converts it into 32 bit ARGB for the jpeg encoder. NV21 is a YUV planar format.
getPicture() is called, by the application, and produces the jpeg data for the image in the private byte array mCurrentFrame and returns that array.
After this, the byteArray mCurrentFrame gets Base64Encoded and send to my webserver in a HTTP POST method together with the string value of Base64 and a own ID code so people won't be able to also send another image to it. At the webserver, it gets decoded again and putted into the file test.jpg. PHP and Javascript is running on the webserver. PHP gets the POST method and JavaScript reloads the image every 750 seconds. This is basically how it works.
Now I am very intrested in your ideas, improvements and other things you would like to add/ask. Here are some of my questions:
1) What would be the best method for live streaming WITH audio? Video Recording OR my method + Audio recording?
2) How would you approach video record streaming?
3) How would you stream audio to the webserver? (Main goal) (With Java, PHP and JavaScript)
4) I am also planning to add typical live streaming feautures to i, e.g. when a famous person appears, you could have the ability to show his name while you are live streaming, or just add an image from your sd directory to your livestream. Would you also decode it and overlay the image, or put the image in your livestream in some way?
This topic is primarly for questions, so please this could be some great help for some people out here. Therefore I added a bounty of 50 (woot!) rep to it.
Sincerely,
XverhelstX
It strikes me that http posting is probably not a good way to do live streaming of video to your server. Other people have been playing with live streaming and they've used a socket to broadcast live video streams and audio streams to their servers.
I thought this was fascinating -- here's a link.
http://www.mattakis.com/blog/kisg/20090708/broadcasting-video-with-android-without-writing-to-the-file-system
But the guy also posted a partial code sample -
String hostname = "your.host.name";
int port = 1234;
Socket socket = new Socket(InetAddress.getByName(hostname), port);
ParcelFileDescriptor pfd = ParcelFileDescriptor.fromSocket(socket);
MediaRecorder recorder = new MediaRecorder();
// Additional MediaRecorder setup (output format ... etc.) omitted
recorder.setOutputFile(pfd.getFileDescriptor());
recorder.prepare();
recorder.start();
The cool part I didn't know about is the ParcelFileDescriptor - which creates a file on the android filesystem that is actually a pipe to a socket - so anything that gets written to the file gets broadcast out over the web to a remote server. Sockets are the right way to go about doing this sort of thing too because they allow you to continuously send data until your recording is complete without having to re-send headers over and over.
What I think is cool about this technique is that he's literally taking the output from MediaRecorder (which is going to be an encoded video stream) and pumping it over a socket to his server. Then he can simply save out the data that's coming in over the socket. No frame by frame, no processing (Android SDK doesn't expose the encoders in the SDK very well and they're pretty performance intensive).
People report that it works, but I haven't tested. Anyway, hope this is helpful.
You are sending a whole snapshot each time? Why don't you try to use some video compressing techniques, like instead of sending a full image each time you send a compressed version (maybe a diff or something like that) and them on the server you create the image based on your last image and the data just received. I think all video codecs do this, you could try looking at some of the open codecs specification to get some ideas.
About audio. I would send the audio stream separated and them sync it with the video streaming based on which video frame we are showing right now.
Basically, I would try to get my streaming as close as possible to how a real video streaming works. Maybe you could look into ffmpeg, ffmpeg has an rtsp server if you could build that for android them you would simplify your work a lot.
Note: I'm not an Android developer.
From what you've said it seems like your just taking a snapshot instead of any real streaming. If your worried about bandwidth then use a lower resolution. Exactly how to do this in android I'm not sure
I think that if there's built in streaming classes that you'll be able to get both the video stream and the audio stream. Don't do any local transcoding (your raw2jpg() counts as transcoding) as it might use too much processing power. Just take the stream, compress it, and send it to your server.
EDIT:
Some Links to get you started
An interesting project that turns the Android phone into an IP camera. You could dig around the code to figure out how they get ahold of the camera stream
An SO question on this topic
1) What would be the best method for live streaming WITH audio? Video Recording OR my method + Audio recording?
This really depends on your view of "best". If you are looking for resources and not the quality, then your way is really good.
Otherwise, you should use a native streaming mechanism or maybe implement a video streaming technique to stream and encode video.
3) How would you stream audio to the webserver? (Main goal) (With Java, PHP and JavaScript)
I suggest that you stick to MediaRecorder because it really does what your doing in a good way. Still try to find a way to get the stream in order to send in your way as files are not the best choice although you could stick to files and send small files in a timely manner. In this way you could put a bigger portion of the load on the server rather than the client.
4) I am also planning to add typical live streaming feautures to i, e.g. when a famous person appears, you could have the ability to show his name while you are live streaming, or just add an image from your sd directory to your livestream. Would you also decode it and overlay the image, or put the image in your livestream in some way?
Do not even try to put it in your livestream. With your php server, you have more capabilities to send this info alone with certain tag and let the server do the processing or maybe integration of these with the video
I want to create a html page that can be used to upload videos and also able to playback the videos. I am totally new to this. 2 weeks before only i learnt uploading and processing images. So, i need some guidelines like
How to upload video?
what concepts i have to learn?
what are all the libraries i may require?
How to convert it into flash format?
How to stream it back to user?
I am using Java in server side!
And i also want to know that Is there any way to do them all with AJAX?
Any suggestions or advices or links or anything that can help me would be more appreciative!!!
Thanks in Advance!
Hmmm... seems interesting..
How to upload video?
Well it depends.
If you are using a thick client (aka swing or swt) then you can use Apache Commons File Uplaod API.
For JSP http://www.roseindia.net/jsp/file_upload/index.shtml
With JSF - (http://balusc.blogspot.com/2008/02/uploading-files-with-jsf.html and http://onjava.com/pub/a/onjava/2005/07/13/jsfupload.html)
With AJAX - http://www.openjs.com/articles/ajax/ajax_file_upload/ (basic example but enough to guide in right direction :))
what concepts i have to learn?
As a library integrator you will need to know about the front end technology you are going to use (JSF, JSP or PHP etc)
You should know about basic of multimedia handling in java (sometimes help in debugging)
Basic of flash video (specially how streaming works in internet video http://blog.xuggle.com/2009/01/23/overly-simplistic-guide-to-internet-video/ )
Assuming you already know about servlets etc.
Have a look at HTML5. It has some great offerings like video playback etc.
what are all the libraries i may
require?
Again depends
IF choosing javascript for front end + AJAX in mind http://jqueryui.com/ or http://jquery.com/
IF JSF is the choice for front end - http://www.jboss.org/richfaces or http://www.primefaces.org/ along with JSTL etc
You will need a library like http://www.xuggle.com/xuggler/
Xuggler is the easy way to uncompress,
modify, and re-compress any media file
(or stream) from Java. Xuggler is
available under the GNU Lesser General
Public License.
Most of the Flash video sites either use xuggler or FFMpeg for conversion and playback.
How to convert it into flash format?
Use Xuggler http://www.xuggle.com/xuggler/. It uses the FFMpeg http://www.ffmpeg.org/. Though you have to use at server side for conversion (As of now you can not use it in applet). Refer to http://wiki.xuggle.com/Tutorials for more information.
How to stream it back to user?
I normally do it in this fasion.
<embed height="385" width="640" type="application/x-shockwave-flash" src="http://s.ytimg.com/yt/swf/watch_as3-vflofTU0v.swf" id="movie_player" flashvars="rv.7.length_seconds=107&rv.2.thumbnailUrl=http%3A%2F%2Fi4....." allowscriptaccess="always" allowfullscreen="true" bgcolor="#000000">
I hope it will help you :)