IContainer containerAudio = IContainer.make(); if (containerVideo.open(filenamevideo, IContainer.Type.READ, null) < 0) throw new IllegalArgumentException("Cant find " + filenamevideo); if (containerAudio.open(filenameaudio, IContainer.Type.READ, null) < 0) throw new IllegalArgumentException("Cant find " + filenameaudio); int numStreamVideo = containerVideo.getNumStreams(); int numStreamAudio = containerAudio.getNumStreams(); IStream stream = containerVideo.getStream(i); IStreamCoder code = stream.getStreamCoder(); IStream stream = containerAudio.getStream(i); IStreamCoder code = stream.getStreamCoder(); IPacket packetvideo = IPacket.make(); IStreamCoder audioCoder = containerAudio.getStream(audiostreamt).getStreamCoder(); while(containerVideo.readNextPacket(packetvideo) >= 0 || containerAudio.readNextPacket(packetaudio) >= 0){
IContainerFormat containerFormat_live = IContainerFormat.make(); containerFormat_live.setOutputFormat("flv", url + fileName, null); container.setInputBufferLength(0); int retVal = container.open(url + fileName, IContainer.Type.WRITE, containerFormat_live); if (retVal < 0) { System.err.println("Could not open output container for live stream"); System.exit(1); IStream stream = container.addNewStream(0); IStreamCoder coder = stream.getStreamCoder(); ICodec codec = ICodec.findEncodingCodec(ICodec.ID.CODEC_ID_H264); container.writeHeader(); long firstTimeStamp = System.currentTimeMillis(); long lastTimeStamp = -1; outFrame.delete(); if (packet.isComplete()) { container.writePacket(packet); System.out.println("[ENCODER] writing packet of size " + packet.getSize() + " for elapsed time " + ((timeStamp - lastTimeStamp) / 1000)); lastTimeStamp = timeStamp; e.printStackTrace(); container.writeTrailer();
if (container.open(filename, IContainer.Type.READ, null) < 0) throw new IllegalArgumentException("could not open file: " + filename); String seconds=container.getDuration()/(1000000*2)+""; // time of thumbnail int numStreams = container.getNumStreams(); for (int i = 0; i < numStreams; i++) { IStream stream = container.getStream(i); IRational timeBase = container.getStream(videoStreamId).getTimeBase(); long target = container.getStartTime() + timeStampOffset; container.seekKeyFrame(videoStreamId, target, 0); while(container.readNextPacket(packet) >= 0 && !isFinished ) { container.close(); container = null;
container = IContainer.make(); openResult = container.open(stream, null, true, true); openResult = container.open(uri.toString(), IContainer.Type.READ, null, true, true); "Trying to open a stream to the URL instead."); final InputStream is = uri.toURL().openStream(); openResult = container.open(is, null, true, true); while (i < container.getNumStreams()) s = container.getStream(i); if (s != null && s.getStreamCoder().getCodecType() == ICodec.Type.CODEC_TYPE_AUDIO) if (container.getDuration() == Global.NO_PTS) this.length = -1; else getStream(this.streamIndex).getStreamCoder();
/** * Create the necessary reader */ synchronized private void create(InputStream stream) { setupReader(); // Check whether the string we have is a valid URI final IContainer container = IContainer.make(); final int openResult = container.open(stream, null, true, true); if (openResult < 0) { logger.error("Error opening container. Error " + openResult + " (" + IError.errorNumberToType(openResult).toString() + ")"); return; } setupReader(container); }
while (i < container.getNumStreams()) { s = container.getStream(i); if (s != null && s.getStreamCoder().getCodecType() == ICodec.Type.CODEC_TYPE_VIDEO) { if (container.getDuration() == Global.NO_PTS) this.totalFrames = -1; else
final double timebase = this.reader.getContainer().getStream( this.streamIndex).getTimeBase().getDouble(); final long position = (long) (timestamp / timebase); final long max = position; final int ret = this.reader.getContainer().seekKeyFrame(this.streamIndex, min, position, max, IContainer.SEEK_FLAG_ANY);
if (container.open("/path/to/video.avi", IContainer.Type.READ, null) < 0) throw new IllegalArgumentException("could not open file: " + filename); int numStreams = container.getNumStreams(); for (int i = 0; i < numStreams; i++) { IStream stream = container.getStream(i);
double timeBase = 0; int videoStreamId = -1; private void seekToMs(IContainer container, long timeMs) { if(videoStreamId == -1) { for(int i = 0; i < container.getNumStreams(); i++) { IStream stream = container.getStream(i); IStreamCoder coder = stream.getStreamCoder(); if (coder.getCodecType() == ICodec.Type.CODEC_TYPE_VIDEO) { videoStreamId = i; timeBase = stream.getTimeBase().getDouble(); break; } } } long seekTo = (long) (timeMs/1000.0/timeBase); container.seekKeyFrame(videoStreamId, seekTo, IContainer.SEEK_FLAG_BACKWARDS); }
IContainer container = IContainer.make(); if (container.open(movie, IContainer.Type.READ, null) < 0) { throw new RuntimeException("Cannot open '" + movie + "'"); } logger.info("# Duration (ms): " + ((container.getDuration() == Global.NO_PTS) ? "unknown" : "" + container.getDuration() / 100)); logger.info("# File size (bytes): " + container.getFileSize()); logger.info("# Bit rate: " + container.getBitRate());
protected boolean setupVideo() { if (videoListener != null) { return true; } IContainer container = IContainer.make(); IContainerFormat format = IContainerFormat.make(); int ret = format.setInputFormat("vfwcap"); if (ret < 0) { container.close(); format.delete(); log.error(String.format("USB Cam: cannot open WebCam ('vfwcap' device)")); return false; } ret = container.open("0", IContainer.Type.READ, format); if (ret < 0) { container.close(); format.delete(); log.error(String.format("USB Cam: cannot open WebCam ('0')")); return false; } IMediaReader reader = ToolFactory.makeReader(container); videoListener = new VideoListener(reader, getResolutionWidth(resolution), getResolutionHeight(resolution)); reader.addListener(videoListener); return true; }
countainer1.open("audio.mp3", IContainer.Type.READ, null); IStreamCoder audio1 = countainer1.getStream(0).getStreamCoder(); audio1.open(null, null); countainer2.open("audio2.mp3", IContainer.Type.READ, null); IStreamCoder audio2 = countainer2.getStream(0).getStreamCoder(); audio2.open(null, null); while (countainer1.readNextPacket(packet) >= 0) { IAudioSamples samples = IAudioSamples.make(512, audio1.getChannels(), IAudioSamples.Format.FMT_S32); audio1.decodeAudio(samples, packet, 0); while (countainer2.readNextPacket(packet) >= 0) { IAudioSamples samples = IAudioSamples.make(512, audio2.getChannels(), IAudioSamples.Format.FMT_S32); audio2.decodeAudio(samples, packet, 0);
private static final String filename = "c:/myvideo.mp4"; IContainer container = IContainer.make(); int result = container.open(filename, IContainer.Type.READ, null); long duration = container.getDuration(); long fileSize = container.getFileSize();
IContainer iContainer = IContainer.make(); if (iContainer.open(inputStream, IContainer.Type.READ, format) >= 0) { IMediaReader mediaReader = ToolFactory.makeReader(iContainer); ... }
public VideoListener(IMediaReader reader, int width, int height) { this.reader = reader; IContainer container = reader.getContainer(); int numStreams = container.getNumStreams(); for (int i = 0; i < numStreams; i++) { IStream stream = container.getStream(i); IStreamCoder coder = stream.getStreamCoder(); if (coder.getCodecType() == ICodec.Type.CODEC_TYPE_VIDEO) { videoStream = i; videoCoder = coder; } } if (videoCoder != null) { videoConverter = ConverterFactory.createConverter(ConverterFactory.XUGGLER_BGR_24, videoCoder.getPixelType(), videoCoder.getWidth(), videoCoder.getHeight()); videoPicture = IVideoPicture.make(videoCoder.getPixelType(), width, height); videoResampler = IVideoResampler.make(width, height, videoCoder.getPixelType(), videoCoder.getWidth(), videoCoder.getHeight(), videoCoder.getPixelType()); } videoReaderThread = new VideoReaderThread(reader); videoReaderThread.setName("Video Reader Thread"); videoReaderThread.setDaemon(true); videoReaderThread.start(); }
/** * Returns the duration of the video in seconds. * * @return The duration of the video in seconds. */ public synchronized long getDuration() { final long duration = (this.reader.getContainer().getStream(this.streamIndex).getDuration()); final double timebase = this.reader.getContainer().getStream(this.streamIndex).getTimeBase().getDouble(); return Math.round(duration * timebase); }
IMediaReader reader = ToolFactory.makeReader(filename); IContainer container = reader.getContainer(); if (container.queryStreamMetaData() >= 0) { long duration = container.getDuration(); // <-- got it }
this.reader.getContainer().seekKeyFrame(this.streamIndex, 0, 0, 0, IContainer.SEEK_FLAG_BYTE); this.reader.getContainer().seekKeyFrame(this.streamIndex, 0, 0, 0, IContainer.SEEK_FLAG_FRAME); this.reader.getContainer().seekKeyFrame(this.streamIndex, 0, 0, 0, IContainer.SEEK_FLAG_BACKWARDS); this.reader.getContainer().seekKeyFrame(this.streamIndex, 0, 0, 0, IContainer.SEEK_FLAG_ANY);
if (container.open(filename, IContainer.Type.READ, null) < 0) throw new IllegalArgumentException("could not open file: " + filename); int numStreams = container.getNumStreams(); for (int i = 0; i < numStreams; i++) { IStream stream = container.getStream(i); IRational timeBase = container.getStream(videoStreamId).getTimeBase(); long target = container.getStartTime() + timeStampOffset; container.seekKeyFrame(videoStreamId, target, 0); while(container.readNextPacket(packet) >= 0 && !isFinished ) { container.close(); container = null;
container = IContainer.make(); openResult = container.open(stream, null, true, true); openResult = container.open(uri.toString(), IContainer.Type.READ, null, true, true); "Trying to open a stream to the URL instead."); final InputStream is = uri.toURL().openStream(); openResult = container.open(is, null, true, true); while (i < container.getNumStreams()) s = container.getStream(i); if (s != null && s.getStreamCoder().getCodecType() == ICodec.Type.CODEC_TYPE_AUDIO) if (container.getDuration() == Global.NO_PTS) this.length = -1; else getStream(this.streamIndex).getStreamCoder();