'H.264 Video format (YUV420p vs YUV420sp)
I'm doing a video streaming project. The standard only mentions using the following format for video:
The terminal shall support H.264 video codecs by default using the H.264 - frame rate of 25 frames / sec - CIF (352 * 288) format - payload type (payload_type): 98 - timestamp frequency (kHz): 90
By default my Android device packs the data in YUV420SP format. When the video goes thru, it comes up with a green tint and a slight distortion.
Probing further it seems that I should have used the YUV420P format instead.
Can somebody help educate me on why H264 itself does not define the actual data format to use? Doesn't this leave it open to developer interpretation instead? Or am I missing something?
Solution 1:[1]
H.264 is the specification for "coding of moving video". The standard describes the syntax of the (compressed) bitstream.
H.264 does not describe a vendor specific encoder input format. It is common practice to leave the encoder specification out or wide open.
Solution 2:[2]
Codecs typically will support different pixel formats - YUV is a pixel format space, like RGB - a way of encoding the colour of a pixel.
Codecs actually have many different parameters that can be set - to try help usage they generally define profiles which provide values for key parameters to us. For example, HEVC codec (h.265) has many different profiles.
Your point is essentially correct - it is possible to have a device support h.264, but not support the particular parameters you select.
Solution 3:[3]
After recreating your same three files in a directory by themselves I found that if I change this:
import foo from './foo';
to this:
import foo from './foo.js';
Then, it works. I believe I remember something about ESM modules that says you have to specify the file extension and you can't just use the root name like you can with CommonJS modules.
Using your exact code, recreated in the same three files, running node v16.13.0, making this one change makes it work for me.
Now, I did not originally get the same error you got. I got this error:
Error [ERR_MODULE_NOT_FOUND]: Cannot find module xxx import from yyy
I wonder if you had a file named just foo somehow that it was finding? If not, something else is still different in your system than mine.
I wonder if you're still trying to use a TypeScript compiler and the TypeScript compile target is set for CommonJS modules?
Because the error you get is somehow indicating that a CommonJS module is getting loaded, but there is no reason for that if given only these three files in a directory by themselves and no compile step of any kind.
Things for you to check.
Are you sure that when you run
node, you're running the plain node executable and not something that Typescript has installed that will try to compile the sources using some default configuration?Are there ANY other files in this directory? If so, then isolate these three files into their own directory where there are no other package.json files anywhere in the parent tree.
Try executing the test.js file from the same directory (so using the same package.json) below and see what it outputs:
Sample file:
// test.js
let foundDirname = typeof __dirname === "string";
let foundModule = typeof module === "object";
console.log("found __dirname", foundDirname);
console.log("found module", foundModule);
if (foundDirname && foundModule) {
console.log("appears to be a CommonJS module")
} else {
console.log("appears to be an ESM module");
}
This should tell you whether it is treating your file as a CommonJS module or an ESM module.
Run this test file with:
node test.js
Solution 4:[4]
Simply import like this.
const foo = require("./foo.js");
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Markus Schumann |
| Solution 2 | |
| Solution 3 | |
| Solution 4 | jatin.7744 |
