Home/News | About | Download | Documentation | Forum | Bug Reports | Contact | Donations | Consulting | Projects | Legal | Security | FATE

This forum has not been maintained for a long time and will probably get deleted in the near future.
For faster responses to your questions, please use StackOverflow instead and tag your questions with "FFmpeg".
If you need a backup of the posts from this forum, please contact me directly.

VHS - Video Handler Script for *nix

A collection of useful tutorials for some common tasks.

VHS - Video Handler Script for *nix

Postby sea » Thu Mar 26, 2015 1:39 am

Hello everyone

ffmpeg is a great tool, alot of thanks to the devs.
All those options are required, without them, ffmpeg wouldnt be as powerfull as it is.

However, many users, me included, cannot remember all those arguments for all diffrent occasions.
And some favorite preferences might want to be reused, but be hard to remember if not used for some time.

Q: True, but why would i use such a script. Besides it has lots of weird options too!
A: Because the longest commands with vhs are still lots shorter than the average ffmpeg command

Q: What is that -Q fwvga you use in the screenshot?
A: The -Q option will absolut enforce the preset fwvga from $HOME/.config/vhs/presets, the video resolution and the bitrates.
Using the -q option will keep the aspect ration of the input file.

A neat trick:
Adding your own presets, and the help text (passing: vhs -h) will show you the calculated file size for a 1 minute file.

So i started to write a script, to type less on the consle, but maintain my preferences for certain types of "video tasks".
What first started as an homage-script named like the old video tapes, just encoding from one file to another, grew from 20 lines to over 2000.
But that may happen as soon one figures out the power of ffmpeg.
And just today i could accomplish a progress bar when encoding from one file to another, so i finaly wanted to share it with you guys :)

  1. Projectpage: http://github.com/sri-arjuna/vhs
  2. Preview of a pracital use:
* This is just an example of the initial purpose, for me, vhs also replaced gtk-recordMyDesktop and ogmrip on my computer and saves me aprox ~250mb diskspace and quite a few dependencies.
* Linebreaks of the first file are intentional to show the progressbar.
* The countdown of the timeout is not shown, could be changed using -T 4m.

For both of the files a similar ffmpeg command was generated and run in background:
Code: Select all
ffmpeg -v quiet -i "02 Applied Physics.mkv"    -strict -2  -map 0:0 -b:v 768K -vf scale=720:-1 -c:v libx264  -minrate 1536K -maxrate 1536K -bufsize 768K   -b:a 384K -ac 2 -c:a ac3   -map 0:1    "02 Applied Physics.0.mkv"

This script works only on *nix systems with bash installed.
Arch, Fedora, FreeBSD, Gentoo and Ubuntu were reported to run it successfully (if 'all' other files were available).
If there is no /etc, dont even try to install!

To run properly (depending on what you want to use) vhs requires the following:
TUI) https://github.com/sri-arjuna/tui
In order to display properly, VHS will install TUI using git only or wget and unzip.
Also, TUI just changed its installation script to use PREFIX, please let me know if it works on your system (which is?) or not.
Bash) Is expected to be installed, bash-completion is optional
ffmpeg) viewtopic.php?f=25&t=38
libaacplus) viewtopic.php?f=25&t=36
libdvdread) http://www.linuxfromscratch.org/blfs/vi ... dread.html
libmp3lame) http://lame.sourceforge.net/
libogg) http://www.linuxfromscratch.org/blfs/vi ... ibogg.html
libtheora) http://www.linuxfromscratch.org/blfs/vi ... heora.html
libvorbis) http://www.linuxfromscratch.org/blfs/vi ... orbis.html
libvpx) http://www.linuxfromscratch.org/blfs/vi ... ibvpx.html
libx264) viewtopic.php?f=25&t=36
H.265) http://xhevc.com/en/hevc/decoder/download.jsp (ffmpeg compile hint: viewtopic.php?f=8&t=1811&p=5113&hilit=h.265#p5113)
vobcopy) http://vobcopy.org/
flac) http://www.linuxfromscratch.org/blfs/vi ... /flac.html
alsa-utils) http://www.linuxfromscratch.org/blfs/vi ... utils.html
mkvtoolnix) https://www.bunkus.org/videotools/mkvto ... loads.html
v4l-utils) http://linuxtv.org/downloads/v4l-utils/ ... .2.tar.bz2
List might be incomplete.

