屏幕捕获带有Java音频的视频

时间:2018-11-11 07:38:01

标签: java audio video screenshot audio-recording

我正在尝试使用Java以编程方式截屏浏览器的视频以及音频。我目前正在使用带有以下代码的monte媒体包,但是我使用的每种音频配置都会破坏视频(实际上并没有添加音频)。以下是相关代码:

GraphicsConfiguration gc = GraphicsEnvironment
            .getLocalGraphicsEnvironment()
            .getDefaultScreenDevice()
            .getDefaultConfiguration();

    screenRecorder = new ScreenRecorder(gc,
            new Format(MediaTypeKey, MediaType.FILE, MimeTypeKey, MIME_AVI),
            new Format(MediaTypeKey, MediaType.VIDEO, EncodingKey, ENCODING_AVI_TECHSMITH_SCREEN_CAPTURE,
                    CompressorNameKey, ENCODING_AVI_TECHSMITH_SCREEN_CAPTURE,
                    DepthKey, 24, FrameRateKey, Rational.valueOf(15),
                    QualityKey, 1.0f,
                    KeyFrameIntervalKey, 10000 * 60),
            new Format(MediaTypeKey, MediaType.VIDEO, EncodingKey, "black",
                    FrameRateKey, Rational.valueOf(30)),

    /* //THIS AUDIO FORMAT DOESN'T WORK, BUT I PUT IT HERE 
       //AS AN EXAMPLE OF WHERE I'VE BEEN TRYING TO 
               //CONFIGURE THE AUDIO
            new Format(MediaTypeKey, MediaType.AUDIO,
                    EncodingKey, ENCODING_PCM_SIGNED,
                    FrameRateKey, new Rational(48000, 1),
                    SampleSizeInBitsKey, 16,
                    ChannelsKey, 2, SampleRateKey, new Rational(48000, 1),
                    SignedKey, true, ByteOrderKey, ByteOrder.BIG_ENDIAN)
    */
    null
    );
    screenRecorder.start();

我尝试使用以下代码创建QuickPlay格式的视频,但这也行不通。实际上,不仅不显示视频,而且录制的音频来自计算机的麦克风,而不是屏幕。这是代码:

new Format(MediaTypeKey, MediaType.FILE,
        MimeTypeKey, MIME_QUICKTIME),
        //
        // the output format for screen capture
        new Format(MediaTypeKey, MediaType.VIDEO,
        EncodingKey, ENCODING_QUICKTIME_ANIMATION,
        CompressorNameKey, COMPRESSOR_NAME_QUICKTIME_ANIMATION,
        DepthKey, 24, FrameRateKey, new Rational(15, 1)),
        //
        // the output format for mouse capture 
        new Format(MediaTypeKey, MediaType.VIDEO,
        EncodingKey, ENCODING_BLACK_CURSOR,
        FrameRateKey, new Rational(30, 1)),
        //
        // the output format for audio capture 
        new Format(MediaTypeKey, MediaType.AUDIO,
        EncodingKey, ENCODING_QUICKTIME_TWOS_PCM,
        FrameRateKey, new Rational(48000, 1),
        SampleSizeInBitsKey, 16,
        ChannelsKey, 2, SampleRateKey, new Rational(48000, 1),
        SignedKey, true, ByteOrderKey, ByteOrder.BIG_ENDIAN));

这里提供了任何帮助,包括告诉我该库已过时并且可以使用其他库(但请实际上告诉我替代方法是什么)。

谢谢!

0 个答案:

没有答案
相关问题