本文整理汇总了Java中com.xuggle.mediatool.IMediaWriter类的典型用法代码示例。如果您正苦于以下问题:Java IMediaWriter类的具体用法?Java IMediaWriter怎么用?Java IMediaWriter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IMediaWriter类属于com.xuggle.mediatool包,在下文中一共展示了IMediaWriter类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testTranscoding
import com.xuggle.mediatool.IMediaWriter; //导入依赖的package包/类
@Test
public void testTranscoding() {
IMediaReader mediaReader = ToolFactory.makeReader(filename);
IMediaWriter mediaWriter = ToolFactory.makeWriter(targetFilename,
mediaReader);
mediaReader.addListener(mediaWriter);
// create a media viewer with stats enabled
// IMediaViewer mediaViewer = ToolFactory.makeViewer(true);
//
// mediaReader.addListener(mediaViewer);
while (mediaReader.readPacket() == null)
;
}
示例2: testModifyMedia
import com.xuggle.mediatool.IMediaWriter; //导入依赖的package包/类
@Test
public void testModifyMedia() {
IMediaReader mediaReader = ToolFactory.makeReader(targetFilename);
// configure it to generate buffer images
mediaReader
.setBufferedImageTypeToGenerate(BufferedImage.TYPE_3BYTE_BGR);
IMediaWriter mediaWriter = ToolFactory.makeWriter(targetAvi,
mediaReader);
IMediaTool imageMediaTool = new StaticImageMediaTool(targetImage);
IMediaTool audioVolumeMediaTool = new VolumeAdjustMediaTool(0.3);
mediaReader.addListener(imageMediaTool);
imageMediaTool.addListener(audioVolumeMediaTool);
audioVolumeMediaTool.addListener(mediaWriter);
while (mediaReader.readPacket() == null)
;
}
示例3: testSplittingIntoTwo
import com.xuggle.mediatool.IMediaWriter; //导入依赖的package包/类
@Test
public void testSplittingIntoTwo() {
String source = "D:/worksap/HUE-kickoff/team-introduction/SRE.mp4";
String target1 = "D:/worksap/HUE-kickoff/team-introduction/SRE-1.mp4";
String target2 = "D:/worksap/HUE-kickoff/team-introduction/SRE-2.mp4";
IMediaReader reader = ToolFactory.makeReader(source);
CutChecker cutChecker = new CutChecker();
reader.addListener(cutChecker);
IMediaWriter writer = ToolFactory.makeWriter(target1, reader);
cutChecker.addListener(writer);
boolean updated = false;
while (reader.readPacket() == null) {
// 15 below is the point to split, in seconds
if ((cutChecker.currentTimestamp >= 15 * 1000000) && (!updated)) {
cutChecker.removeListener(writer);
writer.close();
writer = ToolFactory.makeWriter(target2, reader);
cutChecker.addListener(writer);
updated = true;
}
}
}
示例4: testSplittingOnlyOne
import com.xuggle.mediatool.IMediaWriter; //导入依赖的package包/类
@Test
public void testSplittingOnlyOne() {
String source = "D:/worksap/HUE-kickoff/team-introduction/SRE.mp4";
String target3 = "D:/worksap/HUE-kickoff/team-introduction/SRE-3.mp4";
IMediaReader reader = ToolFactory.makeReader(source);
CutChecker cutChecker = new CutChecker();
reader.addListener(cutChecker);
boolean updated = false;
while (reader.readPacket() == null) {
// 15 below is the point to split, in seconds
if ((cutChecker.currentTimestamp >= 15 * 1000000) && (!updated)) {
IMediaWriter writer = ToolFactory.makeWriter(target3, reader);
cutChecker.addListener(writer);
updated = true;
}
}
}
示例5: ShotRecorder
import com.xuggle.mediatool.IMediaWriter; //导入依赖的package包/类
public ShotRecorder(File relativeVideoFile, File videoFile, long cutDuration, IMediaWriter videoWriter,
String cameraName) {
this.relativeVideoFile = relativeVideoFile;
this.videoFile = videoFile;
this.videoWriter = videoWriter;
this.cameraName = cameraName;
startTime = System.currentTimeMillis();
timeOffset = cutDuration;
logger.debug("Started recording shot video: {}, cut duration = {} ms", videoFile.getName(), cutDuration);
}
示例6: createVideoFromScreens
import com.xuggle.mediatool.IMediaWriter; //导入依赖的package包/类
public void createVideoFromScreens() {
IMediaWriter writer = null;
try {
if (getOutputFile() == null) {
throw new IllegalStateException(
"Output video file cannot be null");
}
setStoppedCreation(false);
writer = ToolFactory.makeWriter(getOutputFile()
.getAbsolutePath());
writer.addVideoStream(0, 0, SCREEEN_BOUNDS.width,
SCREEEN_BOUNDS.height);
long startTime = System.nanoTime();
while (!getPleaseStop()) {
BufferedImage screen = getDesktopScreenshot();
BufferedImage bgrScreen = convertToType(screen, BufferedImage.TYPE_3BYTE_BGR);
writer.encodeVideo(0, bgrScreen, System.nanoTime() - startTime, TimeUnit.NANOSECONDS);
try {
Thread.currentThread().sleep(1000 / FRAME_RATE);
} catch (InterruptedException e) {
// Ignore
}
}
setStoppedCreation(true);
} finally {
if(writer!=null){
writer.flush();
writer.close();
}
}
}
示例7: createFlacXugglerBinary
import com.xuggle.mediatool.IMediaWriter; //导入依赖的package包/类
private Binary createFlacXugglerBinary() throws IOException {
Binary binary = env.getBinarySource().newBinary("" + this, "flac");
File file = env.getBinarySource().getBinaryFile(binary);
ICodec codec = ICodec.findEncodingCodec(ICodec.ID.CODEC_ID_FLAC);
String flacfilepath = file.getAbsolutePath();
IMediaWriter writer = ToolFactory.makeWriter(flacfilepath);
writer.addAudioStream(0, 0, ICodec.ID.CODEC_ID_FLAC, 1,
this.samplespersecond);
//
int index = 0;
while (index < getFS().length()) {
short ss[] = new short[1024];
//
int ssindex = 0;
while (ssindex < ss.length && index < getFS().length()) {
float f = getFS().getSample(index);
// short i = (short) ((f / 2 + 0.5f) * Short.MAX_VALUE);
short i = (short) (f * Short.MAX_VALUE);
ss[ssindex] = i;
index++;
ssindex++;
}
writer.encodeAudio(0, ss);
}
int extrasamples = 6000;
writer.encodeAudio(0, new short[extrasamples]);
writer.close();
//
File nf = new File(flacfilepath);
nf.renameTo(file);
return binary;
}
示例8: ForkContext
import com.xuggle.mediatool.IMediaWriter; //导入依赖的package包/类
public ForkContext(File relativeVideoFile, File videoFile, long lastTimestamp, IMediaWriter videoWriter) {
this.relativeVideoFile = relativeVideoFile;
this.videoFile = videoFile;
this.lastTimestamp = lastTimestamp;
this.videoWriter = videoWriter;
}
示例9: getVideoWriter
import com.xuggle.mediatool.IMediaWriter; //导入依赖的package包/类
public IMediaWriter getVideoWriter() {
return videoWriter;
}
示例10: getMediaWriter
import com.xuggle.mediatool.IMediaWriter; //导入依赖的package包/类
public IMediaWriter getMediaWriter() {
return writer;
}
示例11: main
import com.xuggle.mediatool.IMediaWriter; //导入依赖的package包/类
/**
* Create and display a number of bouncing balls on the
*/
public static void main(String[] args) {
args = new String[] {
"D:\\worksap\\HUE-kickoff\\team-introduction\\SRE.mp4",
"D:\\worksap\\HUE-kickoff\\team-introduction\\SRE-modified.mp4" };
if (args.length < 2) {
System.out
.println("Usage: ModifyAudioAndVideo <inputFileName> <outputFileName>");
System.exit(-1);
}
File inputFile = new File(args[0]);
if (!inputFile.exists()) {
System.out.println("Input file does not exist: " + inputFile);
System.exit(-1);
}
File outputFile = new File(args[1]);
// create a media reader and configure it to generate BufferImages
IMediaReader reader = ToolFactory.makeReader(inputFile.toString());
reader.setBufferedImageTypeToGenerate(BufferedImage.TYPE_3BYTE_BGR);
// create a writer and configure it's parameters from the reader
IMediaWriter writer = ToolFactory.makeWriter(outputFile.toString(),
reader);
// create a tool which paints video time stamp into frame
IMediaTool addTimeStamp = new TimeStampTool();
// create a tool which reduces audio volume to 1/10th original
IMediaTool reduceVolume = new VolumeAdjustTool(0.1);
// create a tool chain:
// reader -> addTimeStamp -> reduceVolume -> writer
reader.addListener(addTimeStamp);
addTimeStamp.addListener(reduceVolume);
reduceVolume.addListener(writer);
// add a viewer to the writer, to see media modified media
writer.addListener(ToolFactory.makeViewer());
// read and decode packets from the source file and
// then encode and write out data to the output file
while (reader.readPacket() == null)
do {
} while (false);
}
示例12: main
import com.xuggle.mediatool.IMediaWriter; //导入依赖的package包/类
/**
* Takes a screen shot of your entire screen and writes it to
* output.flv
*
* @param args
*/
public static void main(String[] args) {
try {
final String outFile;
if (args.length > 0)
outFile = args[0];
else
outFile = "output.mp4";
// This is the robot for taking a snapshot of the
// screen. It's part of Java AWT
final Robot robot = new Robot();
final Toolkit toolkit = Toolkit.getDefaultToolkit();
final Rectangle screenBounds = new Rectangle(
toolkit.getScreenSize());
// First, let's make a IMediaWriter to write the file.
final IMediaWriter writer = ToolFactory.makeWriter(outFile);
// We tell it we're going to add one video stream, with id 0,
// at position 0, and that it will have a fixed frame rate of
// FRAME_RATE.
writer.addVideoStream(0, 0, FRAME_RATE, screenBounds.width,
screenBounds.height);
// Now, we're going to loop
long startTime = System.nanoTime();
for (int index = 0; index < SECONDS_TO_RUN_FOR
* FRAME_RATE.getDouble(); index++) {
// take the screen shot
BufferedImage screen = robot.createScreenCapture(screenBounds);
// convert to the right image type
BufferedImage bgrScreen = convertToType(screen,
BufferedImage.TYPE_3BYTE_BGR);
// encode the image
writer.encodeVideo(0, bgrScreen, System.nanoTime() - startTime,
TimeUnit.NANOSECONDS);
System.out.println("encoded image: " + index);
// sleep for framerate milliseconds
Thread.sleep((long) (1000 / FRAME_RATE.getDouble()));
}
// Finally we tell the writer to close and write the trailer if
// needed
writer.close();
} catch (Throwable e) {
System.err.println("an error occurred: " + e.getMessage());
}
}
示例13: concatenate
import com.xuggle.mediatool.IMediaWriter; //导入依赖的package包/类
/**
* Concatenate two source files into one destination file.
*
* @param sourceUrl1 the file which will appear first in the output
* @param sourceUrl2 the file which will appear second in the output
* @param destinationUrl the file which will be produced
*/
public static void concatenate(String sourceUrl1, String sourceUrl2,
String destinationUrl) {
out.printf("transcode %s + %s -> %s\n", sourceUrl1, sourceUrl2,
destinationUrl);
//////////////////////////////////////////////////////////////////////
// //
// NOTE: be sure that the audio and video parameters match those of //
// your input media //
// //
//////////////////////////////////////////////////////////////////////
// video parameters
final int videoStreamIndex = 0;
final int videoStreamId = 0;
final int width = 1920;
final int height = 1080;
// audio parameters
final int audioStreamIndex = 1;
final int audioStreamId = 0;
final int channelCount = 2;
final int sampleRate = 48000; // Hz
// create the first media reader
IMediaReader reader1 = ToolFactory.makeReader(sourceUrl1);
// create the second media reader
IMediaReader reader2 = ToolFactory.makeReader(sourceUrl2);
// create the media concatenator
MediaConcatenator concatenator = new MediaConcatenator(
audioStreamIndex, videoStreamIndex);
// concatenator listens to both readers
reader1.addListener(concatenator);
reader2.addListener(concatenator);
// create the media writer which listens to the concatenator
IMediaWriter writer = ToolFactory.makeWriter(destinationUrl);
concatenator.addListener(writer);
// add the video stream
writer.addVideoStream(videoStreamIndex, videoStreamId, width, height);
// add the audio stream
writer.addAudioStream(audioStreamIndex, audioStreamId, channelCount,
sampleRate);
// read packets from the first source file until done
while (reader1.readPacket() == null)
;
// read packets from the second source file until done
while (reader2.readPacket() == null)
;
// close the writer
writer.close();
}