Imported Upstream version 0.13.2+dsfg1

This commit is contained in:
Sebastian Ramacher 2016-02-24 00:16:51 +01:00
commit fb3990e9e5
2036 changed files with 287360 additions and 0 deletions

View file

@ -0,0 +1,17 @@
project(obs-x264)
find_package(Libx264 REQUIRED)
include_directories(${LIBX264_INCLUDE_DIRS})
add_definitions(${LIBX264_DEFINITIONS})
set(obs-x264_SOURCES
obs-x264.c
obs-x264-plugin-main.c)
add_library(obs-x264 MODULE
${obs-x264_SOURCES})
target_link_libraries(obs-x264
libobs
${LIBX264_LIBRARIES})
install_obs_plugin_with_data(obs-x264 data)

View file

@ -0,0 +1,6 @@
Bitrate="معدل النقل"
BufferSize="حجم المخزن المؤقت"
KeyframeIntervalSec="الفاصل الزمني لـKeyframe (ثانية, 0=تلقائي)"
Profile="الملف الشخصي"
Tune="لحن"

View file

@ -0,0 +1,5 @@
Bitrate="Битрейт"
BufferSize="Размер на буфера"
KeyframeIntervalSec="Keyframe интервал (секунди, 0 = автоматично)"
Profile="Профил"

View file

@ -0,0 +1,13 @@
Bitrate="Taxa de bits"
CustomBufsize="Utilitza una mida de memòria intermèdia personalitzada"
BufferSize="Mida de la memòria intermèdia"
UseCBR="Usa CBR"
CRF="CRF"
KeyframeIntervalSec="Interval de fotograma clau (en segons, 0 = automàtic)"
CPUPreset="Preconfiguració d'ús de la CPU (més alt = menys CPU)"
Profile="Perfil"
Tune="Ajustament"
None="(Cap)"
EncoderOptions="Opcions x264 (separades amb espais)"
VFR="Velocitat de fotogrames variable (VFR)"

View file

@ -0,0 +1,13 @@
Bitrate="Bitrate"
CustomBufsize="Použít vlastní velikost vyrovnávací paměti"
BufferSize="Velikost vyrovnávací paměti"
UseCBR="Použít CBR"
CRF="CRF"
KeyframeIntervalSec="Interval klíčových snímků (vteřiny, 0=auto)"
CPUPreset="Předvolba využití CPU (vyšší = méně CPU)"
Profile="Profil"
Tune="Ladění"
None="(Žádné)"
EncoderOptions="Možnosti x264 (odděleny mezerou)"
VFR="Měnící se snímkování (VFR)"

View file

@ -0,0 +1,11 @@
Bitrate="Bitrate"
CustomBufsize="Brug brugerdefineret bufferstørrelse"
BufferSize="Bufferstørrelsen"
UseCBR="Brug CBR"
CRF="CRF"
KeyframeIntervalSec="Keyframe Interval (sekunder, 0 = auto)"
Profile="Profil"
Tune="Stil ind"
None="(Ingen)"
EncoderOptions="x264 indstillinger (adskilt af mellemrum)"

View file

@ -0,0 +1,13 @@
Bitrate="Bitrate"
CustomBufsize="Verwende benutzerdefinierte Puffergröße"
BufferSize="Puffergröße"
UseCBR="Benutze CBR"
CRF="CRF"
KeyframeIntervalSec="Keyframeintervall (Sekunden, 0=auto)"
CPUPreset="Prozessorauslastung-Voreinstellung (höher = weniger CPU Auslastung)"
Profile="Profil"
Tune="Tune"
None="(Nichts)"
EncoderOptions="x264 Optionen (durch Leerzeichen getrennt)"
VFR="Variable Framerate (VFR)"

View file

@ -0,0 +1,12 @@
Bitrate="Ρυθμός μετάδοσης bit"
CustomBufsize="Χρήση Προσαρμοσμένου Μεγέθους Buffer"
BufferSize="Μέγεθος buffer"
UseCBR="Χρήση CBR"
CRF="CRF"
KeyframeIntervalSec="Συχνότητα Καρέ-Κλειδιού (δευτερόλεπτα, 0=αυτόματο)"
CPUPreset="Προφίλ Χρήσης CPU (υψηλότερο = λιγότερη CPU)"
Profile="Προφίλ"
Tune="Βελτιστοποίηση"
None="(Κανένα)"
EncoderOptions="Επιλογές x264 (διαχωρισμένες από κενό)"

View file

@ -0,0 +1,12 @@
Bitrate="Bitrate"
CustomBufsize="Use Custom Buffer Size"
BufferSize="Buffer Size"
UseCBR="Use CBR"
CRF="CRF"
KeyframeIntervalSec="Keyframe Interval (seconds, 0=auto)"
CPUPreset="CPU Usage Preset (higher = less CPU)"
Profile="Profile"
Tune="Tune"
None="(None)"
EncoderOptions="x264 Options (separated by space)"
VFR="Variable Framerate (VFR)"

View file

@ -0,0 +1,13 @@
Bitrate="Tasa de bits"
CustomBufsize="Usar tamaño de caché personalizado"
BufferSize="Tamaño de la memoria intermedia"
UseCBR="Usar CBR"
CRF="CRF"
KeyframeIntervalSec="Intervalo de fotogramas clave (segundos, 0 = auto)"
CPUPreset="Perfíl de uso de CPU (superior = menos CPU)"
Profile="Perfil"
Tune="Sintonizar"
None="(Ninguno)"
EncoderOptions="Opciones x264 (separadas por espacio)"
VFR="Framerate Variable (VFR)"

View file

@ -0,0 +1,13 @@
Bitrate="Bitneurria"
CustomBufsize="Erabili Norbere Buffer Neurria"
BufferSize="Buffer Neurria"
UseCBR="Erabili BNG"
CRF="CRF"
KeyframeIntervalSec="Giltzaframe Tartea (segundu, 0=berez)"
CPUPreset="CPU Erabilpen Aurrezarpena (handiagoa = CPU gutxiago)"
Profile="Profila"
Tune="Sintonizatu"
None="(Bat ere ez)"
EncoderOptions="x264 Aukerak (tarte batez bananduta)"
VFR="Frameneurri Aldakorra (VFR)"

View file

@ -0,0 +1,13 @@
Bitrate="Bitrate"
CustomBufsize="Käytä valinnaista puskurin kokoa"
BufferSize="Puskurin koko"
UseCBR="Käytä CBR"
CRF="CRF"
KeyframeIntervalSec="Keyframe-väli (sec, 0=auto)"
CPUPreset="CPU:n käyttö (korkeampi vaatii enemmän tehoa)"
Profile="Profiili"
Tune="Hienosäätö"
None="(Ei mitään)"
EncoderOptions="x264-asetukset (erotetaan välilyönnillä)"
VFR="Muuttuva Framerate (VFR)"

View file

@ -0,0 +1,13 @@
Bitrate="Débit"
CustomBufsize="Utiliser une taille de buffer personnalisée"
BufferSize="Taille du Tampon"
UseCBR="Utiliser CBR"
CRF="CRF"
KeyframeIntervalSec="Intervalle d'image-clé (en secondes, 0 = auto)"
CPUPreset="Réglages prédéfinis du CPU (élevé = charge CPU faible)"
Profile="Profil"
Tune="Régler"
None="(Aucun)"
EncoderOptions="Options x264 (séparées par un espace)"
VFR="Fréquence d'images variable (VFR)"

View file

@ -0,0 +1,12 @@
Bitrate="Velocidade de bits"
CustomBufsize="Utilizar tamaño da caché personalizado"
BufferSize="Tamaño do búfer"
UseCBR="Utilizar CBR"
CRF="CRF"
KeyframeIntervalSec="Intervalo de fotogramas chave (segundos, 0 = auto)"
CPUPreset="Uso predefinido da CPU (superior = menos CPU)"
Profile="Perfil"
Tune="Sintonizar"
None="(Ningún)"
EncoderOptions="Opcións x264 (separadas por un espazo)"

View file

@ -0,0 +1,13 @@
Bitrate="Protok"
CustomBufsize="Koristi specifičnu veličinu bafera"
BufferSize="Veličina buffer-a"
UseCBR="Koristi CBR"
CRF="CRF"
KeyframeIntervalSec="Keyframe interval (sekunde, 0=automatski)"
CPUPreset="Koristi CPU šablon (veće = manje CPU-a)"
Profile="Profil"
Tune="Doterivanje"
None="(Nijedno)"
EncoderOptions="x264 opcije (odvojene razmakom)"
VFR="Promenjivi framerate (VFR)"

View file

@ -0,0 +1,13 @@
Bitrate="Bitráta"
CustomBufsize="Egyéni pufferméret használata"
BufferSize="Bufferméret"
UseCBR="CBR Használata"
CRF="CRF"
KeyframeIntervalSec="Kulcsképkocka Időköze (másodperc, 0=auto)"
CPUPreset="CPU Készlet (magasabb = kevesebb CPU igény)"
Profile="Profil"
Tune="Hangolás"
None="(Nincs)"
EncoderOptions="x264 Opciók (szóközzel elválasztva)"
VFR="Változó Képkockasebesség (VFR)"

View file

@ -0,0 +1,13 @@
Bitrate="Bitrate"
CustomBufsize="Usa dimensione personalizzata del buffer"
BufferSize="Grandezza buffer"
UseCBR="Usa CBR"
CRF="CRF"
KeyframeIntervalSec="Intervallo keyframe (secondi, 0=auto)"
CPUPreset="Preset di utilizzo della CPU (superiore = meno CPU)"
Profile="Profilo"
Tune="Regola"
None="(nessuno)"
EncoderOptions="Opzioni x264 (separati da spazio)"
VFR="Framerate variabile (VFR)"

View file

@ -0,0 +1,13 @@
Bitrate="ビットレート"
CustomBufsize="特定バッファサイズを使用"
BufferSize="バッファサイズ"
UseCBR="CBRを使用する"
CRF="CRF"
KeyframeIntervalSec="キーフレーム間隔 (秒, 0=自動)"
CPUPreset="CPU使用のプリセット (高い = CPU使用低い)"
Profile="プロファイル"
Tune="チューン"
None="(なし)"
EncoderOptions="x264 オプション (スペースで区切る)"
VFR="可変フレームレート(VFR)"

