Im currently using VLCJ (version 2.3.1) for a project that requires me to be able to jump both forwards and backwards frame by frame in a video file. Since VLC does not support going backwards in video, I am having to do this myself using the setTime() function from EmbeddedMediaPlayer. According to the JavaDoc for Media Player, setTime() jumps to a specific moment with the parameter passed. I have setup my program to calculate the time between frames so I can jump to a previous point in time. However, when I try and do this (for say 1 or two frames), the video actually jumps forward by 100+ ms. I can obviously jump forward without any problems with the nextFrame function for the Media Player. I have attached both the source code for my calculations as well as the output from the console. Any help will be greatly appreciated. Thanks!
Code: Select all
public void nextFrame()
{
System.out.println("\n **** nextFrame() ****");
System.out.println("Current Player Time (ms): " + mediaPlayer.getTime());
try
{
Thread.sleep(500);
mediaPlayer.nextFrame();
Thread.sleep(500);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
System.out.println("New Player Time (ms): " + mediaPlayer.getTime());
}
public void previousFrame()
{
long currentTime = mediaPlayer.getTime();
// Frame timing is calculated using 1000 / mediaPlayer.getFps() and done when the video loads.
// It is the same value as the last line in the video information block in the console text
long newTime = (long) (currentTime - frameTiming);
System.out.println("\n**** previousFrame() ****");
System.out.println("Current Player Time (ms): " + currentTime);
System.out.println("Time between frames (ms): " + frameTiming);
System.out.println("Time to jump to (ms): " + newTime);
jumpToTime(newTime);
}
public void jumpToTime(long time)
{
System.out.println("\n **** jumpToTime(long time) ****");
System.out.println("Jumping Video To Time (ms): " + time);
mediaPlayer.setTime(time);
try
{
Thread.sleep(1000);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
System.out.println("Media Player Time (after jump and 1 sec delay): " + mediaPlayer.getTime());
}
-------------------------------- VIDEO INFORMATION --------------------------------
- Video File: CIMG0269_rot.mov
- Video Length: 395127 ms
- Video Size: 320x432
- Video Frame Rate: 29.969627
- Video Time between frames: 33.367115
-----------------------------------------------------------------------------------
Time Change Detected 401
Time Change Detected 701
Time Change Detected 1001
Time Change Detected 1301
Time Change Detected 1601
Time Change Detected 1901
Media Player Time: 2029
**** nextFrame() ****
Current Player Time (ms): 2029
New Player Time (ms): 2069
**** nextFrame() ****
Current Player Time (ms): 2069
New Player Time (ms): 2103
**** previousFrame() ****
Current Player Time (ms): 2103
Time between frames (ms): 33.367115
Time to jump to (ms): 2069
**** jumpToTime(long time) ****
Jumping Video To Time (ms): 2069
Media Player Time (after jump and 1 sec delay): 2259
**** previousFrame() ****
Current Player Time (ms): 2259
Time between frames (ms): 33.367115
Time to jump to (ms): 2225
**** jumpToTime(long time) ****
Jumping Video To Time (ms): 2225
Media Player Time (after jump and 1 sec delay): 2415