[MPlayer-users] slightly offtopic -- editing ?!
Martin Collins
martin at mkcollins.org
Fri Dec 20 02:40:03 CET 2002
On Fri, 20 Dec 2002 01:32:18 +0200
Francois Botha <fbotha at spyder.web.za> wrote:
> I'm perfectly happilly using mencoder to encode some stuff from my
> 'ol bt848 card but wondering what Linux tools you all use for simple
> cut & paste'ing afterwards?
I wrote a python script which uses mencoder for simple editing. You
create an editlist by hand by playing the source avi with mplayer and
noting the start and end times of each section you want to keep from
the terminal output of mplayer. An editlist looks like this:
infile.avi
outfile.avi
0.0 33.2
45.9 73.6
Here's the script:
----<cut here>----
#!/usr/bin/python
#
# A simple video editor using mencoder
import sys, os, string, fnmatch
start = 0
end = 1
def read_edlist(edlist_file):
edlist = []
data = open(edlist_file, 'r').read().splitlines()
i = 0
for line in data:
if i == 0:
infile = line
elif i == 1:
outfile = line
else:
beginning, offset = line.split()
edit = (beginning, repr(float(offset)-float(beginning)))
edlist.append(edit)
i += 1
return infile, outfile, edlist
def edit(infile, edlist):
i = 0
for edit in edlist:
tmpfile = infile[:infile.rfind(".")] + string.zfill(i, 3) + '.tmp'
args = ('mencoder','-oac','copy','-ovc','copy','-ss',edit[start],'-endpos',edit[end],'-o',tmpfile,infile)
os.spawnvp(os.P_WAIT, 'mencoder', args)
i += 1
def finalize(infile, outfile):
tmpfile = outfile[:outfile.rfind(".")] + '.tmp'
for file in os.listdir(os.getcwd()):
if fnmatch.fnmatch(file, infile[:infile.rfind(".")] + '*.tmp'):
os.popen('cat ' + file + '>>' + tmpfile)
os.popen('rm ' + file)
args = ('mencoder', '-oac', 'copy', '-ovc', 'copy', '-o', outfile, '-forceidx', tmpfile)
os.spawnvp(os.P_WAIT, 'mencoder', args)
os.popen('rm ' + tmpfile)
if __name__ == '__main__':
if len(sys.argv) != 2:
print "Usage: medit edlist"
print "where edlist is a text file containing the input filename on the first line,"
print "the output filename on the second line and each subsequent line has a start"
print "offset and an end offset into the input file separated by a space."
print "The offsets should be in seconds."
else:
infile, outfile, edlist = read_edlist(sys.argv[1])
edit(infile, edlist)
finalize(infile, outfile)
-----<cut here>----
Watch out for wrapped lines and remember that in Python the
indentation of lines is significant.
Martin
More information about the MPlayer-users
mailing list