View file

@ -0,0 +1,13 @@
Bitrate="비트레이트"
CustomBufsize="사용자 임의 버퍼 크기 설정"
BufferSize="버퍼 크기"
UseCBR="CBR 사용"
CRF="CRF"
KeyframeIntervalSec="키프레임 간격 (초 단위, 0=자동)"
CPUPreset="CPU 사용량 사전설정 (높음 = 적은 CPU 부담)"
Profile="프로필"
Tune="조정"
None="(없음)"
EncoderOptions="x264 설정 (공백으로 구분)"
VFR="가변 프레임 (VFR)"

View file

@ -0,0 +1,13 @@
Bitrate="Bitrate"
CustomBufsize="Bruk egendefinert bufferstørrelse"
BufferSize="Buffer størrelse"
UseCBR="Bruk CBR"
CRF="CRF"
KeyframeIntervalSec="Nøkkelbildeintervall (sekunder, 0 = automatisk)"
CPUPreset="Forhåndsinstilling for prosessorbruk (raskere betyr mindre belastning)"
Profile="Profil"
Tune="Still inn"
None="(Ingen)"
EncoderOptions="x264 alternativer (separert med mellomrom)"
VFR="Variabel bildefrekvens (VFR)"

View file

@ -0,0 +1,13 @@
Bitrate="Bitrate"
CustomBufsize="Aangepaste buffergrootte gebruiken"
BufferSize="Buffergrootte"
UseCBR="CBR Gebruiken"
CRF="CRF"
KeyframeIntervalSec="Tijd tussen keyframes (seconden, 0=auto)"
CPUPreset="CPU-gebruik instelling (hoger = minder CPU)"
Profile="Profiel"
Tune="Afstemmen"
None="(Geen)"
EncoderOptions="x264 Opties (gescheiden door spaties)"
VFR="Variabele Framerate (VFR)"

View file

@ -0,0 +1,13 @@
Bitrate="Przepływność bitowa"
CustomBufsize="Użyj własnego rozmiaru bufora"
BufferSize="Rozmiar bufora"
UseCBR="Użyj CBR (stały bitrate)"
CRF="CRF"
KeyframeIntervalSec="Interwał klatek kluczowych (sekundy, 0 - auto)"
CPUPreset="Ustawienie obciążenia CPU (wyższe = mniej CPU)"
Profile="Profil"
Tune="Dostrajanie"
None="(Brak)"
EncoderOptions="Opcje x264 (rozdzielone spacją)"
VFR="Zmienna liczba klatek na sekundę (VFR)"

View file

@ -0,0 +1,13 @@
Bitrate="Taxa de Bits"
CustomBufsize="Utilizar tamanho do buffer personalizado"
BufferSize="Tamanho do Buffer"
UseCBR="Utilizar CBR"
CRF="CRF"
KeyframeIntervalSec="Intervalo de Keyframe (segundos, 0 = auto)"
CPUPreset="Predefinição de utilização do processador (maior = menos processamento)"
Profile="Perfil"
Tune="Ajustar"
None="(Nenhum)"
EncoderOptions="Opções do x264 (separado por espaço)"
VFR="Taxa de fotogramas variável (VFR)"

View file

@ -0,0 +1,13 @@
Bitrate="Taxa de Bits (Bitrate)"
CustomBufsize="Utilizar tamanho do buffer personalizado"
BufferSize="Tamanho do Buffer"
UseCBR="Utilizar CBR"
CRF="CRF"
KeyframeIntervalSec="Intervalo de Keyframe (segundos, 0 = auto)"
CPUPreset="Predefinição de utilização do processador (maior = menos processamento)"
Profile="Perfil"
Tune="Sintonizar"
None="(Nenhum)"
EncoderOptions="Opções do x264 (separado por espaço)"
VFR="Taxa de fotogramas variável (VFR)"

View file

@ -0,0 +1,13 @@
Bitrate="Rata biti"
CustomBufsize="Utilizați o Mărime de Buffer Personalizată"
BufferSize="Dimensiune tampon"
UseCBR="Folosește CBR"
CRF="CRF"
KeyframeIntervalSec="Intervalul de cadre (secunde, 0 = auto)"
CPUPreset="Preset utilizare CPU (mai mare = mai puţin CPU)"
Profile="Profil"
Tune="Reglaj"
None="(Nici unul)"
EncoderOptions="Opţiuni x264 (separate prin spațiu)"
VFR="Framerate Variabil (VFR)"

View file

@ -0,0 +1,13 @@
Bitrate="Битрейт"
CustomBufsize="Использовать пользовательский размер буфера"
BufferSize="Размер буфера"
UseCBR="Использовать CBR"
CRF="CRF"
KeyframeIntervalSec="Интервал ключевых кадров (сек, 0=авто)"
CPUPreset="Предустановка использования ЦП (выше = меньше)"
Profile="Профиль"
Tune="Настроить"
None="(Нет)"
EncoderOptions="Настройки x264 (разделённые пробелом)"
VFR="Переменная частота кадров (VFR)"

View file

@ -0,0 +1,10 @@
Bitrate="Bitrate"
CustomBufsize="Použiť vlastnú veľkosť medzipamäte"
BufferSize="Veľkosť medzipamäte"
UseCBR="Použiť CRB"
CRF="CRF"
KeyframeIntervalSec="Kľúčová snímka každých (sekúnd, 0 = automaticky)"
Profile="Profil"
Tune="Vyladenie"
None="(Žiadny)"

View file

@ -0,0 +1,6 @@
Bitrate="Bitrate"
BufferSize="Velikost medpolnilnika"
KeyframeIntervalSec="Okvirni Interval(sekunde, 0=avtomatsko)"
Profile="Profil"
Tune="Tune"

View file

@ -0,0 +1,13 @@
Bitrate="Protok"
CustomBufsize="Koristi specifičnu veličinu bafera"
BufferSize="Veličina buffer-a"
UseCBR="Koristi CBR"
CRF="CRF"
KeyframeIntervalSec="Keyframe interval (sekunde, 0=automatski)"
CPUPreset="Koristi CPU šablon (veće = manje CPU-a)"
Profile="Profil"
Tune="Doterivanje"
None="(Nijedno)"
EncoderOptions="x264 opcije (odvojene razmakom)"
VFR="Promenjivi framerate (VFR)"

View file

@ -0,0 +1,13 @@
Bitrate="Проток"
CustomBufsize="Користи специфичну величину бафера"
BufferSize="Величина buffer-а"
UseCBR="Користи CBR"
CRF="CRF"
KeyframeIntervalSec="Keyframe интервал (секунде, 0=аутоматски)"
CPUPreset="Користи CPU шаблон (веће = мање CPU-а)"
Profile="Профил"
Tune="Дотеривање"
None="(Ниједно)"
EncoderOptions="x264 опције (одвојене размаком)"
VFR="Промењиви framerate (VFR)"

View file

@ -0,0 +1,12 @@
Bitrate="Bithastighet"
CustomBufsize="Använd anpassad buffertstorlek"
BufferSize="Buffertstorlek"
UseCBR="Använd CBR"
CRF="CRF"
KeyframeIntervalSec="Keyframe-tidsintervall (i sek, 0=auto)"
CPUPreset="CPU-användning förinställning (högre = mindre CPU)"
Profile="Profil"
Tune="Tune"
None="(Inga)"
EncoderOptions="x264 inställningar (separerade med blanksteg)"

View file

@ -0,0 +1,4 @@
Bitrate="บิตเรท"
BufferSize="ขนาดของบัฟเฟอร์"
Profile="โปรไฟล์"

View file

@ -0,0 +1,13 @@
Bitrate="Bit hızı"
CustomBufsize="İsteğe Bağlı Arabellek Boyutu Kullan"
BufferSize="Arabellek Boyutu"
UseCBR="CBR kullan"
CRF="CRF"
KeyframeIntervalSec="Anahtarkare Aralığı (saniye, 0=otomatik)"
CPUPreset="CPU Kullanım Önayarı (yüksek = az CPU kullanımı)"
Profile="Profil"
Tune="Ayarla"
None="(Yok)"
EncoderOptions="x264 Ayarları (boşlukla ayrılmış)"
VFR="Değişken Kare Hızı (VFR)"

View file

@ -0,0 +1,4 @@
Bitrate="Бітрейт"
KeyframeIntervalSec="Інтервал ключових кадрів (секунд, 0 = авто)"
Profile="Профіль"

View file

@ -0,0 +1,13 @@
Bitrate="比特率"
CustomBufsize="使用自定义缓存大小"
BufferSize="缓冲大小"
UseCBR="使用 CBR"
CRF="CRF"
KeyframeIntervalSec="关键帧间隔(秒, 0=自动)"
CPUPreset="CPU 使用预设 (更高 = 较少的 CPU占用)"
Profile="档案"
Tune="曲调"
None="(无)"
EncoderOptions="x264 选项 (用空格分隔)"
VFR="可变帧率 (VFR)"

View file

@ -0,0 +1,13 @@
Bitrate="位元率"
CustomBufsize="使用自訂的緩衝區大小"
BufferSize="緩衝區大小"
UseCBR="使用 CBR (固定流量)"
CRF="CRF"
KeyframeIntervalSec="關鍵影格間隔 (秒0 = 自動)"
CPUPreset="CPU 使用率設定 (越快 越少CPU使用率)"
Profile="演算法"
Tune="最佳化"
None="(空)"
EncoderOptions="x264 選項 (用空格分開)"
VFR="變動式流量 (VFR)"

View file

@ -0,0 +1,12 @@
#include <obs-module.h>
OBS_DECLARE_MODULE()
OBS_MODULE_USE_DEFAULT_LOCALE("obs-x264", "en-US")
extern struct obs_encoder_info obs_x264_encoder;
bool obs_module_load(void)
{
obs_register_encoder(&obs_x264_encoder);
return true;
}

703
plugins/obs-x264/obs-x264.c Normal file
View file

