Things I hack together on mager weekends.
Something to convert video file to an MP3 audio file. It uses ffprobe
on source file to determine appropriate audio bitrate.
At times, you don't need the noise or just the noise (for further processing).
ffmpeg_strip_audio FILE
With input a.mp4
, output of strip_audio
is a-.mp4
and for strip_video
is a_audio.mp4
.
Amplify audio by explicit value or automatically based on original file's max loudness. If amplification level is determined based on original file's loudness, file will not be processed if it's outside MIN_THRESHOLD
and MAX_THRESHOLD
(see Arguments).
ffmpeg_amplify.py [-h] [-v VOLUME] [-s] [-m MIN_THRESHOLD] [-M MAX_THRESHOLD] [-y] [-V] [--suffix SUFFIX] FILE
-v VOLUME
,--volume VOLUME
: Manually set volume amplification level.-s
,--show_only
: ShowFILE
's current volume level, then exit.-m MIN_THRESHOLD
,--min_threshold MIN_THRESHOLD
: (Abs. value, default: 1.0)-M MAX_THRESHOLD
,--max_threshold MAX_THRESHOLD
: (Abs. value, default: 30.0)--suffix SUFFIX
: Suffix to be appended to resulting filename.-y
: Suppress question if file exists.-V
: Verbosity
Losslessly rejoin audio and video files. I loathe watching videos with ridiculously low audio volume, so I extract the audio to process in a DAW, then join it back with this script. Why such convoluted workflow? Saves me hours of recompressing, that's why.
ffmpeg_join_av FILE
The assumptions are that FILE
is an MP4 video file, and a corresponding FILE_audio.m4a
to join it with exists.
Example:
ffmpeg_join_av a.mp4
joinsa.mp4
witha_audio.mp4
(if exist) intoa_av.mp4
.
Losslessly cut an audio or video file.
ffmpeg_cut.py [-h] [-s START] [-e END] [-y] [-V] [--suffix SUFFIX] FILE
-s START
: Timestamp of starting point to cut from.-e END
: Timestamp of end point to cut to.--suffix SUFFIX
: Suffix to be appended to resulting filename.-c
: Mark inputFILE
as config file. If set, other switches but-y
and-V
are ignored.-y
: Suppress question if file exists.-V
: Verbosity
If -c
is set, script assumes FILE
to be a configuration file with the following format:
[main] src=FILE.mp4 # path to file sections=1 2 3 # space separated sections to process [sections] 1= 2=01:01 # starting timestamp for a section, first one left empty 3=02:02 9=03:03 # to write any but the last section, put any number
Instead of using installers, I prefer to extract zipped versions of programs I use, then symlink them to a generic name (e.g. E:\blender-2.79b-windows64
to E:\blender
). Shortcuts can then just refer to the symlink and remain unchanged, even if the symlink points to a newer version. This script creates a link to the latest subdirectory in a path with names matching a pattern. Wrote it because I'm sick of constantly removing old symlink to create a different one targeting newer (manually typed) directory path.
lnlatest.py [-h] [-d DIR_PATH] [-e] LINK PATTERN
Arguments:
-d DIR_PATH
: Specify root directory. If unspecified, it defaults to current working directory.-e
: Automatically remove old symlink. Bothmklink
andln
won't overwrite existing link, so usually this is what we'd want. Putting it anyway just to make sure.LINK
: Symlink name to be created.PATTERN
: Glob pattern of directories to be matched. For example,emacs-*
matchesemacs-26.1-x86_64
,emacs-25.0-x86_64
, etc. Latest matching directory will be targeted if found.
Converts PDF to and from QDF, using qpdf. I use these to edit a PDF file's page numbering.
pdf2qdf|qdf2pdf PDF_FILE
Input for qdf2pdf
is also the PDF file, just so I can do the fewest change to the original command when converting back to PDF.
Dump and update PDF metadata, using PDFtk. I use this to edit a PDF file's bookmark list (table of contents).
pdfdata.py [-h] [-d [DATAFILE]] [-s [DATAFILE]] [-T [TOCFILE]] [-t [TOCFILE]] [-o [OUTPUT]] FILE
-d [DATAFILE]
,--dump [DATAFILE]
: Dump PDF data to file.-s [DATAFILE]
,--set [DATAFILE]
: Set PDF data from file.-T [TOCFILE]
,--dump_toc [TOCFILE]
: Dump PDF bookmark data to a TOC file.-t [TOCFILE]
,--toc [TOCFILE]
: Set PDF bookmark data from TOC file.-o [OUTPUT]
,--output [OUTPUT]
: Output PDF file if setting PDF data.
When I use Gnome DE, I miss JGPaiva's GridMove. So I wrote this script, a crude approximation of GridMove's template I use most using wmctrl
and X utils. It's meant to be called through custom keyboard shortcut.
wmctrl_gridmove.py [-h] [-d DISPLAY_ID] {l,r,m}
-d DISPLAY_ID
: Move active window to assigned monitor, 0-indexed.POS
: Positional argument, eitherl
,r
orm
to move and resize active window to the left or right side or maximized, respectively, of assigned monitor.
Example:
wmctrl_gridmove.py -m 0 l
moves active window to 1st monitor's left side. Simple, eh?