Categories
Wowza

BT.709 Wowza

Problem

Noticed that our lowest transcoded video streams had a different colors to the rest of the streams. We do multiple transcoding’s, both 720p, 480p, 360p, 270p and it was only 360p and 270p that had this disparity from the original. The difference is slight but annoying enough that you notice it if you are constantly switching between qualities.

Solution

Setting the three values colour_primaries, transfer_characteristics, matrix_coefficients to be BT.709 for 360p and 270p.

You do this by setting the following encoder properties

NameValue
mainconcept.colour_primaries1
mainconcept.transfer_characteristics1
mainconcept.matrix_coefficients1

Background

There is multiple values that says what color space that is being used. using MPC-HC we can se that the color space we are using for most of the files is BT.709, as it should be for HD broadcasts.

Color primariesBT.709
Transfer characteristicsBT.709
Matrix coefficientsBT.709
For 1080p, 720p and 480p, MPC-HC reported the following color information

however then dropping the resolution to below 360p Wowza and Mainconcept switches the color space.

Color primariesBT.601 PAL
Transfer characteristicsBT.470 System B, BT.470 System G
Matrix coefficientsBT.601
For 360p and 270p different color information was reported compared to the original 1080p

Tests

Wowza allows you to set advanced settings for the Mainconcept encoder, however you must configure Wowza to output what those settings are. you can look at the post Wowza Transcoder options to se which settings that exists.

ParameterPossible Values
mainconcept.colour_primaries1: ITU-R Rec. BT.709-5,
4: ITU-R Rec. BT.470-6 System M,
5: ITU-R Rec. BT.601-6 625,
6: ITU-R Rec. BT.601-6 525,
7: SMPTE 240M, 8: Generic film (colour filters using Illuminant C),
9: Rec. ITU-R BT.2020
mainconcept.transfer_characteristics0:auto (default),
1: BT.709-5,
4: BT.470-6 System M,
5: BT.470-6 System B G,
6: BT.709-5,
7: SMPTE 240M,
8: Linear,
14: Rec. ITU-R BT.2020
mainconcept.matrix_coefficients0:auto (default),
1: BT.709-5 System 1125,
4..6: BT.709-5 System 1250,
7: SMPTE 240M,
9: Rec. ITU-R BT.2020 non-constant luminance system
Difference settings for colors

My educated guess would be that I should set the values for BT.709-5 System 1250 since I am in a pal country running 50fps. But doing so resultat in an outputted file that had Matrix Coeffcient as BT.601

The only combination of the above settings that resultat in BT.709 for all settings was the value 1 for all three properties.

Categories
Uncategorized

Move Git Repository

Short howto move an repository from one remote origin to another.

Step 1, make sure everything is synced before you begin.

git pull
git push

Step 2. Check what your current remote origin is

$ git remote -v
origin  https://old/repository (fetch)
origin  https://old/repository (push)

Step 3. Set your new remote origin

git remote set-url origin ssh://new/repository

Step 4. Verify

$ git remote -v
origin  ssh://new/repository (fetch)
origin  ssh://new/repository (push)
Categories
Uncategorized

Disable dns over https

For Chrome & Edge

chrome://flags/#dns-over-https
Categories
Uncategorized Wowza

Wowza Transcoder options

To view all the encoding parameters you need to add logVideoEncodingParameters and logAudioEncodingParameters in your transcoder configuration as well as enabling debug logging in log4j.properties.

To enable debug add the following to your transcoder profile

<Encode>
	<Name>270p</Name>
	<Enable>true</Enable>
	<Description></Description>
	<StreamName>mp4:${SourceStreamName}_270p</StreamName>
	<Video>
		...
	</Video>
	<Audio>
		...
	</Audio>
	<Properties>
		<Property>
			<Name>logVideoEncodingParameters</Name>
			<Value>true</Value>
			<Type>Boolean</Type>
		</Property>
		<Property>
			<Name>logAudioEncodingParameters</Name>
			<Value>true</Value>
			<Type>Boolean</Type>
		</Property>
	</Properties>
</Encode>

These are the options for your video codec (if using cpu)

# long: profile_id: 0=H264PROFILE_BASELINE, 1=H264PROFILE_MAIN, 3=H264PROFILE_HIGH
mainconcept.profile_id: 3
# long: level_id: = 10 -> 1.0, .. 51 -> 5.1
mainconcept.level_id: 32
# long: idr_interval: gop length
mainconcept.idr_interval: 0
# long: reordering_delay: max distance between two P frames
mainconcept.reordering_delay: 1
# long: use_b_slices
mainconcept.use_b_slices: 0
# long: interlace_mode: 0=H264_PROGRESSIVE, 1=H264_INTERLACED, 2=H264_MBAFF
mainconcept.interlace_mode: 0
# long: def_horizontal_size
mainconcept.def_horizontal_size: 852
# long: def_vertical_size
mainconcept.def_vertical_size: 480
# double: frame_rate
mainconcept.frame_rate: 50.0
# long: num_reference_frames
mainconcept.num_reference_frames: 4
# long: search_range: motion search: spatial search range
mainconcept.search_range: 255
# long: rd_optimization: motion search: rate-distortion optimization
mainconcept.rd_optimization: 1
# long: max_l0_active: motion search: max index of reference frames in list0
mainconcept.max_l0_active: 0
# long: max_l1_active: motion search: max index of reference frames in list1
mainconcept.max_l1_active: 0
# long: quant_pI: macro blocks: quantization parameter
mainconcept.quant_pI: 24
# long: quant_pP: macro blocks: quantization parameter
mainconcept.quant_pP: 25
# long: quant_pB: macro blocks: quantization parameter
mainconcept.quant_pB: 27
# long: bit_rate_mode: bit rate stuff: 0=H264_CBR, 1=H264_CQT, 2=H264_VBR or 3=H264_TQM
mainconcept.bit_rate_mode: 2
# long: bit_rate_buffer_size: bit rate stuff: vbv buffer size
mainconcept.bit_rate_buffer_size: 3740000
# long: bit_rate: bit rate stuff: avg bitrate; if 0, use above quantization parameters
mainconcept.bit_rate: 1700000
# long: max_bit_rate: bit rate stuff: max bitrate, used in VBR mode
mainconcept.max_bit_rate: 1869952
# long: inter_search_shape: prediction: 0=H264_INTERSEARCH_16x16 (use only 16x16 block size) or 1=H264_INTERSEARCH_8x8 (use block size down to 8x8)
mainconcept.inter_search_shape: 1
# long: entropy_coding_mode: coding mode: 0=H264_CAVLC or 1=H264_CABAC
mainconcept.entropy_coding_mode: 1
# long: use_hadamard_transform: coding mode: 0=SAD is used, 1=SATD is used
mainconcept.use_hadamard_transform: 0
# long: sar_width: vui parameters: sample aspect ratio: horizontal size in arbitrary units
mainconcept.sar_width: 1
# long: sar_height: vui parameters: sample aspect ratio: vertical size in arbitrary units
mainconcept.sar_height: 1
# long: video_format: vui parameters: 1=PAL, 2=NTSC
mainconcept.video_format: 1
# long: video_full_range: vui parameters: (currently) not used
mainconcept.video_full_range: 2
# long: num_units_in_tick: vui parameters: timing info use together with time_scale
mainconcept.num_units_in_tick: 1
# long: time_scale: vui parameters: timing info use together with num_units_in_tick (fps = time_scale/num_units_in_tick)
mainconcept.time_scale: 50
# long: vbv_buffer_fullness: advanced settings: initial vbv-fullness
mainconcept.vbv_buffer_fullness: 10
# long: vbv_buffer_fullness_trg: advanced settings: final vbv-fullness
mainconcept.vbv_buffer_fullness_trg: 100
# long: vbv_buffer_units: advanced settings: units of vbv-fullness and buffer size
mainconcept.vbv_buffer_units: 0
# long: cpb_removal_delay: advanced settings: CPB removal delay for the first picture (needed for segment merging)
mainconcept.cpb_removal_delay: 0
# long: bit_rate_scale: external setting of bit_rate_scale (avoids recalculation of bitrate)
mainconcept.bit_rate_scale: 1
# long: cpb_size_scale: external setting of cpb_size_scale (avoids recalculation of bitrate)
mainconcept.cpb_size_scale: 3
# long[4]: max_frame_size: max frames size for I, P, Bref, B frames
mainconcept.max_frame_size: 0,0,0,0
# long: hrd_maintain: 0=hrd model disabled, 1=hrd model enabled
mainconcept.hrd_maintain: 1
# long[4]: min_frame_size: min frames size for I, P, Bref, B frames
mainconcept.min_frame_size: 0,0,0,0
# long: hrd_low_delay: 0=low delay hrd disabled, 1=low delay hrd enabled
mainconcept.hrd_low_delay: 0
# long: smooth_factor: Quantizer curve compression smooth factor, 0 = disabled
mainconcept.smooth_factor: 0
# long: use_deblocking_filter: in-loop filter:
mainconcept.use_deblocking_filter: 1
# long: deblocking_alphaC0_offset: in-loop filter:
mainconcept.deblocking_alphaC0_offset: -1
# long: deblocking_beta_offset: in-loop filter:
mainconcept.deblocking_beta_offset: -1
# long: adaptive_deblocking: in-loop filter: adaptive deblocking filter
mainconcept.adaptive_deblocking: 0
# long: video_type: type issues: one of above defines
mainconcept.video_type: 5
# long: video_pulldown_flag: type issues: one of above flags
mainconcept.video_pulldown_flag: 0
# long: overscan_appropriate_flag: additional vui parameters: controls overscan_appropriate_flag of VUI
mainconcept.overscan_appropriate_flag: 0
# long: stream_type: file/stream issues: 0=H264_STREAM_TYPE_I, 1=H264_STREAM_TYPE_I_SEI, 3=H264_STREAM_TYPE_II, 4=H264_STREAM_TYPE_II_NO_SEI
mainconcept.stream_type: 2
# long: frame_mbs_mode: file/stream issues: 0=H264_FRAME_MBS_ON, 1=H264_FRAME_MBS_OFF
mainconcept.frame_mbs_mode: 0
# long: bit_depth_luma: bit_depth_chroma
mainconcept.bit_depth_luma: 8
# long: bit_depth_chroma: bit_depth_chroma
mainconcept.bit_depth_chroma: 8
# long: chroma_format: 1=H264_CHROMA_400, 2=H264_CHROMA_420 or 3=H264_CHROMA_422, 4=H264_CHROMA_444
mainconcept.chroma_format: 2
# long: vui_presentation: configuration of VUI header: 0 - old school / auto mode, 1 - customized configuration, depending on following flags/bits, 0x002 - aspect_ratio_info_present_flag, 0x004 - overscan_info_present_flag (not supported), 0x008 - video_signal_type_present_flag, 0x010 - colour_description_present_flag, 0x020 - chroma_loc_info_present_flag (not supported), 0x040 - timing_info_present_flag, 0x080 - nal_hrd_parameters_present_flag, 0x100 - vcl_hrd_parameters_present_flag, 0x200 - pic_struct_present_flag, 0x400 - bitstream_restriction_flag
mainconcept.vui_presentation: 0
# long: write_au_delimiters: write access unit delimiters
mainconcept.write_au_delimiters: 1
# long: write_seq_end_code: write seq end code
mainconcept.write_seq_end_code: 1
# long: write_timestamps: write picture timecode in PT SEI
mainconcept.write_timestamps: 1
# long: timestamp_offset: frame offset (in #frames) for timestamps (default = 0)
mainconcept.timestamp_offset: 0
# long: drop_frame_timecode: use NTSC drop frame timecode notation for 29.97 and 59.94 target frame rates
mainconcept.drop_frame_timecode: 0
# long: write_single_sei_per_nalu: writes single sei message per nal unit
mainconcept.write_single_sei_per_nalu: 0
# long: write_seq_par_set: behaviour of writing sequence parameter set (default = 0): 0 - old school (SPS once per IDR), 1 - SPS once per I-frame
mainconcept.write_seq_par_set: 0
# long: write_pic_par_set: behaviour of writing picture parameter set (default = 0): 0 - old school (PPS once per IDR), 1 - PPS once per I picture, 2 - PPS once per picture
mainconcept.write_pic_par_set: 0
# long: log2_max_poc: allows to specify custom log2_max_pic_order_cnt_lsb_minus4 value: valid range is 4..16, default - 8
mainconcept.log2_max_poc: 8
# long: log2_max_frame_num: allows to specify custom log2_max_frame_num_minus4 value: valid range is 4..16, default - 8
mainconcept.log2_max_frame_num: 8
# long: pic_order_cnt_type: allows to specify custom pic_order_cnt_type value: valid values are 0 (default) and 2
mainconcept.pic_order_cnt_type: 0
# long: pic_order_present_flag: controls pic_order_present_flag value in PPS (e.g. for SBTVD-T)
mainconcept.pic_order_present_flag: 0
# long: fixed_frame_rate: controls fixed_frame_rate_flag in VUI
mainconcept.fixed_frame_rate: 1
# long: frame_based_timing: controls time_scale / num_units_in_tick ration in VUI (field or frame rate)
mainconcept.frame_based_timing: 0
# long: vcsd_mode: scene detection: visual content scene detection, 0: OFF, 1: IDR (see vcsd_mode_flags)
mainconcept.vcsd_mode: 0
# long: vcsd_sensibility: describes sensibility of scene detector (0: high, 100: 0)
mainconcept.vcsd_sensibility: 0
# long: slice_mode: advanced settings: = 1, use multiple slices per picture
mainconcept.slice_mode: 1
# long: slice_arg: advanced settings: number of slices per picture
mainconcept.slice_arg: 1
# long: b_slice_reference: advanced settings: use b slices as reference too (b -> B)
mainconcept.b_slice_reference: 0
# long: b_slice_pyramid: advanced settings: pyramidal gop structure  (...bBb...)
mainconcept.b_slice_pyramid: 0
# long: cb_offset: advanced settings: chroma quality offset (-X -> increase quality, +X -> decrease quality)
mainconcept.cb_offset: 1
# long: cr_offset: advanced settings: chroma quality offset (-X -> increase quality, +X -> decrease quality)
mainconcept.cr_offset: 1
# long: me_subpel_mode: advanced settings: 0=H264_FULL_PEL, 1=H264_HALF_PEL, 2=H264_QUARTER_PEL
mainconcept.me_subpel_mode: 2
# long: me_weighted_p_mode: advanced settings: whether to use explicit WP for P-frames or not
mainconcept.me_weighted_p_mode: 1
# long: me_weighted_b_mode: advanced settings: (currently) not used
mainconcept.me_weighted_b_mode: 0
# long: enable_fast_intra_decisions: advanced settings: enables fast intra decisions
mainconcept.enable_fast_intra_decisions: 2
# long: enable_fast_inter_decisions: advanced settings: enables fast inter decisions
mainconcept.enable_fast_inter_decisions: 2
# long: pic_ar_x: advanced settings: picture aspect ratio: horizontal size
mainconcept.pic_ar_x: -1
# long: pic_ar_y: advanced settings: picture aspect ratio: vertical size
mainconcept.pic_ar_y: -1
# long: calc_quality: advanced settings: calculate PSNR or not
mainconcept.calc_quality: 0
# long: cpu_opt: advanced settings: cpu optimization
mainconcept.cpu_opt: 0
# long: num_threads: advanced settings: number of threads
mainconcept.num_threads: 0
# long: live_mode: advanced settings: online or offline mode (not yet implemented)
mainconcept.live_mode: 0
# long: buffering: advanced settings: maximum number of seconds to buffer
mainconcept.buffering: 0
# long: min_quant: advanced settings: minimum quantization parameter
mainconcept.min_quant: 0
# long: max_quant: advanced settings: maximum quantization parameter
mainconcept.max_quant: 51
# long: max_slice_size: advanced settings: maximum slice size in bits, set to 0 if you do not need it
mainconcept.max_slice_size: 0
# long: encoding_buffering: advanced settings: maximum number of seconds to buffer encoding queue
mainconcept.encoding_buffering: 0
# long: low_delay: advanced settings: low delay mode (not yet implemented)
mainconcept.low_delay: 0
# long: air_mode: advanced settings: adaptive intra refresh mode
mainconcept.air_mode: 0
# long: detach_thread: advanced settings: run core in a new thread or not
mainconcept.detach_thread: 1
# long: constrained_intra_pred: advanced settings: constrained intra prediction for improving error resilience
mainconcept.constrained_intra_pred: 0
# long: air_split_frequency: advanced settings: frequency of intra lines for adaptive air mode split
mainconcept.air_split_frequency: 0
# long: air_qp_offset: advanced settings: qp offset for adaptive intra mode lines
mainconcept.air_qp_offset: 0
# long: min_idr_interval: advanced gop settings: min gop length
mainconcept.min_idr_interval: 1
# long: adaptive_b_frames: advanced gop settings: use adaptive B-frames placement or not
mainconcept.adaptive_b_frames: 0
# long: idr_frequency: advanced gop settings: 0 means only first frame is IDR, 1 means every I-frame is IDR, etc
mainconcept.idr_frequency: 1
# long: field_order: advanced gop settings: 0=TFF, 1=BFF
mainconcept.field_order: 0
# long: fixed_i_position: advanced gop settings: constant I frame position
mainconcept.fixed_i_position: 0
# long: isolated_gops: advanced gop settings: allows to limit referencing to frames from the previous GOP, may be useful when idr_frequency != 1
mainconcept.isolated_gops: 0
# long: hierar_p_frames: advanced gop settings: GOP structure with hierarchically coded P frames (for temporal scalability with out using B frames) (not yet supported in enc_avc/trunk)
mainconcept.hierar_p_frames: 0
# long: fast_multi_ref_me: advanced me settings: enables fast decisions for multi-ref ME
mainconcept.fast_multi_ref_me: 1
# long: fast_sub_block_me: advanced me settings: enables fast decisions for sub-block ME
mainconcept.fast_sub_block_me: 1
# long: allow_out_of_pic_mvs: advanced me settings: enables mvs out of picture boundaries
mainconcept.allow_out_of_pic_mvs: 1
# long: constrained_ref_list: advanced me settings: use constrained reference picture list
mainconcept.constrained_ref_list: 0
# long: enable_intra_big: advanced intra settings: allows to use 16x16 intra mode in intra slices
mainconcept.enable_intra_big: 1
# long: enable_intra_8x8: advanced intra settings: same for 8x8
mainconcept.enable_intra_8x8: 1
# long: enable_intra_4x4: advanced intra settings: same for 4x4
mainconcept.enable_intra_4x4: 1
# long: enable_intra_pcm: advanced intra settings: same for PCM
mainconcept.enable_intra_pcm: 0
# long: enable_inter_big: advanced intra settings: allows to use 16x16 intra mode in inter slices
mainconcept.enable_inter_big: 1
# long: enable_inter_8x8: advanced intra settings: same for 8x8
mainconcept.enable_inter_8x8: 1
# long: enable_inter_4x4: advanced intra settings: same for 4x4
mainconcept.enable_inter_4x4: 1
# long: enable_inter_pcm: advanced intra settings: same for PCM
mainconcept.enable_inter_pcm: 0
# long: fast_rd_optimization: advanced rdo settings: allows fast RDO
mainconcept.fast_rd_optimization: 1
# long: quant_mode: advanced rdo settings: quantization optimization mode
mainconcept.quant_mode: 2
# long: grain_mode: advanced rdo settings: granular noise optimization mode, not used any more
mainconcept.grain_mode: 0
# long: grain_opt_strength: advanced rdo settings: scalable film grain optimization [0..100], use 0 to turn it off
mainconcept.grain_opt_strength: 0
# long[8]: adaptive_quant_strength: advanced rdo settings: adaptive quantization strength [-100..100] or every mode (from H264_AQUANT_MODE_BRIGHTNESS to COMPLEXITY), last 5 strengths are not used at the moment
mainconcept.adaptive_quant_strength: 0,0,0,0,0,0,0,0
# long: denoise_strength_y: Psycho-visual enhancement: denoise strength for luma [0..100]
mainconcept.denoise_strength_y: 0
# long: denoise_strength_c: Psycho-visual enhancement: denoise strength for chroma [0..100]
mainconcept.denoise_strength_c: 0
# long: black_norm_level: Psycho-visual enhancement: black normalization level, any luma less than or equal to black_norm_level will be set to 16
mainconcept.black_norm_level: 0
# long: pulse_reduction: Psycho-visual enhancement: key frame pulsing reduction
mainconcept.pulse_reduction: 0
# long: aux_format_idc: alpha plane: aux_format_idc
mainconcept.aux_format_idc: -1
# long: bit_depth_aux: alpha plane: bit_depth_aux
mainconcept.bit_depth_aux: 8
# long: alpha_incr_flag: alpha plane: alpha_incr_flag
mainconcept.alpha_incr_flag: 0
# long: alpha_opaque_value: alpha plane: alpha_opaque_value
mainconcept.alpha_opaque_value: 0
# long: alpha_transparent_value: alpha plane: alpha_transparent_value
mainconcept.alpha_transparent_value: 0
# long: seq_scaling_matrix_present_flag: seq_scaling_list_present_flag equal[i] to 1 specifies that the syntax structure
mainconcept.seq_scaling_matrix_present_flag: 0
# long[8]: seq_scaling_list_present_flag: for scaling list i is present in the sequence parameter set (and not in the picture parameter set)
mainconcept.seq_scaling_list_present_flag: 0,0,0,0,0,0,0,0
# long[16]: intra_y_4x4_scaling_list: scaling lists: intra_y_4x4_scaling_list
mainconcept.intra_y_4x4_scaling_list: 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
# long[16]: intra_cb_4x4_scaling_list: scaling lists: intra_cb_4x4_scaling_list
mainconcept.intra_cb_4x4_scaling_list: 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
# long[16]: intra_cr_4x4_scaling_list: scaling lists: intra_cr_4x4_scaling_list
mainconcept.intra_cr_4x4_scaling_list: 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
# long[16]: inter_y_4x4_scaling_list: scaling lists: inter_y_4x4_scaling_list
mainconcept.inter_y_4x4_scaling_list: 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
# long[16]: inter_cb_4x4_scaling_list: scaling lists: inter_cb_4x4_scaling_list
mainconcept.inter_cb_4x4_scaling_list: 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
# long[16]: inter_cr_4x4_scaling_list: scaling lists: inter_cr_4x4_scaling_list
mainconcept.inter_cr_4x4_scaling_list: 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
# long[64]: intra_y_8x8_scaling_list: scaling lists: intra_y_8x8_scaling_list
mainconcept.intra_y_8x8_scaling_list: 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
# long[64]: inter_y_8x8_scaling_list: scaling lists: inter_y_8x8_scaling_list
mainconcept.inter_y_8x8_scaling_list: 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
# long: performance_level: (0-15) 0:H264_PERF_FASTEST, 9:H264_PERF_BALANCED, 15:H264_PERF_BEST_Q
mainconcept.performance_level: -1
# long: keyframe_follow: 0:off, 1:on (default)
mainconcept.keyframe_follow: 1
# long: maintain_original_pts: 0:off, 1:on (default)
mainconcept.maintain_original_pts: 1
# long: colour_primaries: 0:auto (default), 1: ITU-R Rec. BT.709-5, 4: ITU-R Rec. BT.470-6 System M, 5: ITU-R Rec. BT.601-6 625, 6: ITU-R Rec. BT.601-6 525, 7: SMPTE 240M, 8: Generic film (colour filters using Illuminant C), 9: Rec. ITU-R BT.2020
mainconcept.colour_primaries: 0
# long: transfer_characteristics: 0:auto (default), 1: BT.709-5,4: BT.470-6 System M,5: BT.470-6 System B G,6: BT.709-5,7: SMPTE 240M,8: Linear,14: Rec. ITU-R BT.2020
mainconcept.transfer_characteristics: 0
# long: matrix_coefficients: 0:auto (default), 1: BT.709-5 System 1125, 4..6: BT.709-5 System 1250, 7: SMPTE 240M, 9: Rec. ITU-R BT.2020 non-constant luminance system
mainconcept.matrix_coefficients: 0
# long: extended_sar: Enable extended sample aspect ratio
mainconcept.extended_sar: 0 

