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-bin/doc/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

#!/usr/bin/env python
#
# cropit-0.2.1
#
# author shane lindberg
#
import os, sys, getopt, commands


# this function gets the command options
def get_opts(argv):

    crop = '81'
    try:
        opts, args = getopt.getopt(argv, "hc:", ["help", "crop="])
    except getopt.GetoptError:
        usage()
        sys.exit(2)

    for opt, arg in opts:
        if opt in ("-h", "--help"):
            usage()
            sys.exit()
        elif opt in ("-c", "--crop"):
            crop = arg

    return (crop, args)


# this function gives a usage(help) message. This is either called be the user makeing an invalid
# option choice, or by choosing the -h or --help option
def usage():

    print """\n
Usage: cropit [OPTION]... [FILE]...

Options available to cropit

-h, --help         shows options available to cropit .

-c, --crop         tells how much to crop the width of you avi file. The number
                   given is a percentage of the original, ex. -c 85 will crop
                   the width to 85% of the original. -c 100 will crop it to
                   100% of the original, which means no crop. The smaller the
                   number the larger the crop. The default crop is -c 81, or
                   81%. A typical range of 75 to 90 is prefered for most files.\n\n\n """


# this python function gets the dimensions of a video file and returns them as a tuple (width,height)
def getdimensions(v_video_file):

    avitype_command= '/usr/bin/mplayer -vo null -identify -frames 0 "%s"' % v_video_file
    output = commands.getoutput(avitype_command)
    split = output.splitlines()
    for i in split:
        if i.startswith('ID_VIDEO_WIDTH='):
            width = int(i.replace('ID_VIDEO_WIDTH=',''))
        if i.startswith('ID_VIDEO_HEIGHT='):
            height = int(i.replace('ID_VIDEO_HEIGHT=',''))
    return (width, height)

# this function makes the movie.avi.conf file
def make_conf(v_video_file, v_dimensions, v_user_crop):

    conf_name = "%s.conf" % (v_video_file)
    width = v_dimensions[0]
    height = v_dimensions[1]
    cropped_width = int(float(v_user_crop)/100*width)
    conf_file = open(conf_name, "w")
    conf_file.write("vf=crop=%s:%s\n" %(cropped_width, height))
    conf_file.close()
    print os.path.abspath(conf_name)
def main():

    options = get_opts(sys.argv[1:])

    for i in options[1]:
        if i.endswith('.avi') or i.endswith('.mp4'):
            dimensions = getdimensions(i)
            make_conf(i, dimensions, options[0])

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

#!/usr/bin/env python
#
# this is my first attempt to make a freevo plugin

import os
import time
import plugin
from gui.PopupBox import PopupBox

class PluginInterface(plugin.ItemPlugin):
    """
    This plugin is to enable the program 'cropit' to be integrated into
    the freevo interface. the cropit program creates an mplayer config
    file that tells mplayer to crop the avi file

    If you want to activate it add this line to your
    local config
    plugin.activate('video.cropit')
    """
    def __init__(self):
        plugin.ItemPlugin.__init__(self)

    def actions(self, item):
        self.item = item
        if item.mode == 'file' and os.path.isfile('%s.conf'%item.filename) != True:
            return [ (self.cropit_normal, 'crop an average amount'),
                           (self.cropit_small, 'crop a small amount'),
                           (self.cropit_large, 'crop a large amount') ]
        elif item.mode == 'file' and os.path.isfile('%s.conf'%item.filename) == True:
            return [ (self.cropit_remove, 'remove the cropit config file') ]
        else:
            return []

    def cropit_normal(self,arg=None, menuw=None):
        box = PopupBox(text=_('creating conf file...'))
        box.show()
        os.system('/root/bin/cropit %s'%self.item.filename)
        time.sleep(2)
        box.destroy()
        menuw.delete_menu(arg, menuw)

    def cropit_small(self,arg=None, menuw=None):
        box = PopupBox(text=_('creating conf file...'))
        box.show()
        os.system('/root/bin/cropit -c 87 %s'%self.item.filename)
        time.sleep(2)
        box.destroy()
        menuw.delete_menu(arg, menuw)

    def cropit_large(self,arg=None, menuw=None):
        box = PopupBox(text=_('creating conf file...'))
        box.show()
        os.system('/root/bin/cropit -c 75 %s'%self.item.filename)
        time.sleep(2)
        box.destroy()
        menuw.delete_menu(arg, menuw)

    def cropit_remove(self,arg=None, menuw=None):
        box = PopupBox(text=_('deleteing conf file...'))
        box.show()
        os.system('rm -f %s.conf'%self.item.filename)
        time.sleep(2)
        box.destroy()
        menuw.delete_menu(arg, menuw)

alot of the above code was copied form the example, but I added quite abit

Recommended Answers

All 3 Replies

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!

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?

.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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.