本文整理匯總了Java中io.humble.video.MediaPacket類的典型用法代碼示例。如果您正苦於以下問題:Java MediaPacket類的具體用法?Java MediaPacket怎麽用?Java MediaPacket使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
MediaPacket類屬於io.humble.video包,在下文中一共展示了MediaPacket類的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: open
import io.humble.video.MediaPacket; //導入依賴的package包/類
@Override
public void open(String path, int w, int h, int fps) throws Exception {
final Rational framerate = Rational.make(1, fps);
framenumber = 0;
packet = MediaPacket.make();
muxer = Muxer.make(path, null, null);
format = muxer.getFormat();
codec = Codec.findEncodingCodec(format.getDefaultVideoCodecId());
encoder = Encoder.make(codec);
encoder.setWidth(w);
encoder.setHeight(h);
final PixelFormat.Type pixelformat = PixelFormat.Type.PIX_FMT_YUV420P;
encoder.setPixelFormat(pixelformat);
encoder.setTimeBase(framerate);
if (format.getFlag(MuxerFormat.Flag.GLOBAL_HEADER))
encoder.setFlag(Encoder.Flag.FLAG_GLOBAL_HEADER, true);
encoder.open(null, null);
muxer.addNewStream(encoder);
muxer.open(null, null);
picture = MediaPicture.make(encoder.getWidth(), encoder.getHeight(), pixelformat);
picture.setTimeBase(framerate);
}
示例2: encodeAudio
import io.humble.video.MediaPacket; //導入依賴的package包/類
private void encodeAudio(MediaAudio samples, MediaPacket packet) {
log.tracef("encode audio called : %s", samples);
MediaPacket oPacket = MediaPacket.make(packet, true);
MediaAudio preEncode = samples;
log.tracef("entering while loop");
while (!oPacket.isComplete()) {
log.tracef("audio out coder is not null, is open? -> %s", mOutAudioCoder.getState());
mOutAudioCoder.encodeAudio(oPacket, preEncode);
//log.tracef("encode audio retval: %s", retval);
//if(retval <= 0){
// log.tracef("could not encode audio samples; continuing anyway");
// break;
//}
//log.tracef("no retval errorf");
// numSamplesConsumed += retval;
}
log.tracef("opacket is complete: %s", packet);
writePacket(oPacket);
log.tracef("opacket is written");
}
示例3: decodeVideo
import io.humble.video.MediaPacket; //導入依賴的package包/類
private void decodeVideo(MediaPacket packet) {
int retval = -1;
MediaPicture inPicture = MediaPicture.make(mInVideoCoder.getWidth(), mInVideoCoder.getHeight(), mInVideoCoder.getPixelFormat());
MediaPicture reSample = null;
int offset = 0;
while (offset < packet.getSize()) {
retval = mInVideoCoder.decodeVideo(inPicture, packet, offset);
if(retval <= 0){
log.tracef("noisy shit: decoding video failed for: %s", getSourceURI());
return;
}
offset += retval;
MediaPicture postDecode = inPicture;
if(postDecode.isComplete()){
reSample = resampleVideo(postDecode);
}
if(reSample!=null)
if(reSample.isComplete()){
encodeVideo(reSample, packet);
}
}
}
示例4: convertVideoToImages
import io.humble.video.MediaPacket; //導入依賴的package包/類
@Override
public void convertVideoToImages(File f, boolean singleImage, BlockingQueue<Image> sharedQueue, VideoLoadedLock videoLoadedLock) throws Exception {
cancel = false;
Demuxer demuxer = Demuxer.make();
demuxer.open(f.getAbsolutePath(), null, false, true, null, null);
long streamStartTime = Global.NO_PTS;
int videoStreamId = -1;
Decoder videoDecoder = null;
Rational streamTimeBase = Global.getDefaultTimeBase();
for (int i = 0; i < demuxer.getNumStreams(); i++) {
final DemuxerStream stream = demuxer.getStream(i);
streamStartTime = stream.getStartTime();
final Decoder decoder = stream.getDecoder();
if (decoder != null && decoder.getCodecType() == Type.MEDIA_VIDEO) {
videoStreamId = i;
videoDecoder = decoder;
streamTimeBase = stream.getTimeBase();
log.debug("Timebase {}", stream.getTimeBase());
// stop at the first one.
break;
}
}
videoDecoder.open(null, null);
final MediaPicture picture = MediaPicture.make(videoDecoder.getWidth(), videoDecoder.getHeight(), videoDecoder.getPixelFormat());
final MediaPictureConverter converter = MediaPictureConverterFactory.createConverter(MediaPictureConverterFactory.HUMBLE_BGR_24, picture);
final MediaPacket packet = MediaPacket.make();
videoLoadedLock.preloadFinished();
Long nextSnapShotTime = null;
long sampleRateNanos = Math.round(1000000000d/OptionsObject.getInstance().getVideoFramesPerSecond());
log.debug("Sampling every {}ns", sampleRateNanos);
final Rational systemTimeBase = Rational.make(1, 1000000000);
log.debug("Stream start time {}", streamStartTime);
try {
while (demuxer.read(packet) >= 0) {
// Now we have a packet, let's see if it belongs to our video stream
if (packet.getStreamIndex() == videoStreamId) {
/*
A packet can actually contain multiple sets of samples (or
frames of samples in decoding speak). So, we may need to call
decode multiple times at different offsets in the packet's
data. We capture that here.
*/
int offset = 0;
int bytesRead = 0;
do {
bytesRead += videoDecoder.decode(picture, packet, offset);
nextSnapShotTime = snapshotImageIfAtSampleTime(picture,systemTimeBase, streamStartTime, streamTimeBase, nextSnapShotTime, sharedQueue, converter, sampleRateNanos);
if (cancel || singleImage) {
return;
}
offset += bytesRead;
} while (offset < packet.getSize());
}
}
} finally {
do {
videoDecoder.decode(picture, null, 0);
snapshotImageIfAtSampleTime(picture,systemTimeBase, streamStartTime, streamTimeBase, nextSnapShotTime, sharedQueue, converter, sampleRateNanos);
} while (picture.isComplete());
demuxer.close();
cancel = false;
}
}
示例5: decodeAudio
import io.humble.video.MediaPacket; //導入依賴的package包/類
private void decodeAudio(MediaPacket packet) {
int retval = -1;
MediaAudio inSamples = MediaAudio.make(
mInAudioCoder.getFrameSize(),
mInAudioCoder.getSampleRate(),
mInAudioCoder.getChannels(),
mInAudioCoder.getChannelLayout(),
mInAudioCoder.getSampleFormat());
MediaAudio reSamples = null;
int offset = 0;
log.tracef("ready to decode audio");
while (offset < packet.getSize()) {
retval = mInAudioCoder.decodeAudio(inSamples, packet, offset);
if (retval <= 0) {
log.errorf("couldn't decode audio");
throw new RuntimeException("could not decode audio");
}
offset += retval;
log.tracef("audio loop offset: %s", offset);
MediaAudio postDecode = inSamples;
if (postDecode.isComplete()) {
log.tracef("postDecode was complete: %s", postDecode);
reSamples = resampleAudio(postDecode);
log.tracef("resample finished: %s", reSamples);
} else {
log.tracef("postDecode was NOT completed: %s", postDecode);
reSamples = postDecode;
}
if (reSamples.isComplete()) {
log.tracef("reSamples isComplete: %s", reSamples);
log.tracef("reSampler state: %s", mAudioResampler.getState());
encodeAudio(reSamples, packet);
}
}
log.tracef("finished decoding audio packet");
}
示例6: transcode
import io.humble.video.MediaPacket; //導入依賴的package包/類
private void transcode() throws InterruptedException, IOException {
MediaPacket packet = MediaPacket.make();
log.tracef("Packets and Audio buffers created");
log.tracef("FFThread declares ready: %s", pipePath);
// 02-12-13 -- We now signal JMS to say we are running
EncoderStatusMessage statusMessage = new EncoderStatusMessage();
statusMessage.setStatus(Status.STARTED_ENCODING);
statusMessage.setUri(sourceURI);
statusMessage.setHeight(mobileProfile.getHeight());
statusMessage.setWidth(mobileProfile.getWidth());
statusMessage.setBandwidth(mobileProfile.getBandwidth());
statusMessage.setName(mobileProfile.getName());
log.info("Dispatching FfThread started message");
getEncoderStatusDispatcher().dispatch(statusMessage);
log.info("Dispatched FfThread started message");
// end 02-12-13
log.tracef("About your in-coder: %s", source);
while (source.read(packet) >= 0) {
if(isInterruptMe())
throw new InterruptedException("Transcoding is interrupted");
log.tracef("reading packet");
if (packet.isComplete()) {
log.tracef("Packet is complete");
if (!codersSetup){
if(packet.isKeyPacket()) {
log.tracef("Packet is key packet");
openCoders(packet);
log.tracef("openInputCoders finished");
}
}
if (codersSetup) {
int i = packet.getStreamIndex();
if (i == mAudioStreamId) {
log.tracef("Packet is audio");
decodeAudio(packet);
} else if (i == mVideoStreamId) {
log.tracef("Packet is video");
decodeVideo(packet);
} else {
log.errorf("dropping packet from stream we haven't set-up: %s", i);
}
}
}
}
}
示例7: writePacket
import io.humble.video.MediaPacket; //導入依賴的package包/類
private void writePacket(MediaPacket oPacket) {
destination.write(oPacket, true);
}
示例8: encodeVideo
import io.humble.video.MediaPacket; //導入依賴的package包/類
private void encodeVideo(MediaPicture postDecode, MediaPacket packet) {
MediaPacket oPacket = MediaPacket.make(packet, true);
while(!oPacket.isComplete())
mOutVideoCoder.encodeVideo(oPacket, postDecode);
writePacket(oPacket);
}