These are the parameters available for your audio.

# long: channel copy: 0=donothing, 1=copy-left-over-right, 2=copy-right-over-left
mainconcept.channel_copy: 0
# long: crc protection: 0=off, 1=on
mainconcept.protect_adts_stream: 0
# long: high frequency cut-off
mainconcept.hf_cutoff: 12000
# long: mpeg version: 6=MPEG2_AAC_AUDIO, 7=MPEG4_AAC_AUDIO, 16=MPEG4_AAC_AUDIO_PSP
mainconcept.mpeg_version: 7
# long: variable bitrate mode: 0 = off
mainconcept.vbr: 0
# long: temporal noise shaping (tns) algorithm: 0=off, 1=on
mainconcept.tns: 1
# long: aac object type
mainconcept.aac_object_type: 2
# long: high efficiency: 0=off, 1=HE-v1, 2=HE-v2
mainconcept.he: 0

I extracted this from the logfile using the following command

awk 'BEGIN { FS="\t" } { print $9 }'  wowzastreamingengine_access.log | grep 'mainconcept\|^#' > parameters.log
Categories
Uncategorized

WSL2 / Vmmem

There is an ongoing issue with vmmem eating up all your memory in windows 10 2004. There is a workaround.

Workaround: Create a %UserProfile%\.wslconfig file in Windows and use it to limit memory assigned to WSL2 VM.

Apostolos
https://github.com/microsoft/WSL/issues/4166#issuecomment-526725261

Below is an example of .wslconfig

[wsl2]
memory=6GB
swap=0
localhostForwarding=true
Categories
Linux

RabbitMQ Memory Limit

RabbitMQ has an memory limit, then RabbitMQ hits this limit weird things starts to happen. Example The .NET library for RabbitMQ Client hangs then you try to dispose the connection.

How do you know that RabbitMQ has run out of memory? you have to check the RabbitMQ node (picture below)

Then Memory is read you are out of memory

RabbitMQ will not allocate all available memory in the VM or container you have set up.

High memory watermark blocks publishers and prevents new messages from being enqueued. Since garbage collection can double the memory used by a queue, it is unsafe to set the high memory watermark above 0.5. The default high memory watermark is set to 0.4 since this is safer as not all memory is used by queues. This is entirely workload specific, which differs across RabbitMQ deployments.

https://www.rabbitmq.com/memory-use.html

A freshly started RabbitMQ uses roughly 100MB, that means that you cannot limit your container to less than 250MB of memory if you want your RabbitMQ to actually be useable

Categories
Linux Network

Test Unix socket

This is a small test/benchmark to se if the use of a unix domain socket in Nginx would affect performance in any significant way for an api

The api is hosted by .NET Core and containerized. Test is done by using apache benchmark. doing 100 concurrent request 50 times. The request that is done has a payload of 1,7 KB.

ab -n 5000 -c 100 "http://localhost/v3/api/"

Result

This is the average request per second after 10 tests against each configuration.

Requests per second
HTTP100
HTTP (Keepalive enabled)118
Unix Socket98
Unix Socket (Keepalive enabled)120

Keepalive

Nginx option keepalive has an impact on both http and unix sockets. It looks to be far more important than the actual connection type.

upstream backend {
        keepalive 100;
        server 10.265.44.3:8080;
}

Categories
.NET

Newtonsoft/System.Text.Json Testing

Microsoft has released NET Core 3 and with that included System.Text.Json a new json serializer to replace Newtonsoft. One of the claims is that This new serializer is faster. There is already multiple benchmarks proving that claim. However I wanted to see what the difference actually became in real life against one of my existing APIs.

End to end testing

I will do an E2E testing using ab (Apache Benchmark) to see if there will be a difference in response time and how many simultaneous request the api can handle. I will test everything 10 times and then average out the value.

To test the the response time i will do one single request with ab and se how long it takes.

ab -n 1 -c 1 "https://localhost:5001/v3/api/"

To test how many request per second i can handle i will use ab to send 100 simultaneous request to the server 5 times.

ab -n 500 -c 100 "https://localhost:5001/v3/"

Test 1

The first test is fetching a single item from the API. The payload is 1,7 KB, the request in is fetching the data IDistributedCache, most of the work is therefor deserialize the data from IDistributedCache and then serialize it again for the response.

Response time 1/reqRequest per second
Newtonsoft14,8 ms98,7 req/s
System.Text.Json 18,4 ms100,2 req/s

Test 2

The second test fetches 48 items from the api, the payload is 36,6 KB. Most of the time is spent on fetching data from the database


Response time 1/req

Request per second
Newtonsoft 129,8 ms26,11 req/s
System.Text.Json 123,5 ms
31,3 req/s

Test 2b

I found the result of test 2 interesting and decided to redo the test but increase the total amount of request from 500 to 5000.

Request per second
Newtonsoft 19,4 req/s
System.Text.Json 30,53 req/s

Conclusion

I am a bit amazed on how big the difference became, for test 2. looking into some other tests there actually might be something behind it. quoting from the comments at The Battle of C# to JSON Serializers in .NET Core 3

Up to the initial buffer size (8-16kb depending on the lib)? Nothing, they all pretty much behave the same, the buffer is filled and after the serialization is done, the buffer is flushed to the output pipe/stream.
After that size it gets interesting. System.Text.Json is capable of flushing the data and reusing the old small buffer, Utf8Json/Spanjson will rent a new buffer from the pool and copy the data and continue.

