LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-30-2005, 12:23 PM   #1
shanenin
Member
 
Registered: Aug 2003
Location: Rochester, MN, U.S.A
Distribution: Gentoo
Posts: 987

Rep: Reputation: 30
need video dimensions


I wrote a little program(in python) that makes a mplayer.movie.conf file. this file tells mplayer a specified amount to crop that movie. My program depends of the data widthxheight of the original movie. I am currently useing the program avitype to get this info. The limitation to this method is it only works on avi files not .mp4(I think quictime) files.

I think i could use mplayer somehow to get this data. for example when mplayer plays a mp4 file it gives this output
Code:
MOV: longest streams: A: #3 (274000 samples)  V: #2 (140148 samples)
VIDEO:  [mp4v]  704x368  0bpp  23.976 fps    0.0 kbps ( 0.0 kbyte/s)
==========================================================================
my needed data, 704x368, is being produced, but I have no way of getting it.

I have tried
Code:
mplayer movie.mp4 > file
this does not work well because this file keeps getting ammended until the movie ends.

If their was an option like this it would be great
Code:
mplayer --info_only movie.mp4
is there a way using mplayer, or any other lib or program to get the dimensions of an .mp4 file.

I would prefer to do this with python, but may be able to use a c extensible module, or just a program like avitype.


edit added later//

I have thought about using pymedia, but can't get it to build

Last edited by shanenin; 08-30-2005 at 12:43 PM.
 
Old 08-30-2005, 02:53 PM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
Quote:
If their was an option like this it would be great
There IS one... did you read the manpage?? this is exactly what i do in my acidrip program to source info from non-dvd sources. just use "-identify -frames 0" to show verbose info about the file and continue to play the grand total of 0 frames from it, then quit.
 
Old 08-30-2005, 02:57 PM   #3
shanenin
Member
 
Registered: Aug 2003
Location: Rochester, MN, U.S.A
Distribution: Gentoo
Posts: 987

Original Poster
Rep: Reputation: 30
I read it, that man page is a monster. Thanks for the help :-)


this leads me to an other question. Is there an app that will allow you to search through man pages by keyword? (I have not googled for this answer yet)

i have tryed
Code:
man somthing > file
then used different tools to search throuhg the file, but this dos not do a real good job.

Last edited by shanenin; 08-30-2005 at 03:07 PM.
 
Old 08-30-2005, 02:59 PM   #4
shanenin
Member
 
Registered: Aug 2003
Location: Rochester, MN, U.S.A
Distribution: Gentoo
Posts: 987

Original Poster
Rep: Reputation: 30
wow that works beautifully, I do not even really have to do much to parse the info out :-)

Last edited by shanenin; 08-30-2005 at 03:25 PM.
 
Old 08-31-2005, 07:19 AM   #5
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
an app? How about man? the less pager in it responds to basic vi commands. load the manpage and try typing "/identify". press n to cycle through results. To be honest i've been using linux daily for about 5 years now. I only found this out about 6 months ago!
 
Old 08-31-2005, 11:45 AM   #6
shanenin
Member
 
Registered: Aug 2003
Location: Rochester, MN, U.S.A
Distribution: Gentoo
Posts: 987

Original Poster
Rep: Reputation: 30
I have a linux system(freevo) connected to my tv. I like to crop some of the wider screen movies to fill more of my tv screen. This little script will make an mplayer.conf file for individual movies, or whole directorys. Maybe someone may find it useful
Code:
#!/usr/bin/env python
#
# cropit-0.2
#
# 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 -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):

    base_dir = os.getcwd()
    conf_name = "%s/%s.conf" % (base_dir, 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()


def main():
    
    options = get_opts(sys.argv[1:])
    
    for i in options[1]:
        dimensions = getdimensions(i)
        make_conf(i, dimensions, options[0])

main()
 
Old 11-21-2005, 06:54 PM   #7
shanenin
Member
 
Registered: Aug 2003
Location: Rochester, MN, U.S.A
Distribution: Gentoo
Posts: 987

Original Poster
Rep: Reputation: 30
I made a couple of changes to the original. There was a bug I never noticed before. If you used the absolute path instead of the relative path, it would error out, which in now fixed. Before you were unable to run the program remotely using ssh. I think that was because the program depends on mplayer, since I do not have x11 forwarding it would freeze up at the mplayer command. I changed the video output to this, it seemed to solve the problem
Code:
mplayer -vo null
here is the revised version

Code:
#!/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()
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
aspect ratios dimensions, not adding up shanenin Linux - Software 1 08-01-2005 03:15 PM
Coldfusion - getting image dimensions Locura Programming 2 02-15-2005 04:52 PM
Saving Konqueror's dimensions in KDE iliks Linux - Software 2 07-03-2004 12:20 AM
Java arrays and dimensions pycoucou Programming 5 04-07-2004 01:59 PM
terminal dimensions and lilo nautilus_1987 Linux - General 1 10-22-2003 01:20 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:43 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration