├── .gitignore ├── doc ├── 1full video.gif ├── unused │ └── obs1.png ├── 0obs preview.gif ├── hotkey setup.png ├── 2extracted video.gif ├── script options.png └── resource-publish.bbcode ├── README.md ├── postprocess-from-obs.cmd └── create-animated-gif.lua /.gitignore: -------------------------------------------------------------------------------- 1 | /.vscode 2 | -------------------------------------------------------------------------------- /doc/1full video.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tertius1/obs-lua-scripts/HEAD/doc/1full video.gif -------------------------------------------------------------------------------- /doc/unused/obs1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tertius1/obs-lua-scripts/HEAD/doc/unused/obs1.png -------------------------------------------------------------------------------- /doc/0obs preview.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tertius1/obs-lua-scripts/HEAD/doc/0obs preview.gif -------------------------------------------------------------------------------- /doc/hotkey setup.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tertius1/obs-lua-scripts/HEAD/doc/hotkey setup.png -------------------------------------------------------------------------------- /doc/2extracted video.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tertius1/obs-lua-scripts/HEAD/doc/2extracted video.gif -------------------------------------------------------------------------------- /doc/script options.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tertius1/obs-lua-scripts/HEAD/doc/script options.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## My lua plugin(s) for OBS 2 | 3 | 1. create-animated-gif.lua 4 | 5 | This script will start an external ffmpeg to extract a section of the recorded video and export this as animated 6 | gif or mp4/webm video snippet. 7 | -------------------------------------------------------------------------------- /doc/resource-publish.bbcode: -------------------------------------------------------------------------------- 1 | This script will start an external ffmpeg to extract a section of the recorded video and export this as animated gif or mp4/webm video snippet. 2 | 3 | If you want to export a small section of your capture area as an animated gif or to some small video snippet in general, this is for you. 4 | You mark the section with the borders of a group, then start recording with the script hotkey. Recording is stopped automatically a few seconds later and the section will be exported from the recorded video. If you're not satisfied with the export, for example the file size is too large or the beginning is a second too soon, change the script settings in Tools→Scripts and click the "Process again" button. 5 | Or create a new video and try again. 6 | We're kind of misusing groups here for just pointing the export script to the section we want to extract. To make real use of the group, you can of course add some kind of watermark source to the group to create some branding for your snippets, but an empty group will suffice. 7 | In the settings of the script, you can define how long your snippet will be and how many fps it will have, and more. Usually, the created snippets should be small, so you lower the fps here. 8 | 9 | The export uses a standalone ffmpeg binary, so make sure you get it before you start creating gifs (see installation instructions below). This way the full postprocessing power of all ffmpeg filters can be used. If you need your own ffmpeg settings, look at the [ICODE]postprocess-from-obs.cmd[/ICODE] batchfile and change any settings and ffmpeg commandline arguments you want. This script is essentially a wrapper around ffmpeg that converts the parameters from OBS to the corresponding ffmpeg commandline options. 10 | 11 | [HR][/HR] 12 | 13 | To use this script: 14 | [LIST=1] 15 | [*]Download [ICODE]create-animated-gif.lua[/ICODE] and [ICODE]postprocess-from-obs.cmd[/ICODE] from the download link at github and save them to the directory you usually store your *.lua scripts for OBS. 16 | Currently, only the Windows batch file ([ICODE]postprocess-from-obs.cmd[/ICODE]) as ffmpeg wrapper is provided. If you need Linux support, port this very simple batch file to a bash script, send it to me, and I will add it to the repository. 17 | 18 | 19 | [*]Install a standalone ffmpeg from [url]https://ffmpeg.org/download.html[/url] if you don't have it already. If you download from gyan.dev, the "essentials" build should work fine. 20 | 21 | 22 | [*]If ffmpeg is not in your OS path: edit [ICODE]postprocess-from-obs.cmd[/ICODE] with a text editor such as Notepad and configure the path to ffmpeg, located at the top of the file. 23 | 24 | 25 | [*]Start your recording target, e.g. external app, game, capture device. 26 | 27 | 28 | [*]Start OBS 29 | 30 | 31 | [*]Create a source that will capture your recording target correctly. 32 | 33 | 34 | [*]In OBS, create a Group by clicking the plus (+) in the Sources widget. This will designate the section you want in the postprocessed gif/video. Give this group a meaningful name such as "Video Outline". 35 | 36 | 37 | [*]Move and resize the group, so it designates the section properly. 38 | 39 | 40 | [*]Open the OBS script setup with Tools→Scripts and add [ICODE]create-animated-gif.lua[/ICODE] with the plus (+) to the loaded scripts. 41 | 42 | 43 | [*]In the script settings, first configure the Scene where the created group exists, then the Section (point it to the group). 44 | 45 | 46 | (picture script options.png) 47 | 48 | [*]For Command, configure the path to and including [ICODE]postprocess-from-obs.cmd[/ICODE]. 49 | 50 | 51 | [*]As Output Dir, you can configure your own base output directory for the created gifs/videos. 52 | 53 | 54 | [*]Configure the other settings accordingly: Start, Length, etc. 55 | 56 | 57 | [*]In Setup→Hotkeys, assign the script-specific record+postprocessing hotkey. 58 | 59 | 60 | (picture hotkey setup.png) 61 | [/LIST] 62 | 63 | [HR][/HR] 64 | 65 | The workflow for using the script is simple: 66 | [LIST=1] 67 | [*]Start recording with hotkey (or manually). 68 | [*]Perform some action in your capture target. 69 | [*]Wait for postprocessing. 70 | [/LIST] 71 | 72 | This is an example how OBS itself will look with some group that will designate the section: 73 | 74 | (picture 0obs preview.gif) 75 | 76 | Start recording will create this video: 77 | 78 | (picture 1full video.gif) 79 | 80 | From this big video with parts of the game UI at the left and the right visible, the designated section will be extracted: 81 | 82 | (picture 2extracted video.gif) 83 | 84 | 85 | [HR][/HR] 86 | 87 | Before you start working, verify [i]Start Offset[/i] in the script settings. Set it to the expected delay between recording start and start of the action you want to extract. 88 | It's probably 1 to 5 seconds if you manually click [i]Start Recording[/i], and 0 to 1 second if you use the hotkey. 89 | 90 | If you start recording with the hotkey or with [i]Auto Postprocessing Active[/i] enabled, recording will automatically stop 10 seconds after the configured video length plus start offset plus 10 seconds safety margin elapsed. 91 | If you activated [i]Create additional variations[/i], the recording will stop after at least 30 seconds instead. 92 | 93 | If you disabled [i]Auto Postprocessing Active[/i] and don't use the script specific hotkey for recording start, the script is inactive and will neither stop recording automatically nor do any automated postprocessing. This way it will not interfere with regular OBS usage. However, you can always click [i]Process Again[/i] from the script settings to postprocess the last video you recorded manually. The script will watch what you record and always remember the last filename. 94 | 95 | [HR][/HR] 96 | 97 | After postprocessing finished, check the output. It will be written to the output directory in a subdirectory of its own. 98 | The directory name is the base name of the recorded video to avoid cluttering the OBS output directory with all the generated and variated output snippets. 99 | 100 | If you're not satisfied with the created snippet, adjust start, length and frame rate, then click [i]Process Again[/i] to create a GIF/video with new settings. 101 | 102 | For convenience, activate [i]Create additional variations[/i]. The postprocessing script will create a bunch of files with slightly variated length and fps, so you can pick the best length/fps/size ratio. It's especially useful if you intend to upload an animated gif to a service with a low file size limit. 103 | 104 | Even after you recorded a new video or restarted OBS, you can create new snippets from videos postprocessed earlier. 105 | Change to the directory where the old postprocessing files are and locate the batch file [ICODE]process_again.cmd[/ICODE]. It was created with the current script settings. To create a new snippet, edit the file with a text editor such as Notepad and change the parameters accordingly. Then start [ICODE]process_again.cmd[/ICODE] (double click in Windows Explorer) and a new snippet will be created. 106 | -------------------------------------------------------------------------------- /postprocess-from-obs.cmd: -------------------------------------------------------------------------------- 1 | @echo off 2 | SETLOCAL ENABLEDELAYEDEXPANSION 3 | REM postprocess-from-obs.cmd -- video postprocessing called by OBS 4 | 5 | REM -------------------------------------------------------- 6 | REM If your ffmpeg isn't in the PATH, remove the REM from the 7 | REM second SET ffmpeg=... line and change the path accordingly. 8 | SET ffmpeg=ffmpeg.exe 9 | REM SET ffmpeg=C:\Program Files (x86)\ffmpeg\bin\ffmpeg.exe 10 | REM -------------------------------------------------------- 11 | REM If you want a logfile lf ffmpeg processing, activate it here 12 | SET log=nul 13 | REM SET log=ffmpeg.log 14 | REM -------------------------------------------------------- 15 | 16 | if "%~1"=="" goto :help 17 | if "%~1"=="process" goto :process 18 | 19 | REM read command line 20 | set script=%~f0 21 | 22 | set source=%~1 23 | set destdir=%~2 24 | 25 | set xpos=%3 26 | set ypos=%4 27 | set width=%5 28 | set height=%6 29 | set start=%7 30 | set length=%8 31 | set fps=%9 32 | shift /8 33 | set ext=%9 34 | shift /8 35 | set colors=%9 36 | shift /8 37 | set variated=%9 38 | shift /8 39 | set audio=%9 40 | 41 | set source=%source:/=\% 42 | set destdir=%destdir:/=\% 43 | set outputdir=%destdir%\%~n1 44 | 45 | REM log calls 46 | >>"%destdir%\%~n0.log" echo %* 47 | 48 | md "%outputdir%" 1>nul 2>nul 49 | if not exist "%outputdir%" ( 50 | echo Unable to create output directory "%outputdir%" 51 | goto :help 52 | ) 53 | 54 | set again=%outputdir%\process_again.cmd 55 | 56 | REM create process_again.cmd in outputdir for manual direct postprocessing 57 | >"%again%" echo set source=%source% 58 | >>"%again%" echo set outputdir=%outputdir% 59 | >>"%again%" echo set xpos=%xpos% 60 | >>"%again%" echo set ypos=%ypos% 61 | >>"%again%" echo set width=%width% 62 | >>"%again%" echo set height=%height% 63 | >>"%again%" echo set start=%start% 64 | >>"%again%" echo set length=%length% 65 | >>"%again%" echo set fps=%fps% 66 | >>"%again%" echo set ext=%ext% 67 | >>"%again%" echo set colors=%colors% 68 | >>"%again%" echo set variated=%variated% 69 | >>"%again%" echo set audio=%audio% 70 | >>"%again%" echo "%script%" process 71 | 72 | start "OBS custom postprocessing" "%script%" process 73 | 74 | goto :eof 75 | 76 | 77 | :help 78 | echo postprocess-from-obs.cmd -- video postprocessing called by OBS 79 | echo. 80 | echo Usage: 81 | echo postprocess_from_obs.cmd ^