TORNHOOF (@TORN_HOOF)

As the payload in Test 2 is quit big (36,6 KB), it might explain the increase in throughput compared to test 1.

Categories
.NET

Entity Framework Core 3

I recently upgraded an .NET Core 2 project to .NET Core 3 and with that I also updated other packages, including EF Core. Now EF Core 3 has quite a list of breaking changes you can se them in the list below.

https://docs.microsoft.com/en-us/ef/core/what-is-new/ef-core-3.0/breaking-changes

The worst change for my application was one that is quit a bit down on the list and one that I did not see until I found the actual issue in my code.

Before 3.0, eagerly loading collection navigations via Include operators caused multiple queries to be generated on relational database, one for each related entity type.

Eager loading of related entities now happens in a single query

This does not sound to bad, nothing will stop working, but it will effect performance. If it effects performance depends on your query, some will go faster and some will go slower.

In my case I had an query that did not like this change at all. the query created an list of items. These items then had a bunch of data from other tables, created an 3d dimensional object. I Mocked up an example below on how the Linq Query looked like.

return context.Item
	.Select(i => new ResultItem()
	{
		ItemId   = i.ItemId,
		Siblings = i.parentNavigation.Items.Count(),
		Position = i.parentNavigation.Items.Count(p => p.Order < I.Order),
		tags = i.Tag.Select(t => new ResultTag {
			tag = t.tag
		})
	}).ToList();

