Skip to content

Commit

Permalink
add 'ms' and 'ms_per_frame' to vp9
Browse files Browse the repository at this point in the history
git-svn-id: https://xpra.org/svn/Xpra/trunk@10387 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed Aug 21, 2015
1 parent 3fd123e commit 0eb6b06
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/xpra/codecs/enc_x264/encoder.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ cdef class Encoder:
info["total_time_ms"] = int(self.time*1000.0)
info["pixels_per_second"] = int(pps)
#calculate fps:
cdef int f = 0
cdef unsigned int f = 0
cdef double now = time.time()
cdef double last_time = now
cdef double cut_off = now-10.0
Expand Down
21 changes: 21 additions & 0 deletions src/xpra/codecs/vpx/encoder.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import time
import os
from collections import deque
from xpra.codecs.codec_constants import video_codec_spec
from xpra.os_util import bytestostr

Expand Down Expand Up @@ -339,6 +340,7 @@ cdef class Encoder:
cdef object src_format
cdef int speed
cdef int quality
cdef object last_frame_times

cdef object __weakref__

Expand All @@ -358,6 +360,7 @@ cdef class Encoder:
self.speed = speed
self.quality = quality
self.frames = 0
self.last_frame_times = deque(maxlen=200)
self.pixfmt = get_vpx_colorspace(self.src_format)
try:
#no point having too many threads if the height is small, also avoids a warning:
Expand Down Expand Up @@ -467,6 +470,20 @@ cdef class Encoder:
"encoding" : self.encoding,
"src_format": self.src_format,
"max_threads": self.max_threads})
#calculate fps:
cdef unsigned int f = 0
cdef double now = time.time()
cdef double last_time = now
cdef double cut_off = now-10.0
cdef double ms_per_frame = 0
for start,end in list(self.last_frame_times):
if end>cut_off:
f += 1
last_time = min(last_time, end)
ms_per_frame += (end-start)
if f>0 and last_time<now:
info["fps"] = int(0.5+f/(now-last_time))
info["ms_per_frame"] = int(1000.0*ms_per_frame/f)
return info

def get_encoding(self):
Expand Down Expand Up @@ -536,6 +553,8 @@ cdef class Encoder:
cdef int frame_cnt = 0
cdef int flags = 0
cdef vpx_codec_err_t i #@DuplicatedSignature

start = time.time()
image = <vpx_image_t *> xmemalign(sizeof(vpx_image_t))
memset(image, 0, sizeof(vpx_image_t))
image.w = self.width
Expand Down Expand Up @@ -598,6 +617,8 @@ cdef class Encoder:
img = (<char*> pkt.data.frame.buf)[:pkt.data.frame.sz]
free(image)
log("vpx returning %s image: %s bytes", self.encoding, len(img))
end = time.time()
self.last_frame_times.append((start, end))
return img

def set_encoding_speed(self, int pct):
Expand Down

0 comments on commit 0eb6b06

Please sign in to comment.