Once installed,
  1. Configure vhs to your preferences
    Code: Select all
    vhs -C
  2. To see the generated command or what went wrong, the logfile, run
    Code: Select all
    vhs -L
  3. To see the full ffmpeg process to figure out the error your own, or to post encoding errors you cannot figure to solve yourself (please do not include output lines of vhs)
    Code: Select all
    vhs -v [options] input ...

What can ffmpeg/vhs do?
Original purpose was to encode file to file to save disk space according to presets / video resolution.
Thus, '1.' is the most 'suggested' usage.
  1. Encode file to file, to preset quality settings
    Code: Select all
    vhs -Q fhd *.mpeg

    Would create this command for each of the expanded names:
    Code: Select all
    ffmpeg -v quiet -i "file...2.mpeg"    -strict -2  -map 0:0 -b:v 1920K -vf scale=1920x1080 -c:v libx264  -minrate 3840K -maxrate 3840K -bufsize 1920K   -b:a 384K -ac 2 -c:a ac3   -map 0:1  "file...2.mkv"
  2. Add another subtitle/audio stream to videofile
    Code: Select all
    vhs -a newstream.aac -a newstream.  input.mp4
  3. Record from webcam
    Code: Select all
    vhs -W
  4. Record full desktop/screen
    Code: Select all
    vhs -S [options]
  5. Encode vob files (from dvd, requires vobcopy!), to hd ready quality using 3rd audio stream for default output stream, and 2nd audio stream for alternate, including subtitles, and add jpn as subtitle and audio. (if jpn is either audio stream 3 or 2, it will be added twice!)
    vhs -DQ hd -I "3 2" -tl jpg
  6. Record a 'guide', full desktop with webcam as pip (alignable to 9 preset locations), top right with 480 with
    Code: Select all
    vhs -G [options]

    Would represent:
    Code: Select all
    ffmpeg -v quiet -f v4l2 -s 640x480 -framerate 25 -i /dev/video0 -f x11grab -video_size  1920x1080 -framerate 25 -i :0 -f alsa -i default -filter_complex '[0:v:0]scale=320:-1[a] ; [1:v:0][a]overlay' -c:v libx264 -crf 23 -preset veryfast -c:a ac3 -q:a 4  -strict -2   "$XDG_VIDEO_DIR/guide-out.4.mkv"
  7. Make a sample file, lasting 1 minute (default)
    Code: Select all
    vhs -z 2:30 [options] input.webm
  8. Extract audio from video
    Code: Select all
    vhs -e mp3 -z 0:5-2:30 input.mkv
  9. If audio streams cannot be reckognized (as in language), you can set to force certain audio ids to be used, rather than beeing asked, this examples use the 3rd stream for default audio output.
    Code: Select all
    vhs -I 3 -I 2 input.wmv
    # Either on of the two
    vhs -I "3 2" input.wmv
  10. At all times, you can edit/change the generated ffmpeg command, by passing -A.
    Code: Select all
    vhs -AQ fwvga -z 0:0-1:35:07.145 input.mkv

    Would represent:
    Code: Select all
    ffmpeg -v quiet -i "input.mkv"    -strict -2  -map 0:0 -b:v 768K -vf scale=854x480 -c:v libx264  -minrate 1536K -maxrate 1536K -bufsize 768K   -b:a 384K -ac 2 -c:a ac3   -map 0:1 -ss 0:0 -to 1:35:07.145   "input.0.mkv"
  11. No worries, you still can customize the final ffmpeg command even more, by either passing:
    Code: Select all
    myString="-vf \"drawtext=fontfile=/usr/share/vlc/skins2/fonts/FreeSans.ttf: text='Central Text':\ x=(w-text_w)/2:y=(h-text_h-line_h)/2: fontsize=100: fontcolor=white@0.2\""

    vhs -E "$myString" *
    ## OR
    vhs -A[options] input input2..

    The -E will apply passed STRING to all files passed to encode,
    -A will open a text editor for each and every input file.

