Skip to content

Instantly share code, notes, and snippets.

@acceptableEngineering
Last active July 13, 2024 17:44
Show Gist options
  • Save acceptableEngineering/ba6062358e081196360b941ac93da7fc to your computer and use it in GitHub Desktop.
Save acceptableEngineering/ba6062358e081196360b941ac93da7fc to your computer and use it in GitHub Desktop.
Video Engineering (Command Line) Tricks

Description

These are commands I use on a regular basis. For the sake of simplicity, the filenames I use in the examples below are in.mp4 and out.mp4, though you can use your imagination to picture blah.mov or audio.wav on a case-by-case basis.


FFmpeg

Media Conversion

High-Quality, Infinitely Looping GIF from MP4:

ffmpeg -i input.mp4 -vf "fps=12,scale=720:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" -loop 0 output.gif

Convert FLV to MP4 without full re-encode:

ffmpeg -i in.flv -vcodec copy out.mp4

Analysis

Generating a waveform from a file with audio:

ffmpeg -i in.mp3  -filter_complex "showwavespic=s=1280x320" -frames:v 1 ./waveform.png

Adjustments / Processing

Boost audio level (volume) without re-encoding:

ffmpeg -i in.mp4 -vcodec copy -af "volume=10dB" out.mp4

Delay audio:

ffmpeg -i "in.mp4" -itsoffset 0.3 -i "in.mp4" -map 0:v -map 1:a -vcodec copy -acodec copy "out.mp4"

Ripping

Rip and audio stream (I use this to periodically rip our SHOUTcast stream for a "backup reel"):

ffmpeg -y -i http://geostream.cdn.shoutdrive.com:80/sd-mp3 out.mp3

Rip an M3U8 (video HLS):

ffmpeg -i "http://on-demand.cdn.shoutdrive.com/mixes/service/2018-April-22_Thee-O/play.m3u8" -c copy -bsf:a aac_adtstoasc out.mp4

Encoding / Streaming

Stream a local file to an RTMP server (Periscope specification in this case):

ffmpeg -i FILE.mp4 -crf 30 -preset ultrafast -acodec aac -strict experimental -ar 44100 -ac 2 -b:a 92k -vcodec libx264 -x264-params keyint=60:no-scenecut=1 -r 30 -b:v 3250k -s 1280x720 -f flv rtmp://ca.pscp.tv:80/x/STREAM_KEY_HERE;

Translating / Muxing

Mount RTSP as virtual video device:

ffmpeg -f mjpeg -i rtsp://192.168.1.16/play2.sdp -pix_fmt yuv420p -f v4l2 /dev/video0

Source


youtube-dl CLI

Ripping YouTube Video:

  1. Enumerate format and resolution choices:
youtube-dl --list-formats 'https://www.youtube.com/watch?v=C_YiECKlPuE'

Output:

[youtube] 2nAHpvFXo9s: Downloading webpage
[youtube] 2nAHpvFXo9s: Downloading m3u8 information
[youtube] 2nAHpvFXo9s: Downloading MPD manifest
[info] Available formats for 2nAHpvFXo9s:
format code  extension  resolution note
139          m4a        audio only DASH audio   64k , m4a_dash container, mp4a.40.5 (22050Hz)
140          m4a        audio only DASH audio  144k , m4a_dash container, mp4a.40.2 (44100Hz)
278          webm       256x144    DASH video   80k , webm_dash container, vp9, 30fps, video only
242          webm       426x240    DASH video  139k , webm_dash container, vp9, 30fps, video only
160          mp4        256x144    DASH video  192k , mp4_dash container, avc1.4d400c, 30fps, video only
243          webm       640x360    DASH video  240k , webm_dash container, vp9, 30fps, video only
244          webm       854x480    DASH video  415k , webm_dash container, vp9, 30fps, video only
133          mp4        426x240    DASH video  419k , mp4_dash container, avc1.4d4015, 30fps, video only
134          mp4        640x360    DASH video  772k , mp4_dash container, avc1.4d401e, 30fps, video only
247          webm       1280x720   DASH video  774k , webm_dash container, vp9, 30fps, video only
135          mp4        854x480    DASH video 1077k , mp4_dash container, avc1.4d401f, 30fps, video only
248          webm       1920x1080  DASH video 1402k , webm_dash container, vp9, 30fps, video only
136          mp4        1280x720   DASH video 2187k , mp4_dash container, avc1.4d401f, 30fps, video only
137          mp4        1920x1080  DASH video 4199k , mp4_dash container, avc1.4d4028, 30fps, video only
91           mp4        256x144     269k , avc1.4d400c, 30.0fps, mp4a.40.5
92           mp4        426x240     507k , avc1.4d4015, 30.0fps, mp4a.40.5
93           mp4        640x360     962k , avc1.4d401e, 30.0fps, mp4a.40.2
94           mp4        854x480    1282k , avc1.4d401f, 30.0fps, mp4a.40.2
95           mp4        1280x720   2447k , avc1.4d401f, 30.0fps, mp4a.40.2
96           mp4        1920x1080  4561k , avc1.4d4028, 30.0fps, mp4a.40.2 (best)
  1. The choice with ID 96 "(best)" seems ideal, let's use that one and save it as an MP4:
ffmpeg -i $(youtube-dl -f 96 -g 'https://www.youtube.com/watch?v=C_YiECKlPuE') \
-c:v copy -c:a aac -strict experimental output.mp4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment