org.jcodec.codecs.h264.H264Encoder Java Examples
The following examples show how to use
org.jcodec.codecs.h264.H264Encoder.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SequenceEncoderMp4.java From ImageToVideo with Apache License 2.0 | 6 votes |
public SequenceEncoderMp4(File out) throws IOException { super(out); this.ch = NIOUtils.writableFileChannel(out); // Muxer that will store the encoded frames muxer = new MP4Muxer(ch, Brand.MP4); // Add video track to muxer outTrack = muxer.addTrack(TrackType.VIDEO, timeScale); // Allocate a buffer big enough to hold output frames _out = ByteBuffer.allocate(1920 * 1080 * 6); // Create an instance of encoder encoder = new H264Encoder(); // Transform to convert between RGB and YUV transform = ColorUtil.getTransform(ColorSpace.RGB, encoder.getSupportedColorSpaces()[0]); // Encoder extra data ( SPS, PPS ) to be stored in a special place of // MP4 spsList = new ArrayList<ByteBuffer>(); ppsList = new ArrayList<ByteBuffer>(); }
Example #2
Source File: ImageToH264MP4Encoder.java From CameraV with GNU General Public License v3.0 | 6 votes |
public ImageToH264MP4Encoder(SeekableByteChannel ch, AudioFormat af) throws IOException { this.ch = ch; this.af = af; // Muxer that will store the encoded frames muxer = new MP4Muxer(ch, Brand.MP4); // Add video track to muxer outTrack = muxer.addTrack(TrackType.VIDEO, 25); // Create an instance of encoder encoder = new H264Encoder(); // Transform to convert between RGB and YUV transform = ColorUtil.getTransform(ColorSpace.RGB, encoder.getSupportedColorSpaces()[0]); // Encoder extra data ( SPS, PPS ) to be stored in a special place of // MP4 spsList = new ArrayList<ByteBuffer>(); ppsList = new ArrayList<ByteBuffer>(); if (af != null) audioTrack = muxer.addPCMAudioTrack(af); }
Example #3
Source File: H264FrameEncoder.java From amazon-kinesis-video-streams-parser-library with Apache License 2.0 | 5 votes |
public H264FrameEncoder(final int width, final int height, final int bitRate) { this.encoder = new H264Encoder(new H264FixedRateControl(bitRate)); this.out = ByteBuffer.allocate(width * height * 6); this.frameNumber = 0; final Size size = new Size(width, height); sps = this.encoder.initSPS(size); pps = this.encoder.initPPS(); final ByteBuffer spsBuffer = ByteBuffer.allocate(512); this.sps.write(spsBuffer); spsBuffer.flip(); final ByteBuffer serialSps = ByteBuffer.allocate(512); this.sps.write(serialSps); serialSps.flip(); H264Utils.escapeNALinplace(serialSps); final ByteBuffer serialPps = ByteBuffer.allocate(512); this.pps.write(serialPps); serialPps.flip(); H264Utils.escapeNALinplace(serialPps); final ByteBuffer serialAvcc = ByteBuffer.allocate(512); final AvcCBox avcC = AvcCBox.createAvcCBox(this.sps.profileIdc, 0, this.sps.levelIdc, 4, asList(serialSps), asList(serialPps)); avcC.doWrite(serialAvcc); serialAvcc.flip(); cpd = new byte[serialAvcc.remaining()]; serialAvcc.get(cpd); }