I have a JavaFX application which uses a MediaPlayer and a MediaView to play videos. I've been testing with some mp4 video's I have and it works perfectly fine, audio, visuals, all looks good. Only not for a specific type of mp4 video.
I have the full series of a show I like on my hard drive, and for some reason when I try it with ANY of those videos, I can see the video play perfectly but the audio is just not there. The MediaPlayer is not muted, and the volume is at 1.0 (100%). When I use an AudioSpectrumListener it doesn't even fire, but it does with other videos.
I doubt the code matters since it works fine for any other video, but I'll put it anyways. I'm using an MVC design pattern, so the MediaPlayer is stored in a model object.
public void openVideo() {
File selectedFile = chooseFiles(VIDEO_EXTENSIONS); // opens file chooser for given extensions
if (selectedFile == null) return;
if (dataModel.getVideoPlayer() != null) dataModel.getVideoPlayer().dispose();
dataModel.setVideoPlayer(new MediaPlayer(new Media(selectedFile.toURI().toString())));
dataModel.getVideoPlayer().play();
}
The MediaView is bound to the MediaPlayer in the data model through this line of code:
mediaView.mediaPlayerProperty().bindBidirectional(dataModel.videoPlayerProperty());
The videos that don't work are all about 22 minutes long and 1GB in size. I've attached a screenshot of the properties of a video that works fine, and one which doesn't play the audio.
Works fine, this is a screen recording I made with OBS.
Won't play audio, episode of a show I like to watch.
The only audio-difference is the bit rate, something I don't think should make any difference.
I am starting to think this may be a bug with javaFX, but I really hope that there's something I can do to make this work.
Related
Hey folks I'm trying to save video from a video tag.
This is part of a scraping exercise on Tiktok and I cannot use the url directly to save the video, either in the browser or server.
I also cannot use canvases as I'm getting a tainted canvas error.
What would be the best way to save the video data?
// Example code
let video = document.querySelector('video');
let src = video.src;
// Do something with the el or the source??
I'm currently working on a poker application for fun and I've encountered another issue when trying to work with imageviews.
Right now my structure for my images is the following:
JavaFXApplication1\src\images
that "images" folder contains two more folders, one being "cards" and the other "playerImages".
Here is a screenshot of it also:project structure
Currently I am using a document relative path within scene builder to initially load the images for each of the cards and players. for each of the cards, the imagepath initially is "#..\images\cards\back.png" which is set in scenebuilder. this method works perfectly fine when launching the application. however, for the player images next to the cards, i have "#..\images\playerImages\player1.png" for example and this doesnt work for some reason.
In scenebuilder the "player1.png" image shows up where it should, but disappears when i launch everything.
I read through Images not showing on launch by the main, but showed on Scene builder but Im not not sure the solution for that is the same for me, as my images are in my source folder.
I tried using the fx:id and setting the image manually in my controller class, but was receiving an error stating that my input stream was null.
I also tried just adding "player1.png" to my root images folder and using that path, and that still didnt work. yet, when I change the player1 image path to anything in the cards folder it works. I dont understand why it works for the images in the cards folder but not in the playerImages folder. Both of those folders are in the same location.
I apologize if this was already answered somewhere else and i am too oblivious to see it, but any insight into this seemingly simple problem would be greatly appreciated.
if you have a similar project structure:
--main
--java
--src
--resources
--images
--cards
back.png
--players
player1.png
you can set images from resources in your java-code. But you need to use getResources()
For example:
#FXML
private ImageView imageView;
Image image = new Image(getClass().getResourceAsStream("/images/players/player1.png"));
imageView = new ImageView(image);
Of course directory "resources: shuild be marked as resources root
I tried to display a "mjpeg webcam url" on my javafx application but nothing shows
Code is:
#FXML
private MediaView mediaView;
...
Media media = new Media("http://192.165.96.36/mjpg/video.mjpg");
MediaPlayer player = new MediaPlayer(media);
player.setAutoPlay(true);
mediaView.setMediaPlayer(player);
mediaView.setVisible(true);
Do you know how can I display mjpeg url videos ?
Thanks
As far as I know, only the following video formats are supported:
FLV containing VP6 video and MP3 audio; MPEG-4 multimedia container with H.264/AVC (Advanced Video Coding) video compression
So you'll first have to transcode your video to h.264 (try ffmpeg).
As a comitter of the mjpegstreamer OpenSource project I'd recommend to try
out the latest version of:
https://github.com/BITPlan/com.bitplan.mjpegstreamer
As of 2019-02 it's being ported to JavaFX. You might want to raise issues as you see needs that are not fullfilled.
Since it's opensource you can also see how the mjpeg videos are handled.
I have this application where I display content together with a video file. The video files are either in image/jpeg (MJPG format according to vlc) or video/x-h264 format.
To do this, I use a mediasource combined with a video output element to display the video. This is working perfectly when using h264. However, this is not working at all with the mjpg video files.
But I have no idea how to do this. I have read up on libraries using either ffmpeg or vlc, but I can't seem to find libraries to use in combination with QML elements, only with regular QWidgets.
Here is some (stripped down) relevant code, it is really simple and I would prefer to keep it simple. So ideally I am just looking for a way to get a codec into the project or something like that.
property string videoLocation
FileDialog {
id: videoFileDialog
onAccepted: {
videoLocation = fileUrl
}
}
MediaPlayer {
id: mediaplayer
source: videoLocation
autoPlay: false
}
VideoOutput {
id: videoOutput
source: mediaplayer
}
Maybe relevant:
my system is ubuntu 13.04 and I use qt 5.3.
Thx in advance
EDIT: I have figured out the problem I think: The stream is recorded using gstreamer > 1.0. For some reason it won't play back in 0.10. If I record using the same settings, but with gstreamer 0.10, everything is fine and my application works (though this option is not feasible, I really need to capture using > 1)
Here is the code I am using to capture the stream to a file:
gst-launch-0.10 v4l2src device=/dev/cam1 ! image/jpeg,width=320,height=240,framerate=30/1 ! matroskamux ! filesink location=videotest.mkv
Any suggestions for a setting that is compatible between new and old gstreamer?
On *nix platforms, QtMultimedia uses GStreamer as its backend. On GStreamer's website it appears that JPEG is a supported format (and one would assume that includes motion jpeg.)
Check your package manager to make sure you have all of GStreamer's plugins installed. There's at least three different packages of GStreamer plugins on Ubuntu.
So I fixed it by using an avi container instead of a matroska container. No idea why it works now and not with matroska. I can honestly only think this has to be a bug somewhere.
Is it possible to play an embedded AAC file in Flash/Flex somehow? I know you can playback embedded MP3 files, but I hear that you can't do that with AAC. Anyone know any sneaky ways to get around this?
By way of illustration, here's come code.
[Embed(source='../../audio/music02.m4a', mimeType="audio/aac")]
private static const __ExampleMp4File:Class;
public var myMp4Sound:Sound = new __ExampleMp4File();
public function EmbeddedAudioTest()
{
myMp4Sound.play();
}
Unfortunately you can't. If you convert the audio file to video with just an audio track, then you can play it.
This does seem like a silly oversight in the player since it has support for playing embedded sound and support for AAC embedded in video.