freevo uses python

Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: May 2005
Posts: 215
Reputation: shanenin is an unknown quantity at this point 
Solved Threads: 16
shanenin shanenin is offline Offline
Posting Whiz in Training

freevo uses python

 
0
  #1
Nov 28th, 2005
I am not sure if any of you use a pvr. Linux offers some good choices. One of the choices is freevo, it is fully implemented in python. Of cource it uses tools like mplayer(video player) and others that are written in c/c++ .

I wrote python script that makes a config file that mplayer uses to crop movies. I like to make my widescreen avi fill a little more of the screen. I used to have to do this manually, usually using ssh, because these pvrs are not connected to the moniter(just a tv).

I just found a simple doc that allows you to integrate commands into the freevo interface. Now I am able to crop movies using the freevo interface.
http://freevo.sourceforge.net/cgi-bi...DevelopPlugins


I guess I posted this to tell the ease of ANYONE contruting to the freevo project in the form of plugins. I may clean up the code and submit it to be used. It would be a good feeling if someone else used my code :-)

this is the code for the command line application cropit
  1. #!/usr/bin/env python
  2. #
  3. # cropit-0.2.1
  4. #
  5. # author shane lindberg
  6. #
  7. import os, sys, getopt, commands
  8.  
  9.  
  10. # this function gets the command options
  11. def get_opts(argv):
  12.  
  13. crop = '81'
  14. try:
  15. opts, args = getopt.getopt(argv, "hc:", ["help", "crop="])
  16. except getopt.GetoptError:
  17. usage()
  18. sys.exit(2)
  19.  
  20. for opt, arg in opts:
  21. if opt in ("-h", "--help"):
  22. usage()
  23. sys.exit()
  24. elif opt in ("-c", "--crop"):
  25. crop = arg
  26.  
  27. return (crop, args)
  28.  
  29.  
  30. # this function gives a usage(help) message. This is either called be the user makeing an invalid
  31. # option choice, or by choosing the -h or --help option
  32. def usage():
  33.  
  34. print """\n
  35. Usage: cropit [OPTION]... [FILE]...
  36.  
  37. Options available to cropit
  38.  
  39. -h, --help shows options available to cropit .
  40.  
  41. -c, --crop tells how much to crop the width of you avi file. The number
  42. given is a percentage of the original, ex. -c 85 will crop
  43. the width to 85% of the original. -c 100 will crop it to
  44. 100% of the original, which means no crop. The smaller the
  45. number the larger the crop. The default crop is -c 81, or
  46. 81%. A typical range of 75 to 90 is prefered for most files.\n\n\n """
  47.  
  48.  
  49. # this python function gets the dimensions of a video file and returns them as a tuple (width,height)
  50. def getdimensions(v_video_file):
  51.  
  52. avitype_command= '/usr/bin/mplayer -vo null -identify -frames 0 "%s"' % v_video_file
  53. output = commands.getoutput(avitype_command)
  54. split = output.splitlines()
  55. for i in split:
  56. if i.startswith('ID_VIDEO_WIDTH='):
  57. width = int(i.replace('ID_VIDEO_WIDTH=',''))
  58. if i.startswith('ID_VIDEO_HEIGHT='):
  59. height = int(i.replace('ID_VIDEO_HEIGHT=',''))
  60. return (width, height)
  61.  
  62. # this function makes the movie.avi.conf file
  63. def make_conf(v_video_file, v_dimensions, v_user_crop):
  64.  
  65. conf_name = "%s.conf" % (v_video_file)
  66. width = v_dimensions[0]
  67. height = v_dimensions[1]
  68. cropped_width = int(float(v_user_crop)/100*width)
  69. conf_file = open(conf_name, "w")
  70. conf_file.write("vf=crop=%s:%s\n" %(cropped_width, height))
  71. conf_file.close()
  72. print os.path.abspath(conf_name)
  73. def main():
  74.  
  75. options = get_opts(sys.argv[1:])
  76.  
  77. for i in options[1]:
  78. if i.endswith('.avi') or i.endswith('.mp4'):
  79. dimensions = getdimensions(i)
  80. make_conf(i, dimensions, options[0])
  81.  
  82. main()

then this is the plugin that allows integration into the freevo gui inteface. As of now it is hardcoded to my script location , but that can be fixed
  1. #!/usr/bin/env python
  2. #
  3. # this is my first attempt to make a freevo plugin
  4.  
  5. import os
  6. import time
  7. import plugin
  8. from gui.PopupBox import PopupBox
  9.  
  10. class PluginInterface(plugin.ItemPlugin):
  11. """
  12. This plugin is to enable the program 'cropit' to be integrated into
  13. the freevo interface. the cropit program creates an mplayer config
  14. file that tells mplayer to crop the avi file
  15.  
  16. If you want to activate it add this line to your
  17. local config
  18. plugin.activate('video.cropit')
  19. """
  20. def __init__(self):
  21. plugin.ItemPlugin.__init__(self)
  22.  
  23. def actions(self, item):
  24. self.item = item
  25. if item.mode == 'file' and os.path.isfile('%s.conf'%item.filename) != True:
  26. return [ (self.cropit_normal, 'crop an average amount'),
  27. (self.cropit_small, 'crop a small amount'),
  28. (self.cropit_large, 'crop a large amount') ]
  29. elif item.mode == 'file' and os.path.isfile('%s.conf'%item.filename) == True:
  30. return [ (self.cropit_remove, 'remove the cropit config file') ]
  31. else:
  32. return []
  33.  
  34. def cropit_normal(self,arg=None, menuw=None):
  35. box = PopupBox(text=_('creating conf file...'))
  36. box.show()
  37. os.system('/root/bin/cropit %s'%self.item.filename)
  38. time.sleep(2)
  39. box.destroy()
  40. menuw.delete_menu(arg, menuw)
  41.  
  42. def cropit_small(self,arg=None, menuw=None):
  43. box = PopupBox(text=_('creating conf file...'))
  44. box.show()
  45. os.system('/root/bin/cropit -c 87 %s'%self.item.filename)
  46. time.sleep(2)
  47. box.destroy()
  48. menuw.delete_menu(arg, menuw)
  49.  
  50. def cropit_large(self,arg=None, menuw=None):
  51. box = PopupBox(text=_('creating conf file...'))
  52. box.show()
  53. os.system('/root/bin/cropit -c 75 %s'%self.item.filename)
  54. time.sleep(2)
  55. box.destroy()
  56. menuw.delete_menu(arg, menuw)
  57.  
  58. def cropit_remove(self,arg=None, menuw=None):
  59. box = PopupBox(text=_('deleteing conf file...'))
  60. box.show()
  61. os.system('rm -f %s.conf'%self.item.filename)
  62. time.sleep(2)
  63. box.destroy()
  64. menuw.delete_menu(arg, menuw)

alot of the above code was copied form the example, but I added quite abit
In a perfect world exceptions would not be needed.
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 4,047
Reputation: vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice 
Solved Threads: 935
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite

Re: freevo uses python

 
0
  #2
Dec 2nd, 2005
Freevo is only for Linux, can't get GTK to go on Windows, I feel like I am drowning in a Microsoft induced quagmire!

Did anybody ever look at IronPython (Python for .NET)? Am I off, or is this nothing but a crock of dung?

Me in a bad mood? Heck no, just a little frustrated with Windows stuff!
May 'the Google' be with you!
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 215
Reputation: shanenin is an unknown quantity at this point 
Solved Threads: 16
shanenin shanenin is offline Offline
Posting Whiz in Training

Re: freevo uses python

 
0
  #3
Dec 3rd, 2005
Originally Posted by vegaseat
Freevo is only for Linux, can't get GTK to go on Windows, I feel like I am drowning in a Microsoft induced quagmire!

Did anybody ever look at IronPython (Python for .NET)? Am I off, or is this nothing but a crock of dung?

Me in a bad mood? Heck no, just a little frustrated with Windows stuff!
You could always dual boot linux with windows. We have bothe linux and windows computers in our house, it is nice to be able to use bothe operating systems.

I am curious about .net, I am not really sure what it does, or what it is. Is it kind of a programming language, or more a way to help various programmig languages interact with the windows OS?
In a perfect world exceptions would not be needed.
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 4,047
Reputation: vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice 
Solved Threads: 935
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite

Re: freevo uses python

 
0
  #4
Dec 3rd, 2005
.NET is the common platform for all Microsoft languages and I guess programs. In a sense it could be a good idea, but it can also put you into a straight jacket that "upgrade Bill" can abuse. On my small computer .NET has a gigantic overhead (I have version 1.1 and 2.0 running), but the programs compiled in .NET have a small footprint to make up for it. I like it for C# and Boo programming. There is an effort on the way to do something similar in open source Linux called Mono.
May 'the Google' be with you!
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC