[MPlayer-users] More newbie questions
Martin Collins
martin at mkcollins.org
Fri Mar 28 12:38:56 CET 2003
On 27 Mar 2003 15:09:59 -0500
Yan Seiner <yan at cardinalengineering.com> wrote:
> I can't find a tool that can clip mjpegs or mpeg4...
>
> I've tried kino (just random noise or segfault) and mjpeg tools (I
> get very pretty horizontal rainbow lines.)
In my experience mplayer cannot reliably read or write mjpegs that are
compatible with mjpegtools. I reported this to the ffmpeg list and
Alex said he was working on it but to be patient. This was about three
months ago :-(
In the meantime I wrote a simple editor in python that uses mplayer and
mencoder and works reasonably well with mjpegs. You have to view your
video in mplayer and create an editlist by hand from the timestamps
displayed in the terminal. I include it below. Watch out for line wrap
and remember that indentation is significant in python.
Martin
#!/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 and 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)
More information about the MPlayer-users
mailing list