VLC HowTo/Use for transcription (Linux)

From VideoLAN Wiki
Revision as of 06:49, 6 October 2010 by Derek (talk | contribs) (Instructions and a script useful for doing transcription in linux)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search


VLC makes a good option for people trying to do transcription of audio or video in linux. The script below might be usable in other operating systems, but will likely take some adjusting.

The purpose of this howto is to show you how to configure vlc and use the script below to enable you to control vlc with scripted commands and, most importantly, take a timestamp from vlc and automatically type it into whatever document you are working on, without ever needing to shift focus away from the document.

There are other ways to achieve what I've done with this, many of them likely better than what is here. But this works, and works well.

PREREQUISITES:

First, you need to have VLC (obviously), xautomation OR a version of xdotool (newer than august 2010), and you need the openbsd implementation of netcat.

The openbsd version of netcat is in the repositories of most major linux distirbutions these days. This script is written for use in Archlinux, so it's likely that you will need to change the command used by netcat in the script. Arch uses nc.openbsd, just replace it with whatever you need.

xautomation will almost certainly be in your repos, and xdotool might be. xautomation seems to be the better choice if you're only concerned about how quickly it does the job, but xdotool is nice as well if you're doing fancier things with it. However, if you do choose to try xdotool, you'll need a build done later than August 2010, as some of the features used in this script are not in the older versions available in most repositories.

SETUP:

To set up vlc to use this script, go to tools->preferences and click on "show settings->all" at the bottom. From that menu, select "Interface->Main Interfaces", and check the "Remote Control Interface" box. Next, select "Interface->Main Interfaces->RC", check the "Fake TTY' box, and enter 'home/YOURNAME/vlc.sock'in the "UNIX socket command input" field.

You probably also want to adjust the "Very short jump length" located in "Interface->Hotkeys settings". This script assumes that it is set for 5 seconds rather than the default of 3 seconds. It won't affect the script if you don't change this value, as it uses the 'very short jump' command rather than jogging a specific number of seconds. If you poke around the vlc docs, you'll see a seek command, but that is to go to a certain point in a file rather than going forward or backward a certain number of seconds.

Hit "Save". Restart VLC, and check to see if it creates "vlc.sock" in your home directory. This should be created automatically when vlc starts. If it doesn't, check your socket path and try again.

Next, you need to set up your hotkeys for your window environment. This should work equally well in any window manger, so pick whichever you like. Remember to check to make sure that whichever hotkeys you wish to use are not already used by your windowmanager. Redefine these hotkeys or the defaults as necessary. I didn't have any luck with the global hotkeys settings within VLC, but I personally like having these commands in the script, anyway. You may have better results with some experimentation.

THE vlccontrol.py SCRIPT:

  1. !/usr/bin/env python
        1. licensing nonsense - short version: New BSD License
  2. Copyright (c) 2010, Derek Barnett, Skyehaven Transcription
  3. Contact: derek@skyehaven.net
  4. All rights reserved.
  5. Redistribution and use in source and binary forms, with or
  6. without modification, are permitted provided that the following
  7. conditions are met:
  8. * Redistributions of source code must retain the above
  9. copyright notice, this list of conditions and the following
  10. disclaimer.
  11. * Redistributions in binary form must reproduce the above
  12. copyright notice, this list of conditions and the following
  13. disclaimer in the documentation and/or other materials provided
  14. with the distribution.
  15. * Neither the name of the Skyehaven Transcription nor the
  16. names of its contributors may be used to endorse or promote
  17. products derived from this software without specific prior
  18. written permission.
  19. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  20. CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  21. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  22. MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  23. DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  24. CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  25. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  26. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  27. USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  28. AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  29. LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  30. IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  31. THE POSSIBILITY OF SUCH DAMAGE.
          1. useful notes
  32. vlc control script, compatible with python 2 or 3
  33. this script requires the openbsd version of netcat. gnu's version
  34. does not appear to support unix sockets as of this time. it will
  35. almost certainly be in the repos of your distribution. you may need
  36. to adjust this script to change the name of the binary to whatever
  37. format your distribution uses (change 'nc.openbsd' below to whatever
  38. you need.)
  39. it also requires either xautomation (for it's xte tool) or xdotool
  40. xautomation is used by default, as it's currently a bit faster
  41. if you use xdotool, ensure that it's a version later than aug 2010
  42. to set up vlc to use this script, go to tools->preferences and
  43. click on "show settings->all" at the bottom. from that menu,
  44. select "Interface->Main Interfaces", and check the "Remote Control
  45. Interface" box. Next, select "Interface->Main Interfaces->RC",
  46. check the "Fake TTY' box, and enter 'home/YOURNAME/vlc.sock'in
  47. the "UNIX socket command input" field.
  48. You probably also want to adjust the "Very short jump length" located
  49. in "Interface->Hotkeys settings". This script assumes that it is set
  50. for 5 seconds rather than the default of 3 seconds. It won't affect the
  51. script if you don't change this value, as it uses the 'very short jump'
  52. command rather than jogging a specific number of seconds. If you poke
  53. around the vlc docs, you'll see a seek command, but that is to go to a
  54. certain point in a file rather than going forward or backward a certain
  55. number of seconds.
  56. Hit "Save". Restart VLC, and check to see if it creates "vlc.sock"
  57. in your home directory. This should be created automatically when vlc
  58. starts. If it doesn't, check your socket path and try again.
  59. Next, you need to set up your hotkeys for your window environment.
  60. This should work equally well in any window manger, so pick whichever
  61. you like. Remember to check to make sure that whichever hotkeys you wish
  62. to use are not already used by your windowmanager. Redefine these
  63. hotkeys or the defaults as necessary.
  64. note: vlc supposedly support global hotkeys, but I didn't have any luck
  65. with them, which is why i went this route with the control script. Your
  66. mileage may vary.
  67. I personally set it up like this:
  68. F1 = ~/vlccontrol.py jogbackward
  69. F2 = ~/vlccontrol.py pause (no need to have this twice, just habit)
  70. F3 = ~/vlccontrol.py pause
  71. F4 = ~/vlccontrol.py jogforward
  72. F5 = ~/vlccontrol.py timestamp
  73. Shift+F1 = ~/vlccontrol.py slower
  74. Shift+F3 = ~/vlccontrol.py normal
  75. Shift+F4 = ~/vlccontrol.py faster
          1. end of rambling, on to business

import sys import os

  1. feed command to vlc socket to get the time played in seconds

workingdir = os.path.join(os.path.expanduser('~')) vlcin = os.path.join(workingdir,'vlc.sock') vlcout = os.path.join(workingdir,'vlc.out')

  1. accept argument when running script, e.g. './vlctimestamp.py timestamp'

args = sys.argv[1:] i = "normal" if args:

   i = str.lower(args[0])
  1. acceptable arguments: help, --help, pause, jogforward, +5, jogbackward, -5,
  2. faster, slower, normal, timestamp. no argument assumes 'normal'

if i == "help" or i == "-help" or i == "--help":

   print("""
            'help' or '--help' returns this help
            'pause' is a play/pause toggle
            'jogforward' or '+5' jumps forward 5 seconds
            'jogbackward' or '-5' jumps backward 5 seconds
            'faster' increases the tempo without increasing pitch
            'slower' decreases the tempo without decreasing pitch
             no argument or 'normal' returns vlc to normal speed
             'timestamp' types a hh:mm:ss coded timestamp into 
                         active window. see comments within this
                         script if you need to change the timestamp
                         string, offset the timestamp for a video
                         timecode, or if you've made tempo changes
                         in an audio file outside of vlc
            """)

elif i == "jogforward" or i == "+5":

   os.system('echo "key key-jump+extrashort" | nc.openbsd -U ' + vlcin)

elif i == "jogbackward" or i == "-5":

   os.system('echo "key key-jump-extrashort" | nc.openbsd -U ' + vlcin)

elif i == "pause":

   os.system('echo "pause" | nc.openbsd -U ' + vlcin)

elif i == "faster":

   os.system('echo "key key-rate-faster-fine" | nc.openbsd -U ' + vlcin)

elif i == "slower":

   os.system('echo "key key-rate-slower-fine" | nc.openbsd -U ' + vlcin)

elif i == "normal":

   os.system('echo "normal" | nc.openbsd -U ' + vlcin)

elif i == "timestamp":

   os.system('echo "get_time" | nc.openbsd -U ' + vlcin + ' > ' + vlcout)
   #read vlc.out and report time played in seconds
   f = open(vlcout, 'r')
   f_list = f.read().split("\n")
   if len(f_list) > 2:
       sec = f_list[1]
   else:
       sec = f_list[0]
   sec = int(sec)
   #tempo - if you've adjusted the tempo and an audio file, in 
   #        audacity for instance, then you can use the tempo
   #        variable to give output for a timestamp postion in 
   #        original file. tempo is the percent playback speed
   #        of the modified file. 80 = -20% tempo change, etc.
   #        default is 100
   tempo = 100
   #change offsetneeded to True if, for instance, you need to 
   #use a timecode embedded into a video rather than the playtime
   #of the file
   offset = 0
   offsetneeded = False
   if offsetneeded == True:
   #Pick a spot on the video and pause it. Enter the appropriate values below:
   #vtch = hours on video time code, vtcm = minutes, vtcs = seconds
       vtch = 0
       vtcm = 0
       vtcs = 0
       vtc = (vtch * 3600) + (vtcm * 60) + vtcs
   #atch = hours in actual playtime, atcm = minutes, 
   #atcs = seconds            
       atch = 0
       atcm = 0
       atcs = 0
       atc = ((((atch * 3600) + (atcm * 60) + atcs) * tempo) / 100)
       offset = vtc - atc
   #get the values for hh:mm:ss formatting
   sec = ((sec * tempo) / 100) + offset
   th = sec/3600
   tm = (sec % 3600)/60
   ts = sec % 60
   #format the timestamp, default looks like '##Inaudible 00:01:10## '
   #the timestamp in hours:minutes:seconds                    
   t = "%02d:%02d:%02d" % (th,tm,ts)    
   #string to append before timestamp
   #for no prefix, set prefix = ""
   prefix = "##Inaudible "
   #string to append after timestamp
   #for no suffix, set suffix = ""
   suffix = "## "                           
   #xdotool requires a version later created than august 2010
   #    
   #xdotool command to execute, uncomment next line to use xdotool
   #dropstamp = str("xdotool type --delay 0 --clearmodifiers '" + prefix + t + suffix + "'")
   #    
   #drop the timestamp string into active window, uncomment next line to use xdotool
   #os.system(dropstamp)
   #        
   #use xte from the xautomation package if you don't have a version of 
   #xdotool newer than august 2010
   os.system('xte "str ' + prefix + t + suffix + '"')       
  1. if we don't feed an argument to the script, normalize the play speed of vlc

else:

   os.system('echo "normal" | nc.openbsd -U ' + vlcin)