Resource icon

OBS Lua Animated gif Creator 1.00

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.

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.

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.
Or create a new video and try again.
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.
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.

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 postprocess-from-obs.cmd 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.



To use this script:
  1. Download create-animated-gif.lua and postprocess-from-obs.cmd from the download link at github and save them to the directory you usually store your *.lua scripts for OBS.
    Currently, only the Windows batch file (postprocess-from-obs.cmd) 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.

  2. Install a standalone ffmpeg from https://ffmpeg.org/download.html if you don't have it already. If you download from gyan.dev, the "essentials" build should work fine.

  3. If ffmpeg is not in your OS path: edit postprocess-from-obs.cmd with a text editor such as Notepad and configure the path to ffmpeg, located at the top of the file.

  4. Start your recording target, e.g. external app, game, capture device.

  5. Start OBS

  6. Create a source that will capture your recording target correctly.

  7. 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".

  8. Move and resize the group, so it designates the section properly.

  9. Open the OBS script setup with Tools→Scripts and add create-animated-gif.lua with the plus (+) to the loaded scripts.

  10. In the script settings, first configure the Scene where the created group exists, then the Section (point it to the group).


    script options.png

  11. As Command, configure the path to and including postprocess-from-obs.cmd.

  12. As Output Dir, you can configure your own base output directory for the created gifs/videos.

  13. Configure the other settings accordingly: Start, Length, etc.

  14. In Setup→Hotkeys, assign the script-specific record+postprocessing hotkey:


    hotkey setup.png



The workflow for using the script is simple:
  1. Start recording with hotkey or manually.
  2. Perform some action in your capture target.
  3. Wait for automated postprocessing.

This is an example how OBS itself will look with some group that will designate the section:

0obs preview.gif


Start recording will create this video:

1full video.gif


From this big video with parts of the game UI at the left and the right visible, the designated section will be extracted:

2extracted video.gif





Before you start working, verify Start Offset in the script settings. Set it to the expected delay between recording start and start of the action you want to extract.
It's probably 1 to 5 seconds if you manually click Start Recording, and 0 to 1 second if you use the hotkey.

If you start recording with the hotkey or with Auto Postprocessing Active enabled, recording will automatically stop 10 seconds after the configured video length plus start offset plus 10 seconds safety margin elapsed.
If you activated Create additional variations, the recording will stop after at least 30 seconds instead.

If you disabled Auto Postprocessing Active 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 Process Again 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.



After postprocessing finished, check the output. It will be written to the output directory in a subdirectory of its own.
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.

If you're not satisfied with the created snippet, adjust start, length and frame rate, then click Process Again to create a GIF/video with new settings.

For convenience, activate Create additional variations. 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.

Even after you recorded a new video or restarted OBS, you can create new snippets from videos postprocessed earlier.
Change to the directory where the old postprocessing files are and locate the batch file process_again.cmd. 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 process_again.cmd (double click in Windows Explorer) and a new snippet will be created.
Author
koala
Downloads
494
Views
3,537
First release
Last update
Rating
5.00 star(s) 1 ratings

More resources from koala

Latest reviews

Excellent Plugin!!! Didn't know how badly I needed this until I found it, a million thanks
Top