0

To remotely play a media file I have used UDP datagram. I'm sending packet of 40 kb to clients, but to synchronize all the clients I need to find duration of each packet so that if a packet is lost I can pause player at client side using SocketTimeOutExcpetion. To calculate duration of each packet I have used following equation

        duration of packet= (duration of whole file)/SizeOfPacket

where,

        duration of file = (length of file)/bitrate *8

Currently I'm calculating Bitrate using mediainfo package in ubuntu.

How can I get Bitrate of a Audio or Video File using VLCJ API ?

Lain
  • 2,166
  • 4
  • 23
  • 47
bhushan23
  • 481
  • 1
  • 4
  • 13

1 Answers1

1

First you need to parse or play the media, playing the media is less preferable of course but depending on the media it may be necessary - assuming parse works for your media:

mediaPlayer.parseMedia();

The parse method is synchronous.

If parse does not work, then unfortunately you will need to play the media before the information becomes available.

Depending on the media codec used, the track info may be available immediately or asynchronously some time later - so you may need to listen for media player events or even sleep for a while (nasty, but sometimes it's necessary).

Next you get the track information:

List<TrackInfo> audioTrackInfo = mediaPlayer.getTrackInfo(TrackType.AUDIO);
List<TrackInfo> videoTrackInfo = mediaPlayer.getTrackInfo(TrackType.VIDEO);

You can then iterate the returned list.

for (TrackInfo trackInfo : audioTrackInfo) {
    int bitRate = trackInfo.bitRate();
    // ...
}

for (TrackInfo trackInfo : videoTrackInfo) {
    int bitRate = trackInfo.bitRate();
    // ...
}

An added complication is that mediaPlayer.parse() will almost certainly not work and may even hang if you are playing network streams.

caprica
  • 3,902
  • 4
  • 19
  • 39
  • Hello. I'M trying to get fps and bitrate of the played stream. I tried mediaPlayer.getTrackInfo(TrackType.VIDEO); but it returns null. Also mediaPlayer.getRate() and mediaPlayer.getFps() returns 1.0 and 0.0. Is there something i'm missing ? – Null Pointer Jan 05 '18 at 14:18
  • (Is it not possible to use them with rtsp streams?) – Null Pointer Jan 05 '18 at 14:55