예제 #1
0
#
tmp_fldr = tempfile.mkdtemp()
print("Using '%s' for storing temporary files" % tmp_fldr)

fnt = ImageFont.truetype(FONT_FILE, FONT_SZ)


# --------------------------------------------------------------------------
# Read the video file and extract frames to multiple jpg files
#
vid_file = pyvideomeg.VideoData(sys.argv[1])

for i in range(len(vid_file.ts)):
    img = Image.open(StringIO.StringIO(vid_file.get_frame(i)))
    draw = ImageDraw.Draw(img)
    draw.text((10, 0), "%i  :  %s" % (vid_file.ts[i], pyvideomeg.ts2str(vid_file.ts[i])), font=fnt, fill="black")
    img.save("%s/%08i.jpg" % (tmp_fldr, i))


# --------------------------------------------------------------------------
# If no audio file, encode and exit
#
if len(sys.argv) == 3:
    print("No audio file is specified, using only the video")
    fps = len(vid_file.ts) / (float(vid_file.ts[-1] - vid_file.ts[0]) / 1000)
    print("FPS: %f" % fps)
    vid_opts = "mf://%s/*.jpg -mf type=jpg:fps=%f" % (tmp_fldr, fps)
    cmd = "mencoder %s -ovc lavc -lavcopts vcodec=msmpeg4v2 -nosound -o %s > %s" % (
        vid_opts,
        sys.argv[2],
        MENCODER_LOG_FILE,
예제 #2
0
    i += 1

fnt = ImageFont.truetype(FONT_FILE, FONT_SZ)

indx = []
err = []
first_i = i
while i < len(vid_file_1.ts):
    indx.append(numpy.argmin(abs(vid_file_1.ts[i] - vid_file_2.ts)))
    err.append(vid_file_1.ts[i] - vid_file_2.ts[indx[-1]])
    
    img1 = Image.open(StringIO.StringIO(vid_file_1.get_frame(i)))
    img2 = Image.open(StringIO.StringIO(vid_file_2.get_frame(indx[-1])))
    
    draw = ImageDraw.Draw(img1)
    draw.text((10,0), '%i  :  %s' % (vid_file_1.ts[i], pyvideomeg.ts2str(vid_file_1.ts[i])), font=fnt, fill='black')
    
    draw = ImageDraw.Draw(img2)
    draw.text((10,0), '%i' % err[-1], font=fnt, fill='black')
    
    out_image = Image.new("RGB", (2*img1.size[0],img1.size[1]))
    out_image.paste(img1, (0,0))
    out_image.paste(img2, (img1.size[0],0))
    out_image.save('%s/%08i.jpg' % (tmp_fldr, i))

    i += 1
    
    # if reached the end of the second file, stop
    if indx[-1] == len(vid_file_2.ts)-1:
        break
    
예제 #3
0
        sys.exit(1)
        
if is_audio:
    nsamples = len(af.raw_audio) / af.nchan / 2
    wc_srate = (nsamples - (af.buf_sz/2/af.nchan)) * 1000. / (af.ts[-1] - af.ts[0])
    
    print('\n\n\n')
    print('Audio file.')
    print('\tVersion: %i' % af.ver)
    print('\tNominal sampling rate: %i' % af.srate)
    print('\tWall clock sampling rate: %f' % wc_srate)
    print('\tNumber of channels: %i' % af.nchan)
    print('\tNumber of samples: %i' % nsamples)
    print('\tTotal duration (estimated): %f seconds' % (nsamples / wc_srate))
    print('\tBuffer size: %i frames' % (af.buf_sz / 2 / af.nchan))
    print('\tFirst buffer time: %s' % pyvideomeg.ts2str(af.ts[0]))
    print('\tLast buffer time: %s' % pyvideomeg.ts2str(af.ts[-1]))
    
    if af.ver == 3:
        print('\tSite ID: %i' % af.site_id)
        
        if af.is_sender:
            print('\tThe file was recorded by the *sender* process')
        else:
            print('\tThe file was recorded by the *receiver* process')
    
    del(af)

else:
    fps = (len(vf.ts)-1) * 1000. / (vf.ts[-1] - vf.ts[0])
예제 #4
0
if is_audio:
    nsamples = len(af.raw_audio) / af.nchan / 2
    wc_srate = (nsamples -
                (af.buf_sz / 2 / af.nchan)) * 1000. / (af.ts[-1] - af.ts[0])

    print('\n\n\n')
    print('Audio file.')
    print('\tVersion: %i' % af.ver)
    print('\tNominal sampling rate: %i' % af.srate)
    print('\tWall clock sampling rate: %f' % wc_srate)
    print('\tNumber of channels: %i' % af.nchan)
    print('\tNumber of samples: %i' % nsamples)
    print('\tTotal duration (estimated): %f seconds' % (nsamples / wc_srate))
    print('\tBuffer size: %i frames' % (af.buf_sz / 2 / af.nchan))
    print('\tFirst buffer time: %s' % pyvideomeg.ts2str(af.ts[0]))
    print('\tLast buffer time: %s' % pyvideomeg.ts2str(af.ts[-1]))

    if af.ver == 3:
        print('\tSite ID: %i' % af.site_id)

        if af.is_sender:
            print('\tThe file was recorded by the *sender* process')
        else:
            print('\tThe file was recorded by the *receiver* process')

    del (af)

else:
    fps = (len(vf.ts) - 1) * 1000. / (vf.ts[-1] - vf.ts[0])
예제 #5
0
tmp_fldr = tempfile.mkdtemp()
print('Using \'%s\' for storing temporary files' % tmp_fldr)

fnt = ImageFont.truetype(FONT_FILE, FONT_SZ)

#--------------------------------------------------------------------------
# Read the video file and extract frames to multiple jpg files
#
vid_file = pyvideomeg.VideoData(sys.argv[1])

for i in range(len(vid_file.ts)):
    img = Image.open(BytesIO(vid_file.get_frame(i)))
    draw = ImageDraw.Draw(img)
    draw.text(
        (10, 0),
        '%i  :  %s' % (vid_file.ts[i], pyvideomeg.ts2str(vid_file.ts[i])),
        font=fnt,
        fill='black')
    img.save('%s/%08i.jpg' % (tmp_fldr, i))

#--------------------------------------------------------------------------
# If no audio file, encode and exit
#
if len(sys.argv) == 3:
    print('No audio file is specified, using only the video')
    fps = len(vid_file.ts) / (float(vid_file.ts[-1] - vid_file.ts[0]) / 1000)
    print('FPS: %f' % fps)
    vid_opts = 'mf://%s/*.jpg -mf type=jpg:fps=%f' % (tmp_fldr, fps)
    cmd = 'mencoder %s -ovc lavc -lavcopts vcodec=msmpeg4v2 -nosound -o %s > %s' % (
        vid_opts, sys.argv[2], MENCODER_LOG_FILE)
예제 #6
0
    i += 1

fnt = ImageFont.truetype(FONT_FILE, FONT_SZ)

indx = []
err = []
first_i = i
while i < len(vid_file_1.ts):
    indx.append(numpy.argmin(abs(vid_file_1.ts[i] - vid_file_2.ts)))
    err.append(vid_file_1.ts[i] - vid_file_2.ts[indx[-1]])
    
    img1 = Image.open(BytesIO(vid_file_1.get_frame(i)))
    img2 = Image.open(BytesIO(vid_file_2.get_frame(indx[-1])))
    
    draw = ImageDraw.Draw(img1)
    draw.text((10,0), '%i  :  %s' % (vid_file_1.ts[i], pyvideomeg.ts2str(vid_file_1.ts[i])), font=fnt, fill='black')
    
    draw = ImageDraw.Draw(img2)
    draw.text((10,0), '%i' % err[-1], font=fnt, fill='black')
    
    out_image = Image.new("RGB", (2*img1.size[0],img1.size[1]))
    out_image.paste(img1, (0,0))
    out_image.paste(img2, (img1.size[0],0))
    out_image.save('%s/%08i.jpg' % (tmp_fldr, i))

    i += 1
    
    # if reached the end of the second file, stop
    if indx[-1] == len(vid_file_2.ts)-1:
        break