diff --git a/jpro-media/src/main/java/one/jpro/platform/media/recorder/NativeMediaRecorder.java b/jpro-media/src/main/java/one/jpro/platform/media/recorder/NativeMediaRecorder.java index 935cd782..3090540b 100644 --- a/jpro-media/src/main/java/one/jpro/platform/media/recorder/NativeMediaRecorder.java +++ b/jpro-media/src/main/java/one/jpro/platform/media/recorder/NativeMediaRecorder.java @@ -96,7 +96,7 @@ public NativeMediaRecorder() { // Initialize audio frame grabber micGrabber = new FFmpegFrameGrabber(getDefaultAudioInputDevice()); - micGrabber.setFormat("avfoundation"); + micGrabber.setFormat(getDefaultAudioInputFormat()); micGrabber.setAudioChannels(DEFAULT_AUDIO_CHANNELS); micGrabber.setSampleRate(DEFAULT_AUDIO_SAMPLE_RATE); @@ -592,4 +592,41 @@ public static String getDefaultAudioInputDevice() { return audioDevice; } + /** + * Gets the default audio input format based on the operating system. + *

+ * This method determines the appropriate audio input format for use with {@link FFmpegFrameGrabber}, + * based on the operating system where the application is running: + *

+ * + * + * @return the format string for audio input format + */ + public static String getDefaultAudioInputFormat() { + String OS = System.getProperty("os.name").toLowerCase(); + String format; + + if (OS.contains("win")) { + // Windows - DirectShow + format = "dshow"; + } else if (OS.contains("mac")) { + // macOS - AVFoundation + format = "avfoundation"; + } else if (OS.contains("nix") || OS.contains("nux") || OS.contains("aix")) { + // Linux - ALSA + format = "alsa"; + } else { + // Unknown OS - fallback + format = "default"; + } + + return format; + } + }