Encode H264 with JavaCV

526 views
Skip to first unread message

Ronnie Pottayya

unread,
May 4, 2016, 11:04:55 AM5/4/16
to javacv
Hi all,

I'm new to JavaCV and i was wondering whether JavaCV can encode and decode H264 frames?
I've downloaded the JavaCV 1.1 binaries from there : https://github.com/bytedeco/javacv and got all the jars needed to run the samples.

Thank you for your help.
Ronnie

Samuel Audet

unread,
May 7, 2016, 10:39:25 AM5/7/16
to jav...@googlegroups.com
Yes, sure of course it's possible. Something like this, for example:

FFmpegFrameGrabber grabber = new FFmpegFrameGrabber("in.mp4");
grabber.start();

FrameRecorder recorder = new FFmpegFrameRecorder("out.mp4",
grabber.getImageWidth(), grabber.getImageHeight());
recorder.setFrameRate(grabber.getSampleRate());
recorder.setVideoCodec(AV_CODEC_ID_H264)
recorder.start();

Frame frame;
while ((frame = grabber.grabImage()) != null) {
recorder.record(frame); // or do what you need with each image
}
recorder.stop();
grabber.stop();

Samuel

Ronnie Pottayya

unread,
May 10, 2016, 9:52:11 AM5/10/16
to javacv
Ohh thank you for your answer Samuel. But can you tell me how can i decode the "grabber.grabImage()" afterwards?
I've tried your solution and it is working like a charm. The video is recorded in H264 format!! Thank you for this!!


Thank you for your help.
Ronnie

Ronnie Pottayya

unread,
May 11, 2016, 11:49:22 AM5/11/16
to javacv
Hello,

So i've been able to record a video in h264 and speex formats.
But now what i'm trying to do is to get frames as they are encoded in h264, send them over the network, and decode them afterwards.
I've not been successful in getting some tutorials on that..

Can you please tell me whether it is achievable with JavaCV?
How can i do that?

Thank you for your help.
Ronnie

Samuel Audet

unread,
May 11, 2016, 9:15:15 PM5/11/16
to jav...@googlegroups.com
I'm unfortunately not very familiar with that myself. If you figure out
how to setup the servers and everything, please consider contributing a
tutorial that works! As a new page here for example:
https://github.com/bytedeco/javacv/wiki

Thanks!

Samuel

Samuel Audet

unread,
May 11, 2016, 9:16:18 PM5/11/16
to jav...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages