Fix video input on mac

visualiser-refactor
James H Ball 2025-04-30 20:26:40 +01:00
rodzic 59c5c97881
commit 9e93ffc260
2 zmienionych plików z 44 dodań i 23 usunięć

Wyświetl plik

@ -168,9 +168,18 @@ void ImageParser::processVideoFile(juce::File& file) {
} }
bool ImageParser::loadAllVideoFrames(const juce::File& file, const juce::File& ffmpegFile) { bool ImageParser::loadAllVideoFrames(const juce::File& file, const juce::File& ffmpegFile) {
juce::String cmd = "\"" + ffmpegFile.getFullPathName() + "\" -i \"" + file.getFullPathName() + "\" -hide_banner 2>&1"; // Use StringArray for arguments to handle quoting reliably
juce::StringArray metadataCommand;
ffmpegProcess.start(cmd); metadataCommand.add(ffmpegFile.getFullPathName());
metadataCommand.add("-i");
metadataCommand.add(file.getFullPathName());
metadataCommand.add("-hide_banner");
if (!ffmpegProcess.start(metadataCommand))
{
handleError("Failed to start ffmpeg process for metadata.");
return false;
}
juce::String output = ffmpegProcess.readAllProcessOutput(); juce::String output = ffmpegProcess.readAllProcessOutput();
if (output.isNotEmpty()) { if (output.isNotEmpty()) {
@ -220,30 +229,42 @@ bool ImageParser::loadAllVideoFrames(const juce::File& file, const juce::File& f
// Determine available hardware acceleration options // Determine available hardware acceleration options
#if JUCE_MAC #if JUCE_MAC
// Try to use videotoolbox on macOS // Try to use videotoolbox on macOS
juce::String hwAccel = " -hwaccel videotoolbox"; juce::String hwAccel = "videotoolbox";
#elif JUCE_WINDOWS #elif JUCE_WINDOWS
// Try to use DXVA2 on Windows // Try to use DXVA2 on Windows
juce::String hwAccel = " -hwaccel dxva2"; juce::String hwAccel = "dxva2";
#else #else
juce::String hwAccel = ""; juce::String hwAccel = "";
#endif #endif
// Start ffmpeg process to read frames with optimizations: // Start ffmpeg process to read frames using StringArray
// - Use hardware acceleration if available juce::StringArray frameReadCommand;
// - Lower resolution with scale filter frameReadCommand.add(ffmpegFile.getFullPathName());
// - Use multiple threads for faster processing if (hwAccel.isNotEmpty())
// - Use gray colorspace directly to avoid extra conversion {
cmd = "\"" + ffmpegFile.getFullPathName() + "\"" + frameReadCommand.add("-hwaccel");
hwAccel + frameReadCommand.add(hwAccel);
" -i \"" + file.getFullPathName() + "\"" + }
" -threads 8" + // Use 8 threads for processing frameReadCommand.add("-i");
" -vf \"scale=" + juce::String(width) + ":" + juce::String(height) + "\"" + // Scale to target size frameReadCommand.add(file.getFullPathName());
" -f rawvideo -pix_fmt gray" + // Output format frameReadCommand.add("-threads");
" -v error" + // Only show errors frameReadCommand.add("8");
" pipe:1"; // Output to stdout frameReadCommand.add("-vf");
frameReadCommand.add("scale=" + juce::String(width) + ":" + juce::String(height));
ffmpegProcess.start(cmd); frameReadCommand.add("-f");
frameReadCommand.add("rawvideo");
frameReadCommand.add("-pix_fmt");
frameReadCommand.add("gray");
frameReadCommand.add("-v");
frameReadCommand.add("error");
frameReadCommand.add("pipe:1");
if (!ffmpegProcess.start(frameReadCommand))
{
handleError("Failed to start ffmpeg process for frame reading.");
return false;
}
// Read all frames into memory // Read all frames into memory
int framesRead = 0; int framesRead = 0;

Wyświetl plik

@ -50,7 +50,7 @@ private:
int height = -1; int height = -1;
int count = 0; int count = 0;
juce::TemporaryFile temp; juce::TemporaryFile temp{".temp"};
#if OSCI_PREMIUM #if OSCI_PREMIUM
// Video processing fields // Video processing fields