Closed totaam closed 6 years ago
html5-mpeg1.patch
(13.4 KiB)mpeg1 encoder, decoder and stub html5 implementation
Preparatory work:
The patch attached implements encoding but still needs work:
This may all be moot since H264 decoding seems to be fixed: #1839. It could still be useful for very low powered device (ie: some arm boards?) where the decoding complexity of H264 is too much?
html5-mpeg1-v2.patch
(3.3 KiB)hook up mpeg1 decoding, not painting yet
Updates:
- r19306: test video encoders with two frames (since mpeg1 and mpeg2 delay one frame, they would error only on the second)
- r19312: make muxer optional in ffmpeg encoder
- r19313: implement mpeg1 and mpeg2 encoding, add python avcodec support for decoding mpeg2, and paint colors ("olive" and "lime")
For the html5 client, the patch above seems to decode OK, we just need to do something with the YUV data we get. Either re-use their
WebGLRenderer
or do software YUV-to-RGB as a POC. (and maybe ship a subset of jsmpeg1 - no need for the player and websocket bits - audio?)
html5 mpeg1 decoder added in r19317. (we won't be doing mpeg2: jsmpeg : Support MPEG2?)
Still TODO:
- check CPU load and bandwidth: compare it with h264 (#1839 - once asm.js optimization is fixed there) so we can use weights to choose the most appropriate video encoder
- trim jsmpeg.js file
- re-use the webgl checks to enable the gl renderer in other places?
Note: the "mpeg1" video encoding is controlled by the "Video" option in the advanced connection options. This enables both h264 and mpeg1. To use only mpeg1, set
--video-encoders=ffmpeg
on the server side.
Updates:
Requirements:
ffmpeg-xpra
version 4.0-2
or later--video-encoders=ffmpeg
to ensure only mpeg1 is used for testingInitial testing shows that my decent CPU can render 1080p at a decent framerate (close to 25fps), each frame taking about 10 to 50KB - meaning around 2 to 10Mbps, roughly. Note: mpeg1 always buffers one frame, which is fine for sending video.
@maxmylyn: ready for testing. worth comparing with #1839
It works great - except native decoding seems to be extremely choppy and spews lots of tracebacks on both my Fedora and Windows8.1 boxes.
Is there anything in particular I should be looking at?
It works great - except native decoding seems to be extremely choppy and spews lots of tracebacks on both my Fedora and Windows8.1 boxes.
What tracebacks? Always include all tracebacks.
In any case, mpeg1 is not meant to be used by the python client, it is designed for the html5 client.
For reference I'm running Trunk r19621 on Fedora 28 with Chrome in Fedora and Windows8.1.
On the client side I see the following:
Client.js:1 error painting mpeg4+mp4 DOMException: Failed to execute 'appendBuffer' on 'SourceBuffer': This SourceBuffer has been removed from the parent media source. at XpraWindow._push_video_buffers (http://192.168.1.81:10000/js/Window.js:1:18041) at XpraWindow.do_paint (http://192.168.1.81:10000/js/Window.js:1:25593) at XpraWindow.may_paint_now (http://192.168.1.81:10000/js/Window.js:1:20976) at XpraWindow.paint (http://192.168.1.81:10000/js/Window.js:1:20603) at XpraClient._process_draw_queue (http://192.168.1.81:10000/js/Client.js:2:15980) at XpraClient._process_draw (http://192.168.1.81:10000/js/Client.js:2:14532) at XpraProtocolWorkerHost.XpraClient._route_packet [as packet_handler] (http://192.168.1.81:10000/js/Client.js:1:9239) at Worker.<anonymous> (http://192.168.1.81:10000/js/Protocol.js:1:707) XpraClient.error @ Client.js:1 XpraWindow.error @ Window.js:1 paint_error @ Window.js:1 XpraWindow.do_paint @ Window.js:1 XpraWindow.may_paint_now @ Window.js:1 XpraWindow.paint @ Window.js:1 XpraClient._process_draw_queue @ Client.js:2 XpraClient._process_draw @ Client.js:2 XpraClient._route_packet @ Client.js:1 (anonymous) @ Protocol.js:1 Window.js:1 Uncaught (in promise) DOMException: The element has no supported sources.
On the server side I see the following
2018-06-12 10:33:35,576 client video source buffer error 2018-06-12 10:33:35,576 client video error 2018-06-12 10:33:35,698 client error painting mpeg4+mp4 InvalidStateError: Failed to execute 'appendBuffer' on 'SourceBuffer': This SourceBuffer has been removed from the parent media source. 2018-06-12 10:33:35,713 Warning: client decoding error: 2018-06-12 10:33:35,715 InvalidStateError: Failed to execute 'appendBuffer' on 'SourceBuffer': This SourceBuffer has been removed from the parent media source. 2018-06-12 10:33:36,345 client error painting mpeg4+mp4 InvalidStateError: Failed to execute 'appendBuffer' on 'SourceBuffer': This SourceBuffer has been removed from the parent media source. 2018-06-12 10:33:36,347 Warning: client decoding error: 2018-06-12 10:33:36,347 InvalidStateError: Failed to execute 'appendBuffer' on 'SourceBuffer': This SourceBuffer has been removed from the parent media source. 2018-06-12 10:33:36,360 client video media source EOS error: NotFoundError: Failed to execute 'removeSourceBuffer' on 'MediaSource': The SourceBuffer provided is not contained in this MediaSource. 2018-06-12 10:33:36,361 client video codec string: video/mp4; codecs="avc1.42C01E" for mpeg4+mp4 profile 'baseline', level '3.0' 2018-06-12 10:33:36,362 client video media source open 2018-06-12 10:33:36,410 client video error
(in hindsight I definitely should have included the tracebacks)
Also this error starts to print after a second or so:
Client.js:1 video error XpraClient.error @ Client.js:1 XpraWindow.error @ Window.js:1 (anonymous) @ Window.js:1 error (async) XpraWindow._init_video @ Window.js:1 XpraWindow.do_paint @ Window.js:1 XpraWindow.may_paint_now @ Window.js:1 XpraWindow.paint @ Window.js:1 XpraClient._process_draw_queue @ Client.js:2 XpraClient._process_draw @ Client.js:2 XpraClient._route_packet @ Client.js:1 (anonymous) @ Protocol.js:1 index.html:1 Uncaught (in promise) DOMException: The play() request was interrupted by a call to pause(). https://goo.gl/LdLk22
Those stacktraces have nothing to do with this ticket, they're for native video #1463 - which is known to be broken, and doesn't use mpeg1.
Upped my Fedora 28 server to r20907 and am using Chrome 69 (Fedora 28) as a client.
The mpeg-1 decoding is much better now, but I keep getting random hitches where the framerate drops while watching YouTube videos in Chrome and Firefox. I did some investigating and turned on
-d ffmpeg
, and I see these prints in the logs right around the frame drops:2018-11-01 10:18:54,391 compress_image(None, -1, -1, {u'flush': True}) avcodec_receive_packet avpacket=0x7f2c327fb110 2018-11-01 10:18:54,391 avcodec_receive_packet(..)=0 2018-11-01 10:18:54,391 avcodec_receive_packet returned 0x63f8 bytes of data, flags: 2018-11-01 10:18:54,391 compress_image(None, -1, -1, {u'flush': True}) avcodec_receive_packet avpacket=0x7f2c327fb110 2018-11-01 10:18:54,391 avcodec_receive_packet(..)=-541478725 2018-11-01 10:18:54,391 avcodec_receive_packet returned error 'End of file' for flush request 2018-11-01 10:18:54,391 compress_image(None) 25592 bytes (1 buffers) for mpeg1 with client options: {u'frame': 116, u'delayed': 1} 2018-11-01 10:18:54,391 enc_ffmpeg.Encoder({u'video-description': 'MPEG-1 video', u'encoding': u'mpeg1', u'encoder_width': 1160, u'encoder_height': 652, u'height': 652, u'width': 1160, u'version': (58, 18, 100), u'src_format': u'YUV420P', u'formats': [u'YUV420P'], u'frames': 117, u'type': u'ffmpeg', u'video-codec': 'mpeg1video'}).clean_encoder() 2018-11-01 10:18:54,391 clean_encoder() freeing AVFrame: 0x7f2bd3803fc0 2018-11-01 10:18:54,391 clean_encoder() freeing AVCodecContext: 0x7f2bc633a440 2018-11-01 10:18:54,392 clean_encoder() done 2018-11-01 10:18:54,392 enc_ffmpeg.Encoder(*closed*).clean_encoder() 2018-11-01 10:18:54,392 clean_encoder() freeing AVCodecContext: 0x0 2018-11-01 10:18:54,392 clean_encoder() done 2018-11-01 10:18:54,881 init_context codec(mpeg1)=mpeg1 2018-11-01 10:18:54,881 mpeg1video: "MPEG-1 video", codec flags: SLICE_THREADS, DELAY 2018-11-01 10:18:54,882 AVCodecContext options: b, ab, bt, flags, unaligned, mv4, qpel, loop, qscale, pass1, pass2, gray, psnr, truncated, ildct, low_delay, global_header, bitexact, aic, ilme, cgop, output_corrupt, fast, noout, ignorecrop, local_header, chunks, showall, export_mvs, skip_manual, ass_ro_flush_noop, time_base, g, ar, ac, cutoff, frame_size, frame_number, delay, qcomp, qblur, qmin, qmax, qdiff, bf, b_qfactor, b_strategy, ps, mv_bits, header_bits, i_tex_bits, p_tex_bits, i_count, p_count, skip_count, misc_bits, frame_bits, codec_tag, bug, autodetect, xvid_ilace, ump4, no_padding, amv, qpel_chroma, std_qpel, qpel_chroma2, direct_blocksize, edge, hpel_chroma, dc_clip, ms, trunc, iedge, strict, very, strict, normal, unofficial, experimental, b_qoffset, err_detect, crccheck, bitstream, buffer, explode, ignore_err, careful, compliant, aggressive, has_b_frames, block_align, mpeg_quant, rc_override_count, maxrate, minrate, bufsize, i_qfactor, i_qoffset, dct, auto, fastint, int, mmx, altivec, faan, lumi_mask, tcplx_mask, scplx_mask, p_mask, dark_mask, idct, auto, int, simple, simplemmx, arm, altivec, simplearm, simplearmv5te, simplearmv6, simpleneon, xvid, xvidmmx, faani, simpleauto, slice_count, ec, guess_mvs, deblock, favor_inter, bits_per_coded_sample, pred, left, plane, median, aspect, sar, debug, pict, rc, bitstream, mb_type, qp, dct_coeff, green_metadata, skip, startcode, er, mmco, bugs, buffers, thread_ops, nomc, cmp, subcmp, mbcmp, ildctcmp, dia_size, last_pred, preme, precmp, sad, sse, satd, dct, psnr, bit, rd, zero, vsad, vsse, nsse, dctmax, chroma, msad, pre_dia_size, subq, me_range, global_quality, coder, vlc, ac, raw, rle, context, slice_flags, mbd, simple, bits, rd, sc_threshold, nr, rc_init_occupancy, flags2, threads, auto, dc, nssew, skip_top, skip_bottom, profile, unknown, aac_main, aac_low, aac_ssr, aac_ltp, aac_he, aac_he_v2, aac_ld, aac_eld, mpeg2_aac_low, mpeg2_aac_he, dts, dts_es, dts_96_24, dts_hd_hra, dts_hd_ma, mpeg4_sp, mpeg4_core, mpeg4_main, mpeg4_asp, main10, msbc, level, unknown, lowres, skip_threshold, skip_factor, skip_exp, skipcmp, mblmin, mblmax, mepc, skip_loop_filter, skip_idct, skip_frame, none, default, noref, bidir, nokey, nointra, all, bidir_refine, brd_scale, keyint_min, refs, chromaoffset, trellis, mv0_threshold, b_sensitivity, compression_level, min_prediction_order, max_prediction_order, timecode_frame_start, bits_per_raw_sample, channel_layout, request_channel_layout, rc_max_vbv_use, rc_min_vbv_use, ticks_per_frame, color_primaries, bt709, unknown, bt470m, bt470bg, smpte170m, smpte240m, film, bt2020, smpte428, smpte428_1, smpte431, smpte432, jedec-p22, unspecified, color_trc, bt709, unknown, gamma22, gamma28, smpte170m, smpte240m, linear, log100, log316, iec61966-2-4, bt1361e, iec61966-2-1, bt2020-10, bt2020-12, smpte2084, smpte428, arib-std-b67, unspecified, log, log_sqrt, iec61966_2_4, bt1361, iec61966_2_1, bt2020_10bit, bt2020_12bit, smpte428_1, colorspace, rgb, bt709, unknown, fcc, bt470bg, smpte170m, smpte240m, ycgco, bt2020nc, bt2020c, smpte2085, unspecified, ycocg, bt2020_ncl, bt2020_cl, color_range, unknown, tv, pc, unspecified, mpeg, jpeg, chroma_sample_location, unknown, left, center, topleft, top, bottomleft, bottom, unspecified, log_level_offset, slices, thread_type, slice, frame, audio_service_type, ma, ef, vi, hi, di, co, em, vo, ka, request_sample_fmt, pkt_timebase, sub_charenc, sub_charenc_mode, do_nothing, auto, pre_decoder, ignore, sub_text_format, ass, ass_with_timings, refcounted_frames, side_data_only_packets, apply_cropping, skip_alpha, field_order, progressive, tt, bb, tb, bt, dump_separator, codec_whitelist, pixel_format, video_size, max_pixels, hwaccel_flags, ignore_level, allow_high_depth, allow_profile_mismatch, extra_hw_frames 2018-11-01 10:18:54,882 mpeg1video encoder options: gop_timecode, intra_vlc, drop_frame_timecode, scan_offset, timecode_frame_start, sad, sse, satd, dct, psnr, bit, rd, zero, vsad, vsse, nsse, dct264, dctmax, chroma, msad, mpv_flags, skip_rd, strict_gop, qp_rd, cbp_rd, naq, mv0, luma_elim_threshold, chroma_elim_threshold, quantizer_noise_shaping, error_rate, qsquish, rc_qmod_amp, rc_qmod_freq, rc_eq, rc_init_cplx, rc_buf_aggressivity, border_mask, lmin, lmax, ibias, pbias, rc_strategy, ffmpeg, xvid, motion_est, zero, epzs, xone, force_duplicated_matrix, b_strategy, b_sensitivity, brd_scale, skip_threshold, skip_factor, skip_exp, skip_cmp, sc_threshold, noise_reduction, mpeg_quant, ps, mepc, mepre 2018-11-01 10:18:54,882 init_encoder() thread-type=2, thread-count=0 2018-11-01 10:18:54,882 init_encoder() codec flags: 2018-11-01 10:18:54,882 init_encoder() codec flags2: 2018-11-01 10:18:54,883 avcodec_open2 success 2018-11-01 10:18:54,883 enc_ffmpeg.Encoder.init_context(1160, 652, YUV420P) self={u'video-description': 'MPEG-1 video', u'encoding': u'mpeg1', u'encoder_width': 1160, u'encoder_height': 652, u'height': 652, u'width': 1160, u'version': (58, 18, 100), u'src_format': u'YUV420P', u'formats': [u'YUV420P'], u'frames': 0, u'type': u'ffmpeg', u'video-codec': 'mpeg1video'} 2018-11-01 10:18:54,884 compress_image(libyuv.YUVImageWrapper(YUV420P:(0, 0, 1160, 652, 24):3_PLANES), 65, 48, {'av-sync': True, 'bandwidth-limit': 5086038, 'content-type': 'browser', 'scroll': True}) avcodec_send_frame frame=0x7f2bca5a2280
It looks like the encoder is being restarted while the video is playing, which is causing the frame drops and choppiness.
The compress_image(None, -1, -1, {u'flush': True})
means that we call flush()
on the encoder. That can be called from:
full-refresh
timer (-d refresh
)refresh_subregion
(-d refresh
)video_encoder_flush_timer
(-d regionrefresh
)Unfortunately, these codepaths don't have a lot of debug logging at the moment, so it may not be possible to figure out which one of those methods fired.
-d video
would also tell us more than -d ffmpeg
which is too low-level.
Restarted my server except this time with
-d refresh
.Same setup - Watching YouTube videos in Chrome (with Chrome as the client). Watching the logs, I see lots of the auto refresh with smooth content, but I saw these logs during a series of framedrops. I'd like to retry with
-d refresh,ffmpeg
but I'm pretty sure that'll be way too many logs.2018-11-01 11:58:32,125 auto refresh: mpeg1 screen update (actual quality= 0, lossy= True), keeping existing timer (all pixels outside area) (region=rectangle(157, 192, 1160, 652), refresh regions=[R(1318, 192, 462, 653), R(157, 0, 1623, 192)]) 2018-11-01 11:58:32,156 auto refresh: mpeg1 screen update (actual quality= 0, lossy= True), keeping existing timer (all pixels outside area) (region=rectangle(157, 192, 1160, 652), refresh regions=[R(1318, 192, 462, 653), R(157, 0, 1623, 192)]) 2018-11-01 11:58:32,205 auto refresh: mpeg1 screen update (actual quality= 0, lossy= True), keeping existing timer (all pixels outside area) (region=rectangle(157, 192, 1160, 652), refresh regions=[R(1318, 192, 462, 653), R(157, 0, 1623, 192)]) 2018-11-01 11:58:32,263 auto refresh: mpeg1 screen update (actual quality= 0, lossy= True), keeping existing timer (all pixels outside area) (region=rectangle(157, 192, 1160, 652), refresh regions=[R(1318, 192, 462, 653), R(157, 0, 1623, 192)]) 2018-11-01 11:58:32,350 timer_full_refresh() after 999ms, auto_refresh_encodings=('png', 'webp', 'rgb32'), options={'speed': 50, 'quality': 100, 'optimize': False, 'auto_refresh': True}, regions=[R(1318, 192, 462, 653), R(157, 0, 1623, 192)], refresh_exclude=rectangle(157, 192, 1161, 653) 2018-11-01 11:58:32,356 get_refresh_encoding(462, 653, 50, 100, png)=webp 2018-11-01 11:58:32,356 get_refresh_encoding(1623, 192, 50, 100, png)=webp 2018-11-01 11:58:32,357 auto refresh: mpeg1 screen update (actual quality= 0, lossy= True), added pixels to refresh regions (region=rectangle(157, 192, 1160, 652), refresh regions=[]) 2018-11-01 11:58:32,373 auto refresh: webp screen update (actual quality=100, lossy=False), nothing to do (region=rectangle(157, 0, 1623, 192), refresh regions=[]) 2018-11-01 11:58:32,390 auto refresh: webp screen update (actual quality=100, lossy=False), nothing to do (region=rectangle(1318, 192, 462, 653), refresh regions=[]) 2018-11-01 11:58:32,397 auto refresh: jpeg screen update (actual quality= 5, lossy= True), added pixels to refresh regions (region=rectangle(157, 192, 1161, 653), refresh regions=[]) 2018-11-01 11:58:32,463 auto refresh: mpeg1 screen update (actual quality= 0, lossy= True), added pixels to refresh regions (region=rectangle(157, 192, 1160, 652), refresh regions=[]) 2018-11-01 11:58:32,616 auto refresh: mpeg1 screen update (actual quality= 0, lossy= True), added pixels to refresh regions (region=rectangle(157, 192, 1160, 652), refresh regions=[]) 2018-11-01 11:58:32,619 auto refresh: jpeg screen update (actual quality= 90, lossy= True), added pixels to refresh regions, scheduling refresh in 500ms (pct=7, batch=37) (region=rectangle(1318, 192, 208, 653), refresh regions=[R(1318, 192, 208, 653)]) 2018-11-01 11:58:32,621 auto refresh: jpeg screen update (actual quality= 90, lossy= True), added pixels to refresh regions, re-scheduling refresh (due in 500ms, 2ms added - sched_delay=500, pct=21, batch=37) (region=rectangle(157, 0, 1369, 192), refresh regions=[R(1318, 192, 208, 653), R(157, 0, 1369, 192)]) 2018-11-01 11:58:32,699 video region unchanged: rectangle(157, 192, 1161, 653) - no change in refresh 2018-11-01 11:58:32,699 update_refresh_attributes() wid=3, sizef=1.37, content-type=browser, qf=1.12, sf=1.03, cf=1.00, batch delay=53, bandwidth-limit=5142681, min-delay=500, max-delay=1000, delay=500 2018-11-01 11:58:32,699 do_set_auto_refresh_delay(500, 500) 2018-11-01 11:58:32,699 update_refresh_attributes() wid=3, refresh quality=100%, refresh speed=50%, for cv=0.00, bwl=5142681 2018-11-01 11:58:32,995 auto refresh: mpeg1 screen update (actual quality= 0, lossy= True), keeping existing timer (all pixels outside area) (region=rectangle(157, 192, 1160, 652), refresh regions=[R(1318, 192, 208, 653), R(157, 0, 1369, 192)]) 2018-11-01 11:58:33,120 timer_full_refresh() after 500ms, auto_refresh_encodings=('png', 'webp', 'rgb32'), options={'speed': 50, 'quality': 100, 'optimize': False, 'auto_refresh': True}, regions=[R(1318, 192, 208, 653), R(157, 0, 1369, 192)], refresh_exclude=rectangle(157, 192, 1161, 653) 2018-11-01 11:58:33,120 get_refresh_encoding(208, 653, 50, 100, png)=webp 2018-11-01 11:58:33,120 get_refresh_encoding(1369, 192, 50, 100, png)=webp 2018-11-01 11:58:33,130 auto refresh: webp screen update (actual quality=100, lossy=False), nothing to do (region=rectangle(157, 0, 1369, 192), refresh regions=[]) 2018-11-01 11:58:33,140 auto refresh: webp screen update (actual quality=100, lossy=False), nothing to do (region=rectangle(1318, 192, 208, 653), refresh regions=[]) 2018-11-01 11:58:33,428 auto refresh: jpeg screen update (actual quality= 5, lossy= True), added pixels to refresh regions (region=rectangle(157, 192, 1161, 653), refresh regions=[]) 2018-11-01 11:58:33,487 auto refresh: mpeg1 screen update (actual quality= 0, lossy= True), added pixels to refresh regions (region=rectangle(157, 192, 1160, 652), refresh regions=[]) 2018-11-01 11:58:33,554 auto refresh: mpeg1 screen update (actual quality= 0, lossy= True), added pixels to refresh regions (region=rectangle(157, 192, 1160, 652), refresh regions=[]) 2018-11-01 11:58:33,620 auto refresh: mpeg1 screen update (actual quality= 0, lossy= True), added pixels to refresh regions (region=rectangle(157, 192, 1160, 652), refresh regions=[]) 2018-11-01 11:58:33,699 video region unchanged: rectangle(157, 192, 1161, 653) - no change in refresh 2018-11-01 11:58:33,700 update_refresh_attributes() wid=3, sizef=1.37, content-type=browser, qf=1.11, sf=1.07, cf=1.00, batch delay=49, bandwidth-limit=4927046, min-delay=500, max-delay=1000, delay=500 2018-11-01 11:58:33,700 do_set_auto_refresh_delay(500, 500) 2018-11-01 11:58:33,700 update_refresh_attributes() wid=3, refresh quality=100%, refresh speed=50%, for cv=0.00, bwl=4927046 2018-11-01 11:58:33,739 auto refresh: mpeg1 screen update (actual quality= 0, lossy= True), added pixels to refresh regions (region=rectangle(157, 192, 1160, 652), refresh regions=[]) 2018-11-01 11:58:33,785 auto refresh: mpeg1 screen update (actual quality= 0, lossy= True), added pixels to refresh regions (region=rectangle(157, 192, 1160, 652), refresh regions=[]) 2018-11-01 11:58:33,797 auto refresh: mpeg1 screen update (actual quality= 0, lossy= True), added pixels to refresh regions (region=rectangle(157, 192, 1160, 652), refresh regions=[])
I think it may be the full-refresh that's causing the encoder to get flushed fully. But you probably know more about that than I do.
Issue migrated from trac ticket # 1816
component: html5 | priority: major | resolution: fixed
2018-04-21 04:32:26: antoine created the issue