Commit 8f8858cf authored by Dr. Michael Petter's avatar Dr. Michael Petter

Replaced old JMF .wav cutting code with new Java API code

parent 0cb69f64
......@@ -63,6 +63,9 @@ import;
import javax.sound.sampled.AudioFileFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
* A sample program to cut an input file given the start and end points.
......@@ -203,12 +206,59 @@ public class Cut implements ControllerListener, DataSinkListener {
public boolean doIt(MediaLocator inML, MediaLocator outML, long start[], long end[], boolean frameMode){
if (!inML.getRemainder().endsWith(".wav")){
return false;
AudioInputStream inputStream = null;
AudioInputStream shortenedStream = null;
try {
// Open input
File file = new File(inML.getRemainder());
if (!file.exists()) {
System.err.println(" ... file does not exist: "+ inML.getRemainder());
return false;
AudioFileFormat fileFormat = AudioSystem.getAudioFileFormat(file);
javax.sound.sampled.AudioFormat format = fileFormat.getFormat();
inputStream = AudioSystem.getAudioInputStream(file);
System.err.println(" ... cut audio from "+start[0]+" ns to "+end[0]+"ns");
double startSecond=(start[0]/1000/1000)/1000.0;
double endSecond=(end[0]/1000/1000)/1000.0;
double secondsToCopy=endSecond-startSecond;
// compute parameters for performing the cut
int bytesPerSecond = format.getFrameSize() * (int)format.getFrameRate();
inputStream.skip((long)(startSecond * bytesPerSecond));
long framesOfAudioToCopy = (long)(secondsToCopy * (int)format.getFrameRate());
System.err.println(" ... cut audio from "+startSecond+" sec to "+endSecond+" sec");
// Finally write output
shortenedStream = new AudioInputStream(inputStream, format, framesOfAudioToCopy);
File destinationFile = new File(outML.getRemainder());
AudioSystem.write(shortenedStream, fileFormat.getType(), destinationFile);
} catch (Exception e) {
return false;
} finally {
if (inputStream != null) try { inputStream.close(); } catch (Exception e) { e.printStackTrace(); return false; }
if (shortenedStream != null) try { shortenedStream.close(); } catch (Exception e) { e.printStackTrace();return false; }
System.err.println(" ...done cutting.");
return true;
* Given a source media locator, destination media locator and a start and end point, this program cuts the pieces
* out.
public boolean doIt(MediaLocator inML, MediaLocator outML, long start[], long end[], boolean frameMode) {
public boolean doItOld(MediaLocator inML, MediaLocator outML, long start[], long end[], boolean frameMode) {
// Guess the output content descriptor from the file extension.
ContentDescriptor cd;
......@@ -1605,11 +1605,13 @@ public class PostProcessorPanel extends GradientPanel {
try {
if (mp4CheckBox.isSelected()) {
int x = Integer.parseInt(mp4WidthString.getText());
if (x==0) x=480;
if (x==0) x=recording.prefs.framebufferWidth;
TTT.userPrefs.putInt("VideoResolution", x);
int y = (int)(x * recording.prefs.framebufferHeight)/recording.prefs.framebufferWidth;
int cropx = 0, cropy=0;
int cropw=x, croph=y;
System.out.println(" creating MP4-Video with resolution "+x+"x"+y);
PodcastCreator.createPodcast(recording, x, y, batch,true);
PodcastCreator.createPodcast(recording, x, y, 1, batch,true,cropw,croph,cropx,cropy);
} catch (Exception e) {
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment