Press "Enter" to skip to content

Huahua's Tech Road

Nikon Z8/Z9 Video Format / Bitrate / Compression ratio | NRAW | ProRes | ProRes RAW | H.265

The Nikon official site didn’t provide the birate for ProRes / ProRes RAW, I did some test my self, here’re the results. I only tested fullframe (FX) in ~4K resolution.

ProRes Raw 12Bit

Resolution / FPSBitrate (Mbps)Compression Ratio
4140 x 2330 60p33501.977
4140 x 2330 50p28101.964
4140 x 2330 30p16202.044
4140 x 2330 25p13602.029
4140 x 2330 24p12802.070

ProRes Raw has a very low compression ratio of 2, which suggests that it might be lossless compressed, which takes more spaces than Nikon’s lossy N-RAW, 2.5x of the high quality and 4.5x of the normal quality!

ProRes HQ 422 10Bit

Resolution / FPSBitrate (Mbps)Compression Ratio
3840 x 2160 60p18005.273
3840 x 2160 50p15005.273
3840 x 2160 30p9105.215
3840 x 2160 25p7605.204
3840 x 2160 24p7305.201

With compression ratio of 5.2, ProRes is still 2x the size of the normal quality n-raw! Though the former one has 1.5x number of pixels to deal with (YUV422 vs Bayer).

I hope Nikon could provide more options for ProRes via firmware updates. A 10x~12x compression ratio version (ProRes LT 422) will be very useful to balance between quality and disk space.

H.265 420 10 bit

Resolution / FPSBitrate (Mbps)Compression Ratio
7680 x 4320 30p40047.461
7680 x 4320 25p40039.551
7680 x 4320 24p40037.969
3840 x 2160 120p40047.461
3840 x 2160 100p40039.551
3840 x 2160 60p34027.918
3840 x 2160 50p34023.265
3840 x 2160 30p19024.979
3840 x 2160 25p19020.816
3840 x 2160 24p19019.984

For H.265, there is no option for all-intra, and only in 420. Compression ratio is much higher given long GOP. One thing to note, that bitrate is variable depend on the content, i.e. very dark scene will have a much lower bitrate (<100Mbps for 4K60).

NRAW High Quality 12 bit

Resolution / FPSBitrate (Mbps)Compression Ratio
8256 x 4644 60p57804.555
8256 x 4644 50p48104.561
8256 x 4644 30p28904.555
8256 x 4644 25p24104.552
8256 x 4644 24p23104.559
4128 x 2322 120p38403.428
4128 x 2322 100p29003.783
4128 x 2322 60p17403.783
4128 x 2322 50p14503.783
4128 x 2322 30p8703.783
4128 x 2322 25p7303.757
4128 x 2322 24p7003.761

First of all, given 4.5 compression ratio, NRAW is definitely a lossy codec. Interesting thing is that 8K’s compression ratio is higher than 4K’s. 4.5 vs 3.7.

NRAW Normal Quality 12 bit

Resolution / FPSBitrate (Mbps)Compression Ratio
8256 x 4644 60p34707.587
8256 x 4644 50p28907.591
8256 x 4644 30p17407.565
8256 x 4644 25p14507.565
8256 x 4644 24p13907.576
4128 x 2322 120p17507.522
4128 x 2322 100p14607.513
4128 x 2322 60p8807.479
4128 x 2322 50p7307.513
4128 x 2322 30p4407.479
4128 x 2322 25p3707.412
4128 x 2322 24p3507.522

For normal quality, the compression ratio is even higher, reaching 7.5:1 which is not bad for all-intra.

花花酱 LeetCode 3029. Minimum Time to Revert Word to Initial State I

You are given a 0-indexed string word and an integer k.

At every second, you must perform the following operations:

  • Remove the first k characters of word.
  • Add any k characters to the end of word.

Note that you do not necessarily need to add the same characters that you removed. However, you must perform both operations at every second.

Return the minimum time greater than zero required for word to revert to its initial state.

Example 1:

Input: word = "abacaba", k = 3
Output: 2
Explanation: At the 1st second, we remove characters "aba" from the prefix of word, and add characters "bac" to the end of word. Thus, word becomes equal to "cababac".
At the 2nd second, we remove characters "cab" from the prefix of word, and add "aba" to the end of word. Thus, word becomes equal to "abacaba" and reverts to its initial state.
It can be shown that 2 seconds is the minimum time greater than zero required for word to revert to its initial state.

Example 2:

Input: word = "abacaba", k = 4
Output: 1
Explanation: At the 1st second, we remove characters "abac" from the prefix of word, and add characters "caba" to the end of word. Thus, word becomes equal to "abacaba" and reverts to its initial state.
It can be shown that 1 second is the minimum time greater than zero required for word to revert to its initial state.

Example 3:

Input: word = "abcbabcd", k = 2
Output: 4
Explanation: At every second, we will remove the first 2 characters of word, and add the same characters to the end of word.
After 4 seconds, word becomes equal to "abcbabcd" and reverts to its initial state.
It can be shown that 4 seconds is the minimum time greater than zero required for word to revert to its initial state.

Constraints:

  • 1 <= word.length <= 50
  • 1 <= k <= word.length
  • word consists only of lowercase English letters.

Solution: Suffix ==? Prefix

Compare the suffix with prefix.

