exwm / yt_clipper

Mark up YouTube videos and quickly generate clipped webms.
https://openuserjs.org/scripts/elwm/yt_clipper
MIT License
50 stars 12 forks source link
gfy gfycat gif userscript video youtube

yt_clipper

yt_clipper is a relatively simple way to clip videos from popular platforms (for now YouTube, WeVerse, Naver TV, and AfreecaTV). It provides a graphical UI for video editing that creates instructions in json format for clipping the video. These instruction files are small and in plain text so they can be easily read, modified, and shared with others. The clipper script component provides a way to process these instructions and generate the clips you want.

Video Quick Start

For a video quickstart check out this video: https://imgur.com/a/gQ4KItt

Quick Start Guide

Visit this quickstart guide to get up and running with yt_clipper.

The contents of the quickstart guide are included here for convenience:

1) First install a user script extension (preferably Tampermonkey) for your browser (preferably chrome).

Notices

Browser Support

Video Platform Support

YouTube is the primary video platform supported by yt_clipper. Other supported platforms are listed below.

  1. YouTube
  2. Weverse (at least Weverse Lives)
  3. Naver TV
  4. AfreecaTV (at least VODs)

AfreecaTV Support Notes

Related Scripts

Table of Contents

Terminology and Installation

Markup Script Shortcuts

First ensure the script is active on the page by checking your user script extension.

Alt+Shift+A: Toggle hotkeys on/off. A green message will flash below the video indicating hotkeys are enabled.

A shortcuts reference can be toggled by clicking the scissor icon in the video controls bar.

Marker Shortcuts

A: Add marker at current time (start = green, end = yellow, selected = black center). Multiple marker pairs can be added simultaneously.

Z: Undo last marker.

Shift+Z: Redo last undone marker.

Ctrl+Shift+Alt+Z: Delete currently selected marker pair. Does nothing if no pair selected.

Shift+Mouseover End Marker (Yellow) or Left-Click Any Marker Numbering: Toggle marker pair editor. Selected marker pairs have a black center. yt_clipper_marker_pair_editor

Ctrl+Up: Select/deselect the most recently selected marker pair or else the first available pair.

Ctrl+Down: Toggle auto-hiding of unselected marker pairs. Hidden marker pairs cannot be selected with the mouse.

Adjusting marker position/time:

W: Global settings editor: yt_clipper_globals_editor

  1. Modified global settings are accented red.
  2. Change default new marker speed or crop.
    • Any new markers added will use these defaults, but this will not update existing markers.
    • To update existing markers to the default new marker speed/crop use Alt+Shift+Q/Alt+Shift+X.
  3. Specify crop resolution (automatically scales any existing crops on change).
    • This resolution must match the downloaded video's resolution.
    • By default the max available video resolution is downloaded by the clipper script and the crop resolution auto-scaled if a mismatch is detected.
  4. Specify any webms you want to merge from the clipped webms.
    • Very fast as it does not require re-encoding webms.
    • The format is similar to that for printer page ranges:
      • Each merge is a comma separated list of marker pair numbers or ranges (e.g., '1-3,5,9' = '1,2,3,5,9').
      • Multiple merges are separated with semicolons (e.g., '1-3,5,9;4-6,8' will create two merged webms).
  5. Specify Title Suffix appended to each marker pair Title Prefix to produce its Full Title.
    • By default the Title Suffix is the YouTube video ID in square brackets (e.g., [Bey4XXJAqS8]).
    • The Title Suffix is used for the name of the folder containing all generated webms.

Shift+W: Open additional settings when the global settings editor or a marker pair editor is open.

Alt+Shift+Q/alt+Shift+X: Update all existing markers to default new marker speed (Q) or crop (X).

Cropping Shortcuts

X: When marker or defaults editor is open, begin drawing crop.

Ctrl+X: Cycle crop dim opacity by 25% plus one stop point at 90%. Ctrl+Shift+X: Toggle crop crosshair.

Mouse-Based crop Adjustment:

Arrow Key Crop Adjustment:

Video Playback and Preview Shortcuts

Shift+Mouse-Wheel: Scroll the mouse wheel up/down over the video to skip forward/backward one frame per tick.

Alt+Click+Drag: Scrub/seek video time backward or forward by dragging left or right respectively.

C: Toggle previewing marker pair speed.

Shift+C: Toggle auto looping of currently selected marker pair.

Ctrl+Shift+C: Toggle auto crop chart section looping. This setting takes precedence over auto marker pair looping.

Alt+C: Toggle auto previewing gamma correction setting when between a marker pair.

Alt+Shift+C: Toggle fade loop previewing.

Ctrl+Alt+Shift+C: Toggle all previews.

Shift+R: Toggle big video previews on video progress bar hover.

