java xuggler导致致命错误

时间:2016-01-15 17:43:54

标签: java netbeans windows-7-x64 xuggler

我试图使用xuggler来运行这个java代码:

import com.xuggle.mediatool.IMediaWriter;
import com.xuggle.mediatool.ToolFactory;
import com.xuggle.xuggler.IAudioSamples;
import com.xuggle.xuggler.ICodec;
import com.xuggle.xuggler.IContainer;
import com.xuggle.xuggler.IPacket;
import com.xuggle.xuggler.IStream;
import com.xuggle.xuggler.IStreamCoder;
import com.xuggle.xuggler.IVideoPicture;

/**
* This class is used to merge audio and video file.
*
* @author Arslaan Ejaz
*/
public class DecodeAndSaveAudioVideo {

public static void main(String[] args) {

    String filenamevideo = "C:/testvideo/vid.mp4"; //this is the input file for video. you can change extension
    String filenameaudio = "C:/testvideo/my_vid.mp3"; //this is the input file for audio. you can change extension

    IMediaWriter mWriter = ToolFactory.makeWriter("C:/testvideo/xout.flv"); //output file

    IContainer containerVideo = IContainer.make();
    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();

    System.out.println("Number of video streams: " + numStreamVideo + "\n" + "Number of audio streams: " + numStreamAudio);

    int videostreamt = -1; //this is the video stream id
    int audiostreamt = -1;

    IStreamCoder videocoder = null;

    for (int i = 0; i < numStreamVideo; i++) {
        IStream stream = containerVideo.getStream(i);
        IStreamCoder code = stream.getStreamCoder();

        if (code.getCodecType() == ICodec.Type.CODEC_TYPE_VIDEO) {
            videostreamt = i;
            videocoder = code;
            break;
        }

    }

    for (int i = 0; i < numStreamAudio; i++) {
        IStream stream = containerAudio.getStream(i);
        IStreamCoder code = stream.getStreamCoder();

        if (code.getCodecType() == ICodec.Type.CODEC_TYPE_AUDIO) {
            audiostreamt = i;
            break;
        }

    }

    if (videostreamt == -1) {
        throw new RuntimeException("No video steam found");
    }
    if (audiostreamt == -1) {
        throw new RuntimeException("No audio steam found");
    }

    if (videocoder.open() < 0) {
        throw new RuntimeException("Cant open video coder");
    }
    IPacket packetvideo = IPacket.make();

    IStreamCoder audioCoder = containerAudio.getStream(audiostreamt).getStreamCoder();

    if (audioCoder.open() < 0) {
        throw new RuntimeException("Cant open audio coder");
    }
    mWriter.addAudioStream(1, 1, audioCoder.getChannels(), audioCoder.getSampleRate());

    mWriter.addVideoStream(0, 0, videocoder.getWidth(), videocoder.getHeight());

    IPacket packetaudio = IPacket.make();

    while (containerVideo.readNextPacket(packetvideo) >= 0
            || containerAudio.readNextPacket(packetaudio) >= 0) {

        if (packetvideo.getStreamIndex() == videostreamt) {

            //video packet
            IVideoPicture picture = IVideoPicture.make(videocoder.getPixelType(),
                    videocoder.getWidth(),
                    videocoder.getHeight());
            int offset = 0;
            while (offset < packetvideo.getSize()) {
                int bytesDecoded = videocoder.decodeVideo(picture,
                        packetvideo,
                        offset);
                if (bytesDecoded < 0) {
                    throw new RuntimeException("bytesDecoded not working");
                }
                offset += bytesDecoded;

                if (picture.isComplete()) {
                    System.out.println(picture.getPixelType());
                    mWriter.encodeVideo(0, picture);

                }
            }
        }

        if (packetaudio.getStreamIndex() == audiostreamt) {
            //audio packet

            IAudioSamples samples = IAudioSamples.make(512,
                    audioCoder.getChannels(),
                    IAudioSamples.Format.FMT_S32);
            int offset = 0;
            while (offset < packetaudio.getSize()) {
                int bytesDecodedaudio = audioCoder.decodeAudio(samples,
                        packetaudio,
                        offset);
                if (bytesDecodedaudio < 0) {
                    throw new RuntimeException("could not detect audio");
                }
                offset += bytesDecodedaudio;

                if (samples.isComplete()) {
                    mWriter.encodeAudio(1, samples);

                }
            }

        }

    }
}

}

但我得到了这个致命的错误:

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x000000005a676520,     pid=4548, tid=5300
#
# JRE version: Java(TM) SE Runtime Environment (8.0_65-b17) (build    1.8.0_65-b17)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.65-b01 mixed mode    windows-amd64 compressed oops)
# Problematic frame:
# C  [xuggle4769618689748853529.dll+0x736520]
#
# Failed to write core dump. Minidumps are not enabled by default on   client versions of Windows
#
# An error report file with more information is saved as:
# C:\Users\User\Documents\NetBeansProjects\audiofile \hs_err_pid4548.log
#
# If you would like to submit a bug report, please visit:
#   http://bugreport.java.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#
C:\Users\User\AppData\Local\NetBeans\Cache\8.1\executor-snippets   \run.xml:53: Java returned: 1
BUILD FAILED (total time: 2 seconds)

我正在使用Win7 64bit。 经过一些研究,我发现你只需要使用32位版本的java.But然后netbeans无法启动。我可以使用更优雅的方式吗?

更新:我安装了java 8 32位并重新安装netbeans。错误仍然存​​在。

0 个答案:

没有答案