Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xuggler, forwarding and rewinding video in xuggler 5.4 NOT WORKING

I used the xuggle-xuggler5.4 in my app to add video and audio playing functionality, I have dig into google and found following snippet:

long duration = container.getDuration();
long target = new Double(duration * .50).longValue();
container.seekKeyFrame(0, target, 0, 0, IContainer.SEEK_FLAG_BYTE);

I don't know if this snippet is not correct, or my xuggle is wrong, or I am SICK (just kidding) but every thing looks fine. when i play the video it always start from the first (not the location i want).

I would be very happy if someone can help me Thanks

like image 504
Mohammad Hassany Avatar asked Dec 29 '25 18:12

Mohammad Hassany


1 Answers

OK I got that ;)

I got the video duration and frame rate as below :

IStream stream = iContainerObj.getStream(i);
IStreamCoder coder = stream.getStreamCoder();

if (coder.getCodecType() == ICodec.Type.CODEC_TYPE_VIDEO
    && videoStreamId == -1) {
videoDuration = container.getDuration() == Global.NO_PTS ? 0
        : container.getDuration() / 1000;
frameRate = coder.getFrameRate().getDouble();
    // other ....
 }

then to jump to the specific location, I convert the duration which was in milli second to second then multiplied to frameRate and the second i want. And finally called seekKeyFrame to jump to position.

NOTE: also i used the =>> IContainer.SEEK_FLAG_FRAME, which indicate i am giving frame number to the method.

int jumpToThisSecond = 65;
long jumbTo = (long) (((videoDuration / 1000) * frameRate) * jumpToThisSecond);
container.seekKeyFrame(0, 0, jumbTo, container.getDuration(),
            IContainer.SEEK_FLAG_FRAME);
like image 186
Mohammad Hassany Avatar answered Jan 01 '26 06:01

Mohammad Hassany



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!