@ -0,0 +1,703 @@
/******************************************************************************
Copyright (C) 2014 by Hugh Bailey <obs.jim@gmail.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/
#include <stdio.h>
#include <util/dstr.h>
#include <util/darray.h>
#include <util/platform.h>
#include <obs-module.h>
#ifndef _STDINT_H_INCLUDED
#define _STDINT_H_INCLUDED
#endif
#include <x264.h>
#define do_log(level, format, ...) \
blog(level, "[x264 encoder: '%s'] " format, \
obs_encoder_get_name(obsx264->encoder), ##__VA_ARGS__)
#define warn(format, ...) do_log(LOG_WARNING, format, ##__VA_ARGS__)
#define info(format, ...) do_log(LOG_INFO, format, ##__VA_ARGS__)
#define debug(format, ...) do_log(LOG_DEBUG, format, ##__VA_ARGS__)
/* ------------------------------------------------------------------------- */
struct obs_x264 {
obs_encoder_t *encoder;
x264_param_t params;
x264_t *context;
DARRAY(uint8_t) packet_data;
uint8_t *extra_data;
uint8_t *sei;
size_t extra_data_size;
size_t sei_size;
os_performance_token_t *performance_token;
};
/* ------------------------------------------------------------------------- */
static const char *obs_x264_getname(void *unused)
{
UNUSED_PARAMETER(unused);
return "x264";
}
static void obs_x264_stop(void *data);
static void clear_data(struct obs_x264 *obsx264)
{
if (obsx264->context) {
x264_encoder_close(obsx264->context);
bfree(obsx264->sei);
bfree(obsx264->extra_data);
obsx264->context = NULL;
obsx264->sei = NULL;
obsx264->extra_data = NULL;
}
}
static void obs_x264_destroy(void *data)
{
struct obs_x264 *obsx264 = data;
if (obsx264) {
os_end_high_performance(obsx264->performance_token);
clear_data(obsx264);
da_free(obsx264->packet_data);
bfree(obsx264);
}
}
static void obs_x264_defaults(obs_data_t *settings)
{
obs_data_set_default_int (settings, "bitrate", 2500);
obs_data_set_default_bool (settings, "use_bufsize", false);
obs_data_set_default_int (settings, "buffer_size", 2500);
obs_data_set_default_int (settings, "keyint_sec", 0);
obs_data_set_default_int (settings, "crf", 23);
obs_data_set_default_bool (settings, "vfr", false);
obs_data_set_default_bool (settings, "cbr", true);
obs_data_set_default_string(settings, "preset", "veryfast");
obs_data_set_default_string(settings, "profile", "");
obs_data_set_default_string(settings, "tune", "");
obs_data_set_default_string(settings, "x264opts", "");
}
static inline void add_strings(obs_property_t *list, const char *const *strings)
{
while (*strings) {
obs_property_list_add_string(list, *strings, *strings);
strings++;
}
}
#define TEXT_BITRATE obs_module_text("Bitrate")
#define TEXT_CUSTOM_BUF obs_module_text("CustomBufsize")
#define TEXT_BUF_SIZE obs_module_text("BufferSize")
#define TEXT_USE_CBR obs_module_text("UseCBR")
#define TEXT_VFR obs_module_text("VFR")
#define TEXT_CRF obs_module_text("CRF")
#define TEXT_KEYINT_SEC obs_module_text("KeyframeIntervalSec")
#define TEXT_PRESET obs_module_text("CPUPreset")
#define TEXT_PROFILE obs_module_text("Profile")
#define TEXT_TUNE obs_module_text("Tune")
#define TEXT_NONE obs_module_text("None")
#define TEXT_X264_OPTS obs_module_text("EncoderOptions")
static bool use_bufsize_modified(obs_properties_t *ppts, obs_property_t *p,
obs_data_t *settings)
{
bool use_bufsize = obs_data_get_bool(settings, "use_bufsize");
p = obs_properties_get(ppts, "buffer_size");
obs_property_set_visible(p, use_bufsize);
return true;
}
static bool use_cbr_modified(obs_properties_t *ppts, obs_property_t *p,
obs_data_t *settings)
{
bool cbr = obs_data_get_bool(settings, "cbr");
p = obs_properties_get(ppts, "crf");
obs_property_set_visible(p, !cbr);
return true;
}
static obs_properties_t *obs_x264_props(void *unused)
{
UNUSED_PARAMETER(unused);
obs_properties_t *props = obs_properties_create();
obs_property_t *list;
obs_property_t *p;
obs_properties_add_int(props, "bitrate", TEXT_BITRATE, 50, 10000000, 1);
p = obs_properties_add_bool(props, "use_bufsize", TEXT_CUSTOM_BUF);
obs_property_set_modified_callback(p, use_bufsize_modified);
obs_properties_add_int(props, "buffer_size", TEXT_BUF_SIZE, 0,
10000000, 1);
obs_properties_add_int(props, "keyint_sec", TEXT_KEYINT_SEC, 0, 20, 1);
p = obs_properties_add_bool(props, "cbr", TEXT_USE_CBR);
obs_properties_add_int(props, "crf", TEXT_CRF, 0, 51, 1);
obs_property_set_modified_callback(p, use_cbr_modified);
list = obs_properties_add_list(props, "preset", TEXT_PRESET,
OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_STRING);
add_strings(list, x264_preset_names);
list = obs_properties_add_list(props, "profile", TEXT_PROFILE,
OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_STRING);
obs_property_list_add_string(list, TEXT_NONE, "");
obs_property_list_add_string(list, "baseline", "baseline");
obs_property_list_add_string(list, "main", "main");
obs_property_list_add_string(list, "high", "high");
list = obs_properties_add_list(props, "tune", TEXT_TUNE,
OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_STRING);
obs_property_list_add_string(list, TEXT_NONE, "");
add_strings(list, x264_tune_names);
obs_properties_add_bool(props, "vfr", TEXT_VFR);
obs_properties_add_text(props, "x264opts", TEXT_X264_OPTS,
OBS_TEXT_DEFAULT);
return props;
}
static bool getparam(const char *param, char **name, const char **value)
{
const char *assign;
if (!param || !*param || (*param == '='))
return false;
assign = strchr(param, '=');
if (!assign || !*assign || !*(assign+1))
return false;
*name = bstrdup_n(param, assign-param);
*value = assign+1;
return true;
}
static const char *validate(struct obs_x264 *obsx264,
const char *val, const char *name,
const char *const *list)
{
if (!val || !*val)
return val;
while (*list) {
if (strcmp(val, *list) == 0)
return val;
list++;
}
warn("Invalid %s: %s", name, val);
return NULL;
}
static void override_base_param(struct obs_x264 *obsx264, const char *param,
char **preset, char **profile, char **tune)
{
char *name;
const char *val;
if (getparam(param, &name, &val)) {
if (astrcmpi(name, "preset") == 0) {
const char *valid_name = validate(obsx264, val,
"preset", x264_preset_names);
if (valid_name) {
bfree(*preset);
*preset = bstrdup(val);
}
} else if (astrcmpi(name, "profile") == 0) {
const char *valid_name = validate(obsx264, val,
"profile", x264_profile_names);
if (valid_name) {
bfree(*profile);
*profile = bstrdup(val);
}
} else if (astrcmpi(name, "tune") == 0) {
const char *valid_name = validate(obsx264, val,
"tune", x264_tune_names);
if (valid_name) {
bfree(*tune);
*tune = bstrdup(val);
}
}
bfree(name);
}
}
static inline void override_base_params(struct obs_x264 *obsx264, char **params,
char **preset, char **profile, char **tune)
{
while (*params)
override_base_param(obsx264, *(params++),
preset, profile, tune);
}
static inline void set_param(struct obs_x264 *obsx264, const char *param)
{
char *name;
const char *val;
if (getparam(param, &name, &val)) {
if (strcmp(name, "preset") != 0 &&
strcmp(name, "profile") != 0 &&
strcmp(name, "tune") != 0 &&
strcmp(name, "fps") != 0 &&
strcmp(name, "force-cfr") != 0 &&
strcmp(name, "width") != 0 &&
strcmp(name, "height") != 0) {
if (x264_param_parse(&obsx264->params, name, val) != 0)
warn("x264 param: %s failed", param);
}
bfree(name);
}
}
static inline void apply_x264_profile(struct obs_x264 *obsx264,
const char *profile)
{
if (!obsx264->context && profile && *profile) {
int ret = x264_param_apply_profile(&obsx264->params, profile);
if (ret != 0)
warn("Failed to set x264 profile '%s'", profile);
}
}
static inline const char *validate_preset(struct obs_x264 *obsx264,
const char *preset)
{
const char *new_preset = validate(obsx264, preset, "preset",
x264_preset_names);
return new_preset ? new_preset : "veryfast";
}
static bool reset_x264_params(struct obs_x264 *obsx264,
const char *preset, const char *tune)
{
int ret = x264_param_default_preset(&obsx264->params,
validate_preset(obsx264, preset),
validate(obsx264, tune, "tune", x264_tune_names));
return ret == 0;
}
static void log_x264(void *param, int level, const char *format, va_list args)
{
struct obs_x264 *obsx264 = param;
char str[1024];
vsnprintf(str, 1024, format, args);
info("%s", str);
UNUSED_PARAMETER(level);
}
static inline const char *get_x264_colorspace_name(enum video_colorspace cs)
{
switch (cs) {
case VIDEO_CS_DEFAULT:
case VIDEO_CS_601:
return "undef";
case VIDEO_CS_709:;
}
return "bt709";
}
static inline int get_x264_cs_val(enum video_colorspace cs,
const char *const names[])
{
const char *name = get_x264_colorspace_name(cs);
int idx = 0;
do {
if (strcmp(names[idx], name) == 0)
return idx;
} while (!!names[++idx]);
return 0;
}
static void obs_x264_video_info(void *data, struct video_scale_info *info);
static void update_params(struct obs_x264 *obsx264, obs_data_t *settings,
char **params)
{
video_t *video = obs_encoder_video(obsx264->encoder);
const struct video_output_info *voi = video_output_get_info(video);
struct video_scale_info info;
info.format = voi->format;
info.colorspace = voi->colorspace;
info.range = voi->range;
obs_x264_video_info(obsx264, &info);
int bitrate = (int)obs_data_get_int(settings, "bitrate");
int buffer_size = (int)obs_data_get_int(settings, "buffer_size");
int keyint_sec = (int)obs_data_get_int(settings, "keyint_sec");
int crf = (int)obs_data_get_int(settings, "crf");
int width = (int)obs_encoder_get_width(obsx264->encoder);
int height = (int)obs_encoder_get_height(obsx264->encoder);
bool use_bufsize = obs_data_get_bool(settings, "use_bufsize");
bool vfr = obs_data_get_bool(settings, "vfr");
bool cbr = obs_data_get_bool(settings, "cbr");
if (keyint_sec)
obsx264->params.i_keyint_max =
keyint_sec * voi->fps_num / voi->fps_den;
if (!use_bufsize)
buffer_size = bitrate;
obsx264->params.b_vfr_input = vfr;
obsx264->params.rc.i_vbv_max_bitrate = bitrate;
obsx264->params.rc.i_vbv_buffer_size = buffer_size;
obsx264->params.rc.i_bitrate = bitrate;
obsx264->params.i_width = width;
obsx264->params.i_height = height;
obsx264->params.i_fps_num = voi->fps_num;
obsx264->params.i_fps_den = voi->fps_den;
obsx264->params.pf_log = log_x264;
obsx264->params.p_log_private = obsx264;
obsx264->params.i_log_level = X264_LOG_WARNING;
obsx264->params.vui.i_transfer =
get_x264_cs_val(info.colorspace, x264_transfer_names);
obsx264->params.vui.i_colmatrix =
get_x264_cs_val(info.colorspace, x264_colmatrix_names);
obsx264->params.vui.i_colorprim =
get_x264_cs_val(info.colorspace, x264_colorprim_names);
obsx264->params.vui.b_fullrange =
info.range == VIDEO_RANGE_FULL;
/* use the new filler method for CBR to allow real-time adjusting of
* the bitrate */
if (cbr) {
obsx264->params.rc.f_rf_constant = 0.0f;
obsx264->params.rc.i_rc_method = X264_RC_ABR;
#if X264_BUILD >= 139
obsx264->params.rc.b_filler = true;
#else
obsx264->params.i_nal_hrd = X264_NAL_HRD_CBR;
#endif
} else {
obsx264->params.rc.i_rc_method = X264_RC_CRF;
obsx264->params.rc.f_rf_constant = (float)crf;
}
if (info.format == VIDEO_FORMAT_NV12)
obsx264->params.i_csp = X264_CSP_NV12;
else if (info.format == VIDEO_FORMAT_I420)
obsx264->params.i_csp = X264_CSP_I420;
else if (info.format == VIDEO_FORMAT_I444)
obsx264->params.i_csp = X264_CSP_I444;
else
obsx264->params.i_csp = X264_CSP_NV12;
while (*params)
set_param(obsx264, *(params++));
info("settings:\n"
"\tbitrate: %d\n"
"\tbuffer size: %d\n"
"\tcrf: %d%s\n"
"\tfps_num: %d\n"
"\tfps_den: %d\n"
"\twidth: %d\n"
"\theight: %d\n"
"\tkeyint: %d\n"
"\tvfr: %s\n"
"\tcbr: %s",
obsx264->params.rc.i_vbv_max_bitrate,
obsx264->params.rc.i_vbv_buffer_size,
(int)obsx264->params.rc.f_rf_constant,
cbr ? " (0 when CBR is enabled)" : "",
voi->fps_num, voi->fps_den,
width, height,
obsx264->params.i_keyint_max,
vfr ? "on" : "off",
cbr ? "on" : "off");
}
static bool update_settings(struct obs_x264 *obsx264, obs_data_t *settings)
{
char *preset = bstrdup(obs_data_get_string(settings, "preset"));
char *profile = bstrdup(obs_data_get_string(settings, "profile"));
char *tune = bstrdup(obs_data_get_string(settings, "tune"));
const char *opts = obs_data_get_string(settings, "x264opts");
char **paramlist;
bool success = true;
paramlist = strlist_split(opts, ' ', false);
blog(LOG_INFO, "---------------------------------");
if (!obsx264->context) {
override_base_params(obsx264, paramlist,
&preset, &profile, &tune);
if (preset && *preset) info("preset: %s", preset);
if (profile && *profile) info("profile: %s", profile);
if (tune && *tune) info("tune: %s", tune);
success = reset_x264_params(obsx264, preset, tune);
}
if (success) {
update_params(obsx264, settings, paramlist);
if (opts && *opts)
info("custom settings: %s", opts);
if (!obsx264->context)
apply_x264_profile(obsx264, profile);
}
obsx264->params.b_repeat_headers = false;
strlist_free(paramlist);
bfree(preset);
bfree(profile);
bfree(tune);
return success;
}
static bool obs_x264_update(void *data, obs_data_t *settings)
{
struct obs_x264 *obsx264 = data;
bool success = update_settings(obsx264, settings);
int ret;
if (success) {
ret = x264_encoder_reconfig(obsx264->context, &obsx264->params);
if (ret != 0)
warn("Failed to reconfigure: %d", ret);
return ret == 0;
}
return false;
}
static void load_headers(struct obs_x264 *obsx264)
{
x264_nal_t *nals;
int nal_count;
DARRAY(uint8_t) header;
DARRAY(uint8_t) sei;
da_init(header);
da_init(sei);
x264_encoder_headers(obsx264->context, &nals, &nal_count);
for (int i = 0; i < nal_count; i++) {
x264_nal_t *nal = nals+i;
if (nal->i_type == NAL_SEI)
da_push_back_array(sei, nal->p_payload, nal->i_payload);
else
da_push_back_array(header, nal->p_payload,
nal->i_payload);
}
obsx264->extra_data = header.array;
obsx264->extra_data_size = header.num;
obsx264->sei = sei.array;
obsx264->sei_size = sei.num;
}
static void *obs_x264_create(obs_data_t *settings, obs_encoder_t *encoder)
{
struct obs_x264 *obsx264 = bzalloc(sizeof(struct obs_x264));
obsx264->encoder = encoder;
if (update_settings(obsx264, settings)) {
obsx264->context = x264_encoder_open(&obsx264->params);
if (obsx264->context == NULL)
warn("x264 failed to load");
else
load_headers(obsx264);
} else {
warn("bad settings specified");
}
if (!obsx264->context) {
bfree(obsx264);
return NULL;
}
obsx264->performance_token =
os_request_high_performance("x264 encoding");
return obsx264;
}
static void parse_packet(struct obs_x264 *obsx264,
struct encoder_packet *packet, x264_nal_t *nals,
int nal_count, x264_picture_t *pic_out)
{
if (!nal_count) return;
da_resize(obsx264->packet_data, 0);
for (int i = 0; i < nal_count; i++) {
x264_nal_t *nal = nals+i;
da_push_back_array(obsx264->packet_data, nal->p_payload,
nal->i_payload);
}
packet->data = obsx264->packet_data.array;
packet->size = obsx264->packet_data.num;
packet->type = OBS_ENCODER_VIDEO;
packet->pts = pic_out->i_pts;
packet->dts = pic_out->i_dts;
packet->keyframe = pic_out->b_keyframe != 0;
}
static inline void init_pic_data(struct obs_x264 *obsx264, x264_picture_t *pic,
struct encoder_frame *frame)
{
x264_picture_init(pic);
pic->i_pts = frame->pts;
pic->img.i_csp = obsx264->params.i_csp;
if (obsx264->params.i_csp == X264_CSP_NV12)
pic->img.i_plane = 2;
else if (obsx264->params.i_csp == X264_CSP_I420)
pic->img.i_plane = 3;
else if (obsx264->params.i_csp == X264_CSP_I444)
pic->img.i_plane = 3;
for (int i = 0; i < pic->img.i_plane; i++) {
pic->img.i_stride[i] = (int)frame->linesize[i];
pic->img.plane[i] = frame->data[i];
}
}
static bool obs_x264_encode(void *data, struct encoder_frame *frame,
struct encoder_packet *packet, bool *received_packet)
{
struct obs_x264 *obsx264 = data;
x264_nal_t *nals;
int nal_count;
int ret;
x264_picture_t pic, pic_out;
if (!frame || !packet || !received_packet)
return false;
if (frame)
init_pic_data(obsx264, &pic, frame);
ret = x264_encoder_encode(obsx264->context, &nals, &nal_count,
(frame ? &pic : NULL), &pic_out);
if (ret < 0) {
warn("encode failed");
return false;
}
*received_packet = (nal_count != 0);
parse_packet(obsx264, packet, nals, nal_count, &pic_out);
return true;
}
static bool obs_x264_extra_data(void *data, uint8_t **extra_data, size_t *size)
{
struct obs_x264 *obsx264 = data;
if (!obsx264->context)
return false;
*extra_data = obsx264->extra_data;
*size = obsx264->extra_data_size;
return true;
}
static bool obs_x264_sei(void *data, uint8_t **sei, size_t *size)
{
struct obs_x264 *obsx264 = data;
if (!obsx264->context)
return false;
*sei = obsx264->sei;
*size = obsx264->sei_size;
return true;
}
static inline bool valid_format(enum video_format format)
{
return format == VIDEO_FORMAT_I420 ||
format == VIDEO_FORMAT_NV12 ||
format == VIDEO_FORMAT_I444;
}
static void obs_x264_video_info(void *data, struct video_scale_info *info)
{
struct obs_x264 *obsx264 = data;
enum video_format pref_format;
pref_format = obs_encoder_get_preferred_video_format(obsx264->encoder);
if (!valid_format(pref_format)) {
pref_format = valid_format(info->format) ?
info->format : VIDEO_FORMAT_NV12;
}
info->format = pref_format;
}
struct obs_encoder_info obs_x264_encoder = {
.id = "obs_x264",
.type = OBS_ENCODER_VIDEO,
.codec = "h264",
.get_name = obs_x264_getname,
.create = obs_x264_create,
.destroy = obs_x264_destroy,
.encode = obs_x264_encode,
.update = obs_x264_update,
.get_properties = obs_x264_props,
.get_defaults = obs_x264_defaults,
.get_extra_data = obs_x264_extra_data,
.get_sei_data = obs_x264_sei,
.get_video_info = obs_x264_video_info
};