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);
Related
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();
I'm using VLCJ and I wish to save a video clip I'm playing using mediaPlayer.playMedia(); to my desktop. I know this can be accomplished by setting media options using a :sout string but I don't know which options to set and I'm having trouble understanding the example option strings on the web. Could someone help by explaining the following :sout option string?
String[] options = {":sout=#transcode{vcodec=mp4v,vb=4096,scale=1,acodec=mpga,ab=128,channels=2,samplerate=44100}:duplicate{dst=file{dst=" + fileName + "},dst=display}", ":input-slave=alsa://hw:0,0"};
I just need an options array that creates an mp4 video using the fileName destination. These options fail/error out for me.
Also, VLCJ seems to be dropping a ton of frames with this error
avcodec decoder error: more than 5 seconds of late video -> dropping frame
by using these options
String[] options = {":sout=#transcode{vcodec=mp1v,vb=2048,scale=1,acodec=mpga,ab=128,channels=2,samplerate=44100}:duplicate{dst=file{mux=mpeg1,dst=" + fileName + "},dst=display}", ":input-slave=dshow://hw:0,0" };
To save a raw stream, use media options similar to the following when you play the media:
String mrl = "your-streaming-mrl";
String[] opts = {"sout=#duplicate{dst=std{access=file,mux=raw,dst=output-file.ext}}"};
Clearly you replace "your-streaming-mrl" and "output-file.ext" with whatever is appropriate.
And then:
mediaPlayer.playMedia(mrl, opts);
You will need to wait (listen) for a media player "finished" event before your saved file is ready.
You may also need to explicitly invoke release() on the media player before your saved file is ready.
hy there, i hope i can explain my question:
i´ve an ip webcam and i want to read&save a .jpg file out of the path
webacm-ip-adr:8084/snapshot.cgi
i´ve little java experience and would like to program it in processing to keep it simple:
i´ve found this link:
https://www.java.net/node/702486
but its a slight overkill for me to understand it would be great if i can work with the 2 processing examples: web/loadingimages and net/httpClient
or do i make an logic mistake and its not solveable this way ?
You can use java lib "Apache Commons IO" to done it.
My Simple Code:
URL url = new URL("http://webacm-ip-adr:8084/snapshot.cgi");
InputStream input = url.openStream();
String jpg = "sample.jpg";
FileOutputStream output = new FileOutputStream(jpg);
IOUtils.copy(input, output);
Class "IOUtils" is a common tool for IO stream operation in commons-io jar.
I am trying to program a classroom assistant (I work as a teacher) using Java who will give spoken instructions to students/ask them questions etc. I have managed to connect successfully to the cerevoice cloud to create an ogg file
e.g. "https://cerevoice.s3.amazonaws.com/Heather220501c8c2e94d4650f64f7d951bf76b08b0eb.ogg"
however when I try to play this ogg file from java I get an error that it could not be found or that it is an unsupported audio resource depending on the ogg player I use (i have tried EasyOGG and TinySound so far) - both the ogg players work successfully locally but I cannot get them to play a file directly from the website.
Examples how I have tried to reference it:
URL url = new URL("https://cerevoice.s3.amazonaws.com/Heather220501c8c2e94d4650f64f7d951bf76b08b0eb.ogg");
Music song = TinySound.loadMusic(url);
song.play(true);
OggClip ogg = new OggClip("https://cerevoice.s3.amazonaws.com/Heather220501c8c2e94d4650f64f7d951bf76b08b0eb.ogg");
ogg.loop();
Apologies for my ignorance I'd really appreciate any help anyone can give with playing this file! =)
Many thanks,
Darren
Edited to show using a literal String value to help clarity
Edit very ugly hack 1 solution: //opens a browser window plays file then closes window
String url = "https://cerevoice.s3.amazonaws.com/Heather220501c8c2e94d4650f64f7d951bf76b08b0eb.ogg"; //hard coded here for simplicity but URL dynamically retrieved from webservice
java.awt.Desktop.getDesktop().browse(java.net.URI.create(url));
Thread.sleep(3000);
Runtime.getRuntime().exec("taskkill /F /IM chrome.exe");
Edit slightly less ugly hack 2 solution:
//creation of a temporary file to allow playing from java without creating a browser window
try{
Files.deleteIfExists(Paths.get("C:/cere/temp.ogg"));
try (InputStream in = URI.create(url.value).toURL().openStream()) {
Files.copy(in, Paths.get("C:/cere/temp.ogg"));
}catch(IOException e) {
}
JMF provides a class MediaPlayer which can be used as a full-featured player. However, I can't find a way to play an audio file. Some snippets of the code used.
import javax.media.bean.playerbean.MediaPlayer;
// ....
MediaPlayer mp = new MediaPlayer();
mp.setMediaLocation(location of file); // <- syntax error!
mp.start();
But it doesn't work. Eclipse shows this error:
Syntax error on token "setMediaLocation", Identifier expected after this token
..on setMediaLocation() method.
Can someone tell me how to use MediaPlayer class to play audio file? and what is wrong in my coding?
You do not literally have ..setMediaLocation(location of file); in the source do you? I thought that was paraphrased.
In that case, the answer is to supply an argument to the setMediaLocation() method. The docs. specify a String or MediaLocator instance.
I avoid using String instances to represent file or URL based sources. If a method needs a File or URL - give it a File or URL. That leaves the best option as a MediaLocator(URL). Here is how it might go. First we need a URL - there are a number of different ways of getting one, depending on what the source of the URL is. E.G. the internet, a file on the local file-system, or an embedded resource in a Jar delivered with the app. The last two might be something like:
File based URL
File mediaFile = new File("user.mp3");
URL mediaURL = mediaFile.toURI().toURL();
// ...
Embedded resource URL
URL mediaURL = this.getClass().getResource("/path/to/our.mp3");
// ...
Once there is a mediaURL instance, we can create a locator and use it in the method.
Using the URL
MediaLocator mediaLocator = new MediaLocator(mediaURL);
MediaPlayer mp = new MediaPlayer();
mp.setMediaLocation(mediaLocator);
// ...
General tips
JMF is an abandoned API.
Since you seem interested only in audio, look to use Java Sound. It can play audio samples just fine, is part of core Java, and with a small part of the JMF, can play MP3 format (see link for details).
You seem new to the abandoned API being used, Eclipse and debugging. Perhaps you should focus on simpler things for the moment. Media handling is an advanced topic.