Your default target container (mkv is preset) is set within the configuration file $HOME/.config/vhs/vhs.conf.
So are your two most favorite languages. you can choose to either use both or only one of the languages to be kept when encoding file to file or dvd to file.

I would like to add 'streaming' options, but since i have no personal need for that, i would like to ask (along this post/introduction) for some real-life examples (as PM or reply)
Encoding a dvd might fail during vobcopy, which is an external tool and cannot be fixed by me.

Code: Select all
vhs (1.3.4) - Video Handler Script
Usage:       vhs [options] filename/s ...

Examples:   vhs -C            | Enter the configuration/setup menu
      vhs -b a128 -b v512 filename   | Encode file with audio bitrate of 128k and video bitrate of 512k
      vhs -c aAUDIO -c vVIDEO -c sSUBTITLE filename   | Force given codecs to be used for either audio or video (NOT recomended, but as bugfix for subtitles!)
      vhs -e mp4 filename      | Re-encode a file, just this one time to mp4, using the input files bitrates
      vhs -[S|W|G]         | Record a video from Screen (desktop) or Webcam, or make a Guide-video placing the webcam stream as pip upon a screencast
      vhs -l ger         | Add this language to be added automaticly if found (applies to audio and subtitle (if '-t' is passed)
      vhs -Q fhd filename      | Re-encode a file, using the screen res and bitrate presets for FullHD (see RES info below)
      vhs -Bjtq fhd filename      | Re-encode a file, using the bitrates from the config file, keeping attachment streams and keep subtitle for 'default 2 languages' if found, then forcing it to a Full HD dimension

Where options are: (only the first letter)
   -h(elp)          This screen
   -2(-pass)         Enabled 2 Pass encoding: Video encoding only (Will fail when combinied with -y (copy)!)
   -a(dd)      FILE      Adds the FILE to the 'add/inlcude' list, most preferd audio- & subtitle files (images can be only on top left position, videos 'anywhere' -p allows ; just either one Or the other at a time)
   -A(dvanced)         Will open an editor before executing the command
   -b(itrate)   [av]NUM      Set Bitrate to NUM kilobytes, use either 'a' or 'v' to define audio or video bitrate
   -B(itrates)         Use bitrates (a|v) from configuration (/home/sea/.config/vhs/vhs.conf)
   -c(odec)   [atv]NAME   Set codec to NAME for audio, (sub-)title or video, can pass '[atv]copy' as well
   -C(onfig)         Shows the configuration dialog
   -d(imension)   RES      Sets to ID-resolution, but keeps aspect-ratio (:-1) (will probably fail, use AFTER '-Q RES')
   -D(VD)            Encode from DVD (not working since code rearrangement)
   -e(xtension)   CONTAINER   Use this container (ogg,webm,avi,mkv,mp4)
   -E(tra)      'STRING'   STRING can be any option to ffmpeg you want, understand that it is inserted right after the first input file!
   -f(ps)      FPS      Force the use of the passed FPS
   -F(PS)            Use the FPS from the config file (25 by default)
   -G(uide)         Capures your screen & puts Webcam as PiP (default: top left @ 320), use -p ARGS to change
   -i(nfo)      filename   Shows a short overview of the video its streams and exits
   -I(d)      NUM      Force this audio ID to be used (if multiple files dont have the language set)
   -j(pg)            Thought to just include jpg icons, changed to include all attachments (fonts, etc)
   -K(ill)            Lets you select the job to kill among currenlty running VHS jobs.
   -l(anguage)   LNG      Add LNG to be included (3 letter abrevihation, eg: eng,fre,ger,spa,jpn)
   -L(OG)            Show the log file
   -p(ip)      LOCATION[NUM]   Possible: tl, tc, tr, br, bc, bl, cl, cc, cr ; optional appending (NO space between) NUM would be the width of the PiP webcam
   -q(uality)   RES      Encodes the video at ID's bitrates from presets
   -Q(uality)   RES      Sets to ID-resolution and uses the bitrates from presets, video might become sctreched
   -r(ate)      48000      Values from 48000 to 96000, or similar
   -R(ate)            Uses the frequency rate from configuration (/home/sea/.config/vhs/vhs.conf)
   -S(creen)         Records the fullscreen desktop
   -t(itles)         Use default and provided langauges as subtitles, where available
   -T(imeout)   2m      Set the timeout between videos to TIME (append either 'm' or 'h' as other units)
   -v(erbose)         Displays encode data from ffmpeg
   -V(erbose)         Show additional info on the fly
   -w(eb-optimized)      Moves the videos info to start of file (web compatibility)
   -W(ebcam)         Record from webcam
   -x(tract)         Clean up the log file
   -X(tract)         Clean up system from vhs-configurations
   -y(copY)         Just copy streams, fake convert
   -z(sample)  1:23[-1:04:45[.15]   Encdodes a sample file which starts at 1:23 and lasts 1 minute, or till the optional endtime of 1 hour, 4 minutes and 45 seconds

After installing codecs, drivers or plug in of webcam,
it is highy recomended to update the list file.
You can do so by entering the Setup dialog: vhs -C
and select 'UpdateLists'.

NUM:      Number for specific bitrate (ranges from 96 to 15536
NAME:      See '/home/sea/.config/vhs/vhs.list' for lists on diffrent codecs
RES:      These bitrates are ment to save storage space and still offer great quality, you still can overwrite them using something like -b v1234.
      Use '-q LABEL' if you want to keep the original bitrates, use '-Q LABEL' to use the shown bitrates and aspect ratio below.
      Also, be aware that upcoding a video from a lower resolution to a (much) higher resolution brings nothing but wasted diskspace, but if its close to the next 'proper' resolution aspect ratio, it might be worth a try.
      See "/home/sea/.config/vhs/presets" to see currently muted ones or to add your own presets.

   Label   Resolution   Pixels   Vidbit   Audbit   Bitrate   1min   Comment
   a-vga   640x480    307.20K   512   196   708.00k   5.2mb   Anime optimized, VGA     
   a-dvd   720x576    414.72K   640   256   896.00k   6.6mb   Anime optimized, DVD-wide - PAL   
   a-hd   1280x720    921.60K   768   256   1.02M   7.5mb   Anime optimized, HD     
   a-fhd   1920x1080    2.07M   1280   256   1.54M   11.2mb   Anime optimized, Full HD   
   qvga   320x240    76.80K   240   128   368.00k   2.7mb   Quarter of VGA, mobile devices   
   hvga   480x320    153.60K   320   192   512.00k   3.8mb   Half VGA, mobile devices   
   nhd   640x360    230.40K   512   256   768.00k   5.6mb   Ninth of HD, mobile devices   
   vga   640x480    307.20K   640   256   896.00k   6.6mb   VGA       
   dvdn   720x480    345.60K   744   384   1.13M   8.3mb   DVD NTSC     
   dvd   720x576    414.72K   768   384   1.15M   8.4mb   DVD-wide - Pal     
   fwvga   854x480    409.92K   768   384   1.15M   8.4mb   DVD-wide - NTCS, mobile devices   
   hd   1280x720    921.60K   1280   384   1.66M   12.2mb   HD aka HD Ready   
   fhd   1920x1080    2.07M   1920   384   2.30M   16.9mb   Full HD     
   qhd   2560x1440    3.69M   3840   448   4.29M   31.4mb   2k, Quad HD - 4xHD   
   uhd   3840x2160    8.29M   7680   512   8.19M   60.0mb   4K, Ultra HD TV   
   yt-240   426x240    102.24K   768   196   964.00k   7.1mb   YT, seriously, no reason to choose 
   yt-360   640x360    230.40K   1000   196   1.20M   8.8mb   YT, Ninth of HD, mobile devices 
   yt-480   854x480    409.92K   2500   196   2.70M   19.7mb   YT, DVD-wide - NTCS, mobile devices 
   yt-720   1280x720    921.60K   5000   512   5.51M   40.4mb   YT, HD     
   yt-1080   1920x1080    2.07M   8000   512   8.51M   62.3mb   YT, Full HD     
   yt-1440   2560x1440    3.69M   10000   512   10.51M   77.0mb   YT, 2k, Quad HD - 4xHD 
   yt-2160   3840x2160    8.29M   40000   512   40.51M   296.7mb   YT, 4K, Ultra HD TV   

CONTAINER (a):   aac ac3 dts flac mp3 ogg vorbis wav wma
CONTAINER (v):  avi flv mkv mp4 mpeg ogv theora webm wmv xvid
VIDEO:      [/path/to/]videofile
LOCATION:   tl, tc, tr, br, bc, bl, cl, cc, cr :: as in :: top left, bottom right, center center
LNG:      A valid 3 letter abrevihation for diffrent langauges
HRZ:      44100 *48000* 72000 *96000* 128000
TIME:      Any positive integer, optionaly followed by either 's', 'm' or 'h'

For more information or a FAQ, please see man vhs.

Script:      /home/sea/.local/bin/vhs.sh
Config:      /home/sea/.config/vhs/vhs.conf
Containers:   /home/sea/.config/vhs/containers/*
Lists:      /home/sea/.config/vhs/vhs.list
Log:      /home/sea/.config/vhs/vhs.log
Presets:   /home/sea/.config/vhs/presets

Replace /home/sea by just $HOME in your mind, which is used to display and within the help text.

Hope this helps and have fun :)
Last edited by sea on Tue Mar 31, 2015 3:09 pm, edited 5 times in total.
Posts: 12
Joined: Wed Mar 25, 2015 11:04 pm

Re: VHS - Video Handler Script for *nix

Postby sea » Fri Mar 27, 2015 2:28 pm

  • Updated: corrected filesize calculation
  • - Updated: during verbose ffmpeg progress bar is no longer shown
  • - Updated: Now can change volume
  • - Updated: Now can merge/join/append video files.
  • - Updated: Now uses a single file to handle all containers

Todays crazyness :mrgreen: :ugeek:
Code: Select all
vhs.sh -2xJe mp4 -b v768 -b a192  v*o[12].mkv

This is the equivalent of _6_ individual ffmpeg calls!
  • -2 = 2 Pass encoding ( times = + 2 )
  • x = Clean logfile
  • -J = Join passed files ( times = + (files + 1) ) ## 2 files +1 = 3
  • -e mp4 = encode to mp4 (times = + 1)
  • -b [av]123 = use bitrate for audio/video
And it looks:
The extension of the final file is just a display error, and is already fixed.

Hope you like it as much as i do :)
Posts: 12
Joined: Wed Mar 25, 2015 11:04 pm

Re: VHS - Video Handler Script for *nix

Postby sea » Sun Mar 29, 2015 2:36 pm

Final Release 2.0
  • Added: Stream Play
  • Added: Stream Server: Webcam, Screen, Guide, Video
  • Added: History re-select for Stream Play/Server individualy
  • Updated: Now can encode multiple files to audio

Once you've played some webradios like:
Code: Select all
vhs -Pu http://www.engeryswiss.ice.infomaniak.ch/energyswiss-high.mp3

You can easy select among previously played urls later.

Just alike, you can stream from your webcam, your desktop, a guide (desktop+webcam), video or audio files...

Hope you like it as much as i do :)
:D :cool:
Have a nice weekend!
Posts: 12
Joined: Wed Mar 25, 2015 11:04 pm

Return to Tutorials

Who is online

Users browsing this forum: No registered users and 2 guests