lavc video: prefer libaom-av1 for ARM macs

While on x86_64 is libsvtav1 still slightly ahead, on the M1 mac, the
AOM AV1 performs significantly better (2x faster).

The above holds for native builds, it actually looks like the x86_64
build running SVT AV1 on M1 mac doesn't run correctly at all - it
produces just blank picture (green as is zeroed YCbCr buffer).
This commit is contained in:
Martin Pulec
2023-05-17 12:27:50 +02:00
parent 2961fe2f44
commit 5b750c2ff3
3 changed files with 30 additions and 2 deletions

View File

@@ -45,6 +45,7 @@
#include <unistd.h>
#include <cassert>
#include <cerrno>
#include <climits>
#include <cmath>
#include <cstring>
@@ -57,6 +58,11 @@
#include "utils/misc.h"
#include "utils/color_out.h"
#ifdef __APPLE__
#include <sys/types.h>
#include <sys/sysctl.h>
#endif
#define STRERROR_BUF_LEN 1024
using std::invalid_argument;
@@ -305,3 +311,24 @@ uint32_t parse_uint32(const char *value_str) noexcept(false)
return val;
}
/**
* Checks whether host machine is an ARM Mac (native or running x86_64 code with Rosetta2)
*/
bool is_arm_mac() {
#ifdef __APPLE__
char machine[256];
size_t len = sizeof machine;
if (sysctlbyname("hw.machine", &machine, &len, NULL, 0) != 0) {
perror("sysctlbyname hw.machine");
return false;
}
int proc_translated = -1; // Rosetta2 - 0 off, 1 on; sysctl ENOENT - x86_64 mac
len = sizeof proc_translated;
if (int ret = sysctlbyname("sysctl.proc_translated", &proc_translated, &len, NULL, 0); ret != 0 && errno != ENOENT) {
perror("sysctlbyname sysctl.proc_translated");
}
return strstr(machine, "arm") != NULL || proc_translated == 1;
#else
return false;
#endif
}

View File

@@ -4,7 +4,7 @@
* @author Martin Piatka <piatka@cesnet.cz>
*/
/*
* Copyright (c) 2014-2022 CESNET z.s.p.o.
* Copyright (c) 2014-2023 CESNET z.s.p.o.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -64,6 +64,7 @@ int get_framerate_d(double framerate);
const char *ug_strerror(int errnum);
void ug_perror(const char *s);
int get_cpu_core_count(void);
bool is_arm_mac(void);
struct key_val {
const char *key;

View File

@@ -212,7 +212,7 @@ static map<codec_t, codec_params_t> codec_params = {
502
}},
{ AV1, codec_params_t{
[](bool) { return "libsvtav1"; },
[](bool) { return is_arm_mac() ? "libaom-av1" : "libsvtav1"; },
0.1,
get_av1_preset,
setparam_h264_h265_av1,