ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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
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.
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.
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!
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()
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()
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.