RTSP stream with OpenCV [duplicate] - java

I'm trying to access a RTSP video stream from an IP camera using OpenCV and Java. I can access the stream using VLC player with the following format: rtsp://192.168.1.10:554/rtsp_live0 but when I try to use OpenCV the video stream seems to always be closed.
The code I'm using... (simplified)
VideoCapture capture = new VideoCapture();
capture.open("rtsp://192.168.1.10:554/rtsp_live0");
while(!capture.isOpened())
System.out.print("Not opened :( \r");
I have a Mustcam H806P and found the stream URI from this website: http://www.ispyconnect.com/man.aspx?n=ipcamera
What am I doing wrong?

I'm reporting Alexander Smorkalov answer on answers.opencv.org
OpenCV uses ffmpeg library for video I/O. Try to get video stream with console ffmpeg tool. The address must be the same.
See also here OpenCV - how to capture rtsp video stream

Related

Java: playing audio from a youtube video

I'm thinking about coding a Java applet that would take in the top 100 or so songs, find their samples (music that appears within the songs) off WhoSampled.com and then playing those samples off of YouTube.
My problem is the playing part, let's say I have the URL. What's the best way to deal with that in Java, do you think ripping the audio off and playing the audio from there would be best, or should I try to control a sentient YouTube player.
I'm leaning towards extracting the audio, and this: thread mentions a way to extract that audio, however the code:
wget http://www.youtube.com/get_video.php?video_id=...
ffmpeg -i - audio.mp3
Is not written in Java. How do I, if possible convert this to run in a Java program? Or does anyone know a good way in Java
Thank you for your suggestions.
You can use an FFMPEG Java wrapper like this one https://github.com/bramp/ffmpeg-cli-wrapper/
An example can be found in Readme. Converting MP4 to mp3 should be like this:
FFmpeg ffmpeg = new FFmpeg("/path/to/ffmpeg");
FFprobe ffprobe = new FFprobe("/path/to/ffprobe");
FFmpegBuilder builder = new FFmpegBuilder()
.setInput("input.mp4") // Filename, or a FFmpegProbeResult
.overrideOutputFiles(true) // Override the output if it exists
.addOutput("output.mp3") // Filename for the destination
.setFormat("mp3") // Format is inferred from filename, or can be set
.setAudioCodec("aac") // using the aac codec
.setAudioSampleRate(48_000) // at 48KHz
.setAudioBitRate(32768) // at 32 kbit/s
.done();
FFmpegExecutor executor = new FFmpegExecutor(ffmpeg, ffprobe);
// Run a one-pass encode
executor.createJob(builder).run();

Sony Ip camera opencv Java

I am trying to take images from an IP cam (sony snc p1) for motion detection using opencv java. The stream is in mjpeg format and I am using opencv's VideoCapture to try to retrieve an image. I can grab an image from a video file using videocapture but when I try to open the camera doesn't work. I can view the stream on vlc but that ip address doesn't work on opencv. This is the code that I use:
while (true){
VideoCapture camera1=newVideoCapture("http://192.168.0.101/mjpeg");
if (!camera1.isOpened())
System.out.println("Cannot open file");
}
What version are you using? In openCV 2.4 this is a known bug. (fixed in later versions)
You can olso try adding a dummy param, at the end, something like camera1.open("http://192.168.0.101/?dummy=video.mjpg");
because opencv VideoCapture expects an extension at the end of the file name.

Opencv java IP camera mjpg stream

I am trying to grab images from a IP cam for image processing using opencv java. The stream is in mjpg format and I am using opencv's VideoCapture to try to retrieve a image. I can grab a image from my webcam using videocapture but when I try to open a IP cam it will never open. I can also view test stream here. I tried searching around for an answer but none pf them seem to work. I am on windows 7 with opencv 2.4.9. This is the code I am trying to get to work.
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
VideoCapture vc = new VideoCapture();
vc.open("http://construction.sfhs.com/mjpg/video.mjpg");
Thread.sleep(100);
while(true) {
System.out.println(vc.isOpened());
Thread.sleep(100);
}
It just outputs false
I had the same problem.
Try adding "opencv_ffmpeg249.dll" to the folder of your program.

Android record in FLAC file

How can I make a record with a microphone in FLAC file?
I have tried this:
import javaFlacEncoder.FLAC_FileEncoder;
FLAC_FileEncoder flacEncoder = new FLAC_FileEncoder();
File outputFile = new File(dir + "/flac1.flac");
flacEncoder.encode(file, outputFile);
Error:
E/AndroidRuntime(5891): java.lang.VerifyError: javaFlacEncoder/FLAC_FileEncoder
Whether it is possible to record sound in format Wav using Java 1.6 and android 4.0.3?
From what earlier comments here were alluding to:
From this link Android appears only support AMR, PCM and GSM codecs. If you need .flac (often google's services favorite) I suggest using the lossless PCM (supports .wav) formats and using FFMPEG, SOX or some other audio converter service to then make them .flac.
(all codecs implemented in Android 3.1x (level 12) so this should apply to your version)

java: rtsp stream to file using vlcj

I am trying to store a rtsp stream to file using vlcj.
I've done a couple of tutorials, looked at some of their test projects but haven't been able to do this.
Any ideas? Thanks in advance!
EDIT
Found an An example of transcoding and saving video from a capture device. Trying to get it to work. Looking for some documentation on the "options" part in mediaPlayer.playMedia(mrl, options);.
Someone answered me on the video lan forums, check it out.
My relevant code is below, where the most important part is the additional option for the vlc media player ":file{dst=C:/Users/the man/yahoo.mp4}".
mFactory = new MediaPlayerFactory();
mPlayer = mFactory.newHeadlessMediaPlayer();
String mrl = "rtsp://#" + addressStr + ":" + mPhoneRTSPPort;
String options = ":sout=#transcode{vcodec=h264,venc=x264{cfr=16},scale=1,acodec=mp4a,ab=160,channels=2,samplerate=44100}"
+ ":file{dst=C:/Users/the man/yahoo.mp4}";
mPlayer.playMedia(mrl, options);

Categories