java - xuggle-xuggler 5.4 NullPointerException when encoding audio -
today working xuggler library , tried capturing screen worked flawless. wanted add audio microphone video file captured. not easy had expected, , i'm stuck strange nullpointerexception.
this code (abbreviated):
audioformat format = new audioformat(8000.0f, 16, 1, true, false); writer.addaudiostream(1, 0, 1, (int) format.getsamplerate()); targetdataline line = gettargetdatalineforrecord(format); final int framesizeinbytes = format.getframesize(); final int bufferlengthinframes = line.getbuffersize() / 8; final int bufferlengthinbytes = bufferlengthinframes * framesizeinbytes; final byte[] buf = new byte[bufferlengthinbytes]; final long starttime = system.nanotime(); ... while (recording) { int numbytesread = 0; numbytesread = line.read(buf, 0, bufferlengthinbytes); int numsamplesread = numbytesread / 2; short[] audiosamples = new short[numsamplesread]; if (format.isbigendian()) { (int = 0; < numsamplesread; i++) { audiosamples[i] = (short) ((buf[2 * i] << 8) | buf[2 * + 1]); } } else { (int = 0; < numsamplesread; i++) { audiosamples[i] = (short) ((buf[2 * + 1] << 8) | buf[2 * i]); } } writer.encodeaudio(1, audiosamples, system.nanotime() - starttime, timeunit.nanoseconds); // capturescreen.java:118 } writer.close();
and here nullpointerexception:
java.lang.nullpointerexception @ com.xuggle.mediatool.mediawriter.encodeaudio(mediawriter.java:923) @ exe.media.capturescreen.capturescreen(capturescreen.java:118) @ exe.media.capturescreen.main(capturescreen.java:43)
the problem i'm having @ line (118):
writer.encodeaudio(1, audiosamples, system.nanotime() - starttime, timeunit.nanoseconds);
for reason when try encode audio samples, xuggle throws nullpointerexception, i'm not sure if bug or me doing stupid unable solve anyway.
for better understanding have posted code on pastebin , includes code capturing screen , code try record audio.
these jars have included:
commons-cli-1.2.jar
logback-classic-1.1.2.jar
logback-core-1.1.2.jar
xuggle-xuggler-arch-x86_x64-w64-mingw32.jar*
xuggle-xuggler-noarch-5.4.jar*
(the '*' means didn't download jar it's primary location.
thanks in advance and remember helpful answer rewarded 50 rep bounty!
i assume have line.open(format); , line.start(); somewhere?
you may need make sure have audiosamples: if (audiosamples.length > 0) writer.encodeaudio ...
also, may want add slf4j-api-1.6.4.jar , slf4j-simple-1.6.4.jar more details on errors xuggler.
Comments
Post a Comment