Ticket #1107: save-video-to-file.patch
File save-video-to-file.patch, 7.3 KB (added by , 5 years ago) |
---|
-
xpra/codecs/enc_x264/encoder.pyx
12 12 X264_LOGGING = os.environ.get("XPRA_X264_LOGGING", "WARNING") 13 13 LOG_NALS = os.environ.get("XPRA_X264_LOG_NALS", "0")=="1" 14 14 USE_OPENCL = os.environ.get("XPRA_X264_OPENCL", "0")=="1" 15 SAVE_TO_FILE = os.environ.get("XPRA_SAVE_TO_FILE") 15 16 16 17 from xpra.util import nonl 17 from xpra.util import nonl, AtomicInteger 18 18 from xpra.os_util import bytestostr 19 19 from xpra.codecs.codec_constants import get_subsampling_divs, video_spec 20 20 from collections import deque … … 322 322 def get_type(): 323 323 return "x264" 324 324 325 generation = AtomicInteger() 325 326 def get_info(): 326 327 global COLORSPACES, MAX_WIDTH, MAX_HEIGHT 327 328 return {"version" : get_version(), 328 329 "buffer_api": get_buffer_api_version(), 329 330 "max-size" : (MAX_WIDTH, MAX_HEIGHT), 331 "generation": generation.get(), 330 332 "formats" : COLORSPACES.keys()} 331 333 332 334 def get_encodings(): … … 410 412 cdef unsigned long long bytes_in 411 413 cdef unsigned long long bytes_out 412 414 cdef object last_frame_times 415 cdef object file 413 416 cdef uint64_t first_frame_timestamp 414 417 415 418 cdef object __weakref__ 416 419 417 420 def init_context(self, int width, int height, src_format, dst_formats, encoding, int quality, int speed, scaling, options): #@DuplicatedSignature 418 global COLORSPACE_FORMATS 421 global COLORSPACE_FORMATS, generation 419 422 cs_info = COLORSPACE_FORMATS.get(src_format) 420 423 assert cs_info is not None, "invalid source format: %s, must be one of: %s" % (src_format, COLORSPACE_FORMATS.keys()) 421 424 assert encoding=="h264", "invalid encoding: %s" % encoding … … 441 444 self.profile = cs_info[1] 442 445 log("using default profile=%s", self.profile) 443 446 self.init_encoder() 447 gen = generation.increase() 448 if SAVE_TO_FILE is not None: 449 filename = SAVE_TO_FILE+str(gen)+".%s" % encoding 450 self.file = open(filename, 'wb') 451 log.info("saving %s stream to %s", encoding, filename) 444 452 445 453 cdef init_encoder(self): 446 454 cdef x264_param_t param … … 487 495 self.bytes_out = 0 488 496 self.last_frame_times = [] 489 497 self.first_frame_timestamp = 0 498 f = self.file 499 if f: 500 self.file = None 501 f.close() 490 502 491 503 492 504 def get_info(self): #@DuplicatedSignature … … 643 655 self.frames += 1 644 656 self.last_frame_times.append((start, end)) 645 657 assert self.context!=NULL 658 if self.file and frame_size>0: 659 self.file.write(cdata) 660 self.file.flush() 646 661 return cdata, client_options 647 662 648 663 -
xpra/codecs/vpx/encoder.pyx
8 8 from collections import deque 9 9 from xpra.codecs.codec_constants import video_spec 10 10 from xpra.os_util import bytestostr 11 from xpra.util import AtomicInteger 11 12 12 13 from xpra.log import Logger 13 14 log = Logger("encoder", "vpx") 14 15 16 SAVE_TO_FILE = os.environ.get("XPRA_SAVE_TO_FILE") 15 17 18 16 19 #sensible default: 17 20 cpus = 2 18 21 try: … … 269 272 return [input_colorspace] 270 273 271 274 275 generation = AtomicInteger() 272 276 def get_info(): 273 277 global CODECS, MAX_SIZE 274 278 info = {"version" : get_version(), … … 275 279 "encodings" : CODECS, 276 280 "buffer_api" : get_buffer_api_version(), 277 281 "abi_version" : get_abi_version(), 282 "generation" : generation.get(), 278 283 "build_config" : vpx_codec_build_config()} 279 284 for e, maxsize in MAX_SIZE.items(): 280 285 info["%s.max-size" % e] = maxsize … … 368 373 cdef int quality 369 374 cdef int lossless 370 375 cdef object last_frame_times 376 cdef object file 371 377 372 378 cdef object __weakref__ 373 379 … … 461 467 self.codec_control("periodic Q boost", VP9E_SET_FRAME_PERIODIC_BOOST, 0) 462 468 self.do_set_encoding_speed(speed) 463 469 self.do_set_encoding_quality(quality) 470 gen = generation.increase() 471 if SAVE_TO_FILE is not None: 472 filename = SAVE_TO_FILE+str(gen)+".%s" % encoding 473 self.file = open(filename, 'wb') 474 log.info("saving %s stream to %s", encoding, filename) 464 475 465 476 466 477 def codec_control(self, info, int attr, int value): … … 563 574 self.max_threads = 0 564 575 self.encoding = "" 565 576 self.src_format = "" 577 f = self.file 578 if f: 579 self.file = None 580 f.close() 566 581 567 582 568 583 def compress_image(self, image, quality=-1, speed=-1, options={}): … … 659 674 log("vpx returning %s image: %s bytes", self.encoding, len(img)) 660 675 end = time.time() 661 676 self.last_frame_times.append((start, end)) 677 if self.file and pkt.data.frame.sz>0: 678 self.file.write(img) 679 self.file.flush() 662 680 return img 663 681 664 682 def set_encoding_speed(self, int pct): -
xpra/codecs/xvid/encoder.pyx
9 9 from xpra.log import Logger 10 10 log = Logger("encoder", "xvid") 11 11 12 from xpra.util import nonl 13 from xpra.os_util import bytestostr 14 from xpra.codecs.codec_constants import get_subsampling_divs, video_spec 15 from collections import deque 12 from xpra.util import AtomicInteger 13 from xpra.codecs.codec_constants import video_spec 16 14 17 from libc.stdint cimport int64_t, uint64_t, uint8_t 15 SAVE_TO_FILE = os.environ.get("XPRA_SAVE_TO_FILE") 18 16 19 17 18 from libc.stdint cimport uint8_t 19 20 20 cdef extern from "string.h": 21 21 void * memset ( void * ptr, int value, size_t num ) 22 22 … … 269 269 def get_type(): 270 270 return "xvid" 271 271 272 generation = AtomicInteger() 272 273 def get_info(): 273 274 global COLORSPACES, MAX_WIDTH, MAX_HEIGHT 274 275 return {"version" : get_version(), 275 276 "buffer_api": get_buffer_api_version(), 276 277 "max-size" : (MAX_WIDTH, MAX_HEIGHT), 278 "generation": generation.get(), 277 279 "formats" : COLORSPACES} 278 280 279 281 def get_encodings(): … … 310 312 cdef int speed 311 313 cdef unsigned long long bytes_in 312 314 cdef unsigned long long bytes_out 315 cdef object file 313 316 314 317 cdef object __weakref__ 315 318 … … 326 329 self.frames = 0 327 330 self.time = 0 328 331 self.init_encoder() 332 gen = generation.increase() 333 if SAVE_TO_FILE is not None: 334 filename = SAVE_TO_FILE+str(gen)+".%s" % encoding 335 self.file = open(filename, 'wb') 336 log.info("saving %s stream to %s", encoding, filename) 329 337 330 338 cdef init_encoder(self): 331 339 cdef int r, i … … 367 375 self.time = 0 368 376 self.quality = 0 369 377 self.speed = 0 378 f = self.file 379 if f: 380 self.file = None 381 f.close() 370 382 371 383 372 384 def get_info(self): #@DuplicatedSignature … … 489 501 self.time += end-start 490 502 self.frames += 1 491 503 assert self.context!=NULL 504 if self.file and r>0: 505 self.file.write(cdata) 506 self.file.flush() 492 507 return cdata, client_options 493 508 494 509