word = “abacaba”, k = 3
ans = 1, “abacaba” != “abacaba
ans = 2, “abacaba” == “abacaba“, we find it.

Time complexity: O(n * n / k)
Space complexity: O(1)

C++

花花酱 LeetCode 3028. Ant on the Boundary

An ant is on a boundary. It sometimes goes left and sometimes right.

You are given an array of non-zero integers nums. The ant starts reading nums from the first element of it to its end. At each step, it moves according to the value of the current element:

  • If nums[i] < 0, it moves left by -nums[i] units.
  • If nums[i] > 0, it moves right by nums[i] units.

Return the number of times the ant returns to the boundary.

Notes:

  • There is an infinite space on both sides of the boundary.
  • We check whether the ant is on the boundary only after it has moved |nums[i]| units. In other words, if the ant crosses the boundary during its movement, it does not count.

Example 1:

Input: nums = [2,3,-5]
Output: 1
Explanation: After the first step, the ant is 2 steps to the right of the boundary.
After the second step, the ant is 5 steps to the right of the boundary.
After the third step, the ant is on the boundary.
So the answer is 1.

Example 2:

Input: nums = [3,2,-3,-4]
Output: 0
Explanation: After the first step, the ant is 3 steps to the right of the boundary.
After the second step, the ant is 5 steps to the right of the boundary.
After the third step, the ant is 2 steps to the right of the boundary.
After the fourth step, the ant is 2 steps to the left of the boundary.
The ant never returned to the boundary, so the answer is 0.

Constraints:

  • 1 <= nums.length <= 100
  • -10 <= nums[i] <= 10
  • nums[i] != 0

Solution: Simulation

Simulate the position of the ant by summing up the numbers. If the position is zero (at boundary), increase the answer by 1.

Time complexity: O(n)
Space complexity: O(1)

C++

花花酱 LeetCode 3005. Count Elements With Maximum Frequency

You are given an array nums consisting of positive integers.

Return the total frequencies of elements in nums such that those elements all have the maximum frequency.

The frequency of an element is the number of occurrences of that element in the array.

Example 1:

Input: nums = [1,2,2,3,1,4]
Output: 4
Explanation: The elements 1 and 2 have a frequency of 2 which is the maximum frequency in the array.
So the number of elements in the array with maximum frequency is 4.

Example 2:

Input: nums = [1,2,3,4,5]
Output: 5
Explanation: All elements of the array have a frequency of 1 which is the maximum.
So the number of elements in the array with maximum frequency is 5.

Constraints:

  • 1 <= nums.length <= 100
  • 1 <= nums[i] <= 100

Solution: Hashtable

Use a hashtable to store the frequency of each element, and compare it with a running maximum frequency. Reset answer if current frequency is greater than maximum frequency. Increment the answer if current frequency is equal to the maximum frequency.

Time complexity: O(n)
Space complexity: O(n)

C++

// Author: Huahua

花花酱 LeetCode 2976. Minimum Cost to Convert String I

You are given two 0-indexed strings source and target, both of length n and consisting of lowercase English letters. You are also given two 0-indexed character arrays original and changed, and an integer array cost, where cost[i] represents the cost of changing the character original[i] to the character changed[i].

You start with the string source. In one operation, you can pick a character x from the string and change it to the character y at a cost of z if there exists any index j such that cost[j] == zoriginal[j] == x, and changed[j] == y.

Return the minimum cost to convert the string source to the string target using any number of operations. If it is impossible to convert source to targetreturn -1.

Note that there may exist indices ij such that original[j] == original[i] and changed[j] == changed[i].

Example 1:

Input: source = "abcd", target = "acbe", original = ["a","b","c","c","e","d"], changed = ["b","c","b","e","b","e"], cost = [2,5,5,1,2,20]
Output: 28
Explanation: To convert the string "abcd" to string "acbe":
- Change value at index 1 from 'b' to 'c' at a cost of 5.
- Change value at index 2 from 'c' to 'e' at a cost of 1.
- Change value at index 2 from 'e' to 'b' at a cost of 2.
- Change value at index 3 from 'd' to 'e' at a cost of 20.
The total cost incurred is 5 + 1 + 2 + 20 = 28.
It can be shown that this is the minimum possible cost.

Example 2:

Input: source = "aaaa", target = "bbbb", original = ["a","c"], changed = ["c","b"], cost = [1,2]
Output: 12
Explanation: To change the character 'a' to 'b' change the character 'a' to 'c' at a cost of 1, followed by changing the character 'c' to 'b' at a cost of 2, for a total cost of 1 + 2 = 3. To change all occurrences of 'a' to 'b', a total cost of 3 * 4 = 12 is incurred.

Example 3:

Input: source = "abcd", target = "abce", original = ["a"], changed = ["e"], cost = [10000]
Output: -1
Explanation: It is impossible to convert source to target because the value at index 3 cannot be changed from 'd' to 'e'.

Constraints:

  • 1 <= source.length == target.length <= 105
  • sourcetarget consist of lowercase English letters.
  • 1 <= cost.length == original.length == changed.length <= 2000
  • original[i]changed[i] are lowercase English letters.
  • 1 <= cost[i] <= 106
  • original[i] != changed[i]

Solution: All pairs shortest path

Compute the shortest path (min cost) for any given letter pairs.

Time complexity: O(26^3 + m + n)
Space complexity: O(26^2)

C++