In EF Core 2, this worked quite well. EF Core divided the code in two parts. First it did one query to fetch the items, count the siblings and position, and then it would do multiple queries to fetch the tags. So if I fetched 12 items. it would be 1 query to fetch the items and then 12 queries to fetch all the tags.

EF Core 3 however does one query, ONE BIG QUERY. In this case it resulted in some performance drop. In EF Core 2 it had a stable 250ms execution time, independent on how many tags each item had. In EF Core 3 it hovered around 650ms but could be slower if one item had more tags than usual.

Improvement 1

var items = context.Item
	.Select(i => new ResultItem()
	{
		ItemId   = i.ItemId,
                ParentId = i.ParentId,
                Order = i.Order
	}).ToList();

foreach (var item in items)
{
	item.Siblings = context.Item.Count(i => i.ParentId == item.ParentId);
	item.Position = context.Item.Count(i => i.ParentId == item.ParentId && i.Order < item.Order);
	item.tags = context.Tag.Where(t => t.ItemId = item.ItemId).Select(t => new ResultTag {
			tag = t.tag
		}).ToList();
}

First step was to separate the different queries. We simply fetched the item first and then looped over them to fetch the extra data needed. This resulted in quite some improvement, we decreased the time from around 650ms to 350ms. But it was still not fast enough.

The reason it still not as fast as before is because this code results in a lot of queries. If we fetch 12 items, it will result 1 query to fetch the items, then it will loop over all the items and do 3 separate queries for each item. Resulting in a total of 1+36 queries against the database.

Each query means another roundtrip to the database. And this is partly the reason why EF Core decided to make the change in EF core 3, to try to avoid as many roundtrips as possible.

Improvement 2

var items = context.Item
	.Select(i => new ResultItem()
	{
		ItemId   = i.ItemId,
                ParentId = i.ParentId,
                Order = i.Order
	}).ToList();

var itemIds = items.Select(c => c.ItemId);
var tags = context.Tag.Where(t => itemIds.Contains(t.ItemId)).Select(t => new ResultTag {
	ItemId = t.ItemId,
	Tag = t.Tag
}).ToList();

var parentIds = items.Select(i => i.ParentId);
var siblings = context.Item.Where(i => parentIds.Contains(i.parentId)).Select(i => new SiblingItem {
	ParentId = i.ParentId,
	Order = i.Order
}).ToList();

foreach (var item in items)
{
	item.Siblings = siblings.Count(i => i.ParentId == item.ParentItem);
	item.Position = siblings.Count(i => i.ParentId == item.ParentItem && i.Order < item.Order);
	item.tags = tags.Where(t => t.ItemId = item.ItemId);
}

Now we have complicated our code somewhat, but this was the fastest way of doing it. As previous example we first fetch all the items. Our next step is for all items we fetched, select their siblings in on query and select all their tags in another query. We can then loop over the items and filter out the result for each item. This resulted in a total of 3 queries being sent to the database and the execution time dropped to under 100ms.

Categories
Programming

VS Code: Wrap Attributes

Go to File > Settings > Preferences. Expand Extensions and click on HTML. Scroll down until you find the setting Wrap Attribute. set to force-aligned

Enabling this setting will make the formatter to but each html attributes on a new line. You activate the formatter by pressing Shift+Alt+ F