[MPlayer-users] mencoder: question N2
James Lancaster
james at kirk.math.twsu.edu
Fri Jan 10 04:13:20 CET 2003
On Thursday 09 January 2003 21:18, you wrote:
> [Automatic answer: RTFM (read DOCS, FAQ), also read DOCS/bugreports.html]
> Dear Sirs,
>
> how can I combine two files into one using mencoder ?
> (I want to cut the commercial, so, I first split file into parts and then
> I will combine all the parts together without any commercial)
>
It is possible. Someone posted a python script which is nice
It uses files where the video you want is specified in seconds each line
after the first two (which are source and destination files)
example (from -rencoded):
episode09-rencoded.avi
episode09-edited.avi
0 379.4
593.0 1291.6
1515.0 1850.0
2083.3 2442.7
2662.3 3047.6
3201.1 3614.3
original message, dated: Fri, 20 Dec 2002 01:03:13 +0000
> 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
> Regards, (Наилучшие пожелания)
> Ilia Chipitsine (Илья Шипицин)
>
>
> _______________________________________________
> RTFM!!! http://www.MPlayerHQ.hu/DOCS
> Search: http://www.MPlayerHQ.hu/cgi-bin/htsearch
> http://mplayerhq.hu/mailman/listinfo/mplayer-users
More information about the MPlayer-users
mailing list