Q: Toggle auto force setting of video playback speed. Takes precedence over any marker pair speed. This can be useful to try out different playback speeds without modifying settings.

Alt+Q: Cycle the force-set video speed down by 0.25. Use Q to toggle force settings video speed.

R/Alt+R: Toggle between a 90 degree clockwise/counter-clockwise rotation and no rotation.

Frame Capturing Shortcuts

E: Capture frame at current time of video at currently selected video quality/resolution.

Alt+E Trigger zipping of all captured frames for download.

Save and Load Shortcuts

S: Save markers info to a .json file.

Alt+S: Copy markers json data to clipboard. Useful if saving breaks.

G: Toggle markers data commands UI. Allows for uploading and loading markers data files in .json format and for restoring markers data auto-saved in browser local storage.

Miscellaneous Shortcuts

Shift+F: Flatten a VR video to make it easier to crop.

Dynamic Speed and Crop Shortcuts

Common Dynamic Chart Shortcuts

D: Toggle dynamic speed chart.

Alt+D: Toggle dynamic crop chart.

Shift+Click: Add a point at the clicked location.

Alt+A: Add a point at the current time.

Alt+Shift+Click: Delete a point.

Right-Click: Seek to time on bottom time-axis when clicking anywhere in chart area.

Alt+Right-Click/Ctrl+Alt+Right-Click: Set chart looping start/end marker.

Shift+D: Toggle chart loop markers

Ctrl+Mousewheel: Zoom in and out of chart.

Ctrl+Click: Reset zoom.

Click+Drag: Drag a point to move it or drag chart area to pan when zoomed in.

Alt+Z/Alt+Shift+Z: Undo/redo marker moves as well as speed and crop changes.

Dynamic Speed Chart Shortcuts

See Common Dynamic Chart Shortcuts for shortcuts shared between dynamic charts like adding and removing points.

D: Toggle dynamic speed chart.

yt_clipper_speed_chart

Notes:

Dynamic Crop Chart Shortcuts

See Common Dynamic Chart Shortcuts for shortcuts shared between dynamic charts like adding and removing points.

Dynamic crop allows for panning a crop in the default pan-only mode. In pan-only mode the crops of all crop chart points are maintained equal. For zooming and panning, enable zoompan mode from the marker pair settings extended options (Shift+W). In zoompan mode crops can change size for a zooming effect, but their aspect ratios are maintained equal.

Alt+D: Toggle dynamic crop chart.

Left-Click: Left-click a crop chart point to seek to it's time.

Left-Click+Drag: Left-click and drag a crop chart point to change it's time and seek/scrub the video.

Ctrl+Shift+C: Toggle auto crop chart section looping.

Ctrl/Alt+Mouseover: Select point as start/end of crop section.

Alt+Mousewheel-Up/Down: Intelligently toggle modes or select points. More specifically:

Ctrl+Alt+Shift+Mousewheel-Up/Down: Set current crop point's crop to that of the next/previous point's crop.

Ctrl+Shift+Click: Toggle crop point easing between auto and instant.

A/Shift+A: Set target crop component of all points following/preceding the currently selected point. Select crop components by placing your cursor in the crop input field in the marker pair settings.

ZoompPan Mode

In zoompan mode crops can change size for a zooming effect, but their aspect ratios are maintained equal. The usual crop shortcuts have different effects than usual in this mode as described here.

Ctrl+Drag: Resize crop while maintaining aspect ratio.

Ctrl+Alt+Drag: Freely resize the crop, updating the aspect ratio of all other crop points to match automatically.

X: Draw crop.

Dynamic Crop Tips

Useful YouTube Controls

  1. Use [space_bar] or K to pause/play the video.
  2. Use < and > to view a video frame by frame.
  3. Use Left-Arrow and Right-Arrow to jump backwards or forwards by 5 seconds.

Tips

User Script Tips

  1. If you're new to userscripts check out https://openuserjs.org/about/Userscript-Beginners-HOWTO for instructions.
  2. Check out the companion script for copying gfy links from gfycat as reddit markdown at https://openuserjs.org/scripts/elwm/gfy2md.
  3. Refresh the page if the script doesn't load and to clear markers when switching videos in the same window.
  4. Videos can be marked up and the markers json or clipper script can be saved before higher quality levels are available, but the final generated webm quality depends on the quality formats available.

Clipper Script Tips

  1. The clipper script skips regenerating any existing webms.
    • This makes it easy to delete webms you want regenerated and by rerunning the script.
    • Use this to work incrementally, saving markers data, starting a batch encode, continuing to mark up, overwriting the markers data, and then rerunning the encoding.

Encoding Settings Guide

Articles on CRF and vp9 Encoding

  1. Basic crf guide
  2. ffmpeg vp9 encoding guide
  3. Google vp9 basic encoding
  4. vp9 encoding tests

Tips and Settings

Markup Script Tips

  1. Move between input fields with Tab and Shift+Tab.
  2. Numeric input fields can be set using the Up/Down arrow keys or the Mousewheel.
  3. Access additional settings, including various encoding settings using the Shift+W additional settings editors.
  4. Hover over settings in the markup script to view tooltips describing each setting. yt_clipper_tooltip

Clipper Script Tips

  1. The clipper script is set to use the vp9 encoder by default (encoding used for webm videos on YouTube).
  2. Use --help, -h, or the yt_clipper_options helper script for additional options that can be enabled on the command line.
  3. Encoding settings will be automatically selected, unless overridden, based on the detected bitrate and other properties of the input video.

Gamma Correction

Clipper Script Source

Clipper Script Usage

python ./yt_clipper.py -h # Prints help. Details all options and arguments.

python ./yt_clipper.py --markers-json markers.json # automatically generate webms using markers json

python ./yt_clipper.py -j markers.json --input-video ./clip.webm  # provide a local input video

python ./yt_clipper.py -j markers.json --preview  # preview marker pairs using ffplay

python ./yt_clipper.py -j markers.json --format bestvideo[width<=1080] # specify download format used by youtube-dl

Clipper Default Arguments Files

Default arguments for the clipper script may be set using a simple file format. A default_args.txt file with comments explaining the usage is provided with the clipper script installation. The file contents are copied below for convenience:

# By default, this args file will be read by yt_clipper to set default arguments.
# To see all arguments use the `yt_clipper_options` helper script or the `-h` argument.
# Lines that begin with a `#` in this file are comments and are ignored.
# To use other arg files use the `--arg-files` argument outside of an arg file.

# The following commented lines provide an example of how to use this file.
# The lines can be uncommented (by removing the `#`) to test their effects.

# --audio
# --two-pass
# -di -dn 2
# --youtube-dl-alternative yt_dlp

Clipper Script Preview Shortcuts

See https://ffmpeg.org/ffplay.html#While-playing.

Clipper Script Installation

There is an installation that does not require the dependencies below.

  1. Extract the appropriate zip file anywhere:
  2. Simply drag and drop the markers .json file onto the yt_clipper_auto.bat file on Windows or at the terminal prompt after executing yt_clipper_auto on Mac.
  3. Use Ctrl+C if you need to cancel the process.
  4. All generated webm clips will be placed in ./webms/<markers-json-filename>.
  5. Windows users may require Microsoft Visual C++ 2010 Redistributable Package (x86).

Manual and Beta/Alpha Version Installation

Markup script (js): (1) Find the yt_clipper*.js file in the github release assets, (2) right-click > copy address, (3) open user script extension dashboard, (4) find and use option to add a script via url (in tampermonkey, utilities tab > install from url; in violentmonkey, + button at top > install from url).

Alternatively, (1) Download the yt_clipper*.js file from the github release assets, (2) open user script extension dashboard, (3) open yt_clipper for editing, (4) click inside the editor and select everything with Ctrl+A, (5) delete everything with say backspace, (6) drag and drop the markup script js file into the editor, (7) Ctrl+S to save.

Clipper script (platform-specific zip): Install as usual by extracting the zip file to a convenient location.

Additional Helper Scripts

There are some alternative helper scripts for more options:

The helper scripts have a simple format. Copy and edit yt_clipper_auto in a text editor to create custom automated versions. For example you could add --deinterlace to enable deinterlacing or use --only 2,5 to process only marker pairs 2 and 5.

Utility Scripts

There several utility scripts provided as well that wrap ffmpeg or other tools either for convenience or additional functionality.

  1. The fast_trim utility script takes a single video file as input and trims it quickly BUT approximately. The script prompts for a start time and an end time to trim the input video file. The output file name will be suffixed with -trim.
  2. The vid2gif utility script converts an input video file to a gif with a small file size and resolution. The script will prompt for the output gif fps and scale/resolution.
  3. The preprocess_hevc utility script preprocesses an input video file (likely mp4) with an hevc video stream to ensure compatibility with ffmpeg. You may need to use this script if you see errors like Invalid data found when processing input from ffmpeg when using hevc with the --input-video/-i option or the yt_clipper_auto_input_video helper script. The preprocessed output file name will be suffixed with -preproc.

Merge Utility Script

The merge utility script can be used to merge any webm files in any order:

All Releases

Since clipper script v3.6.1, releases can be tracked here: https://github.com/exwm/yt_clipper/releases.

Clipper Script Dependencies

These dependencies must be manually installed when not using the clipper script installation:

Changelog

For a complete changelog, including beta and alpha releases, see https://github.com/exwm/yt_clipper/blob/master/changelog.md.

For pre-version-unification (between markup and clipper scripts) changelogs see https://github.com/exwm/yt_clipper/blob/master/changelog-pre-version-unification.md.