Skip to content
Snippets Groups Projects
Commit f947fb5f authored by Leo Ma's avatar Leo Ma
Browse files

Not repeat nal headers in x264


Repeat nal headers in front of each I-frame will produce lower output fps.

Signed-off-by: default avatarLeo Ma <begeekmyfriend@gmail.com>
parent 1e49d04a
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -91,6 +91,11 @@ public class SrsEncoder {
setOutputResolution(vOutWidth, vOutHeight);
setOutputFps(VFPS);
setOutputGop(VGOP);
// Unfortunately for some android phone, the output fps is less than 10 limited by the
// capacity of poor cheap chips even with x264. So for the sake of quick appearance of
// the first picture on the player, a spare lower GOP value is suggested. But note that
// lower GOP will produce more I frames and therefore more streaming data flow.
// setOutputGop(15);
setOutputBitrate(VBITRATE);
if (useSoftEncoder && !openSoftEncoder()) {
Loading
Loading
No preview for this file type
Loading
Loading
@@ -26,9 +26,7 @@ typedef struct x264_context {
x264_param_t params;
x264_t *encoder;
x264_picture_t picture;
// sei buffer
uint8_t sei[256];
int sei_size;
bool global_nal_header;
// input
int width;
int height;
Loading
Loading
@@ -196,23 +194,23 @@ static int encode_nals(const x264_nal_t *nals, int nnal) {
int i;
uint8_t *p = h264_es;
/* Write the SEI as part of the first frame. */
if (x264_ctx.sei_size > 0 && nnal > 0) {
memcpy(p, x264_ctx.sei, x264_ctx.sei_size);
p += x264_ctx.sei_size;
x264_ctx.sei_size = 0;
}
for (i = 0; i < nnal; i++) {
if (nals[i].i_type != NAL_SEI) {
memcpy(p, nals[i].p_payload, nals[i].i_payload);
p += nals[i].i_payload;
}
memcpy(p, nals[i].p_payload, nals[i].i_payload);
p += nals[i].i_payload;
}
return p - h264_es;
}
static int encode_global_nal_header() {
int nnal;
x264_nal_t *nals;
x264_ctx.global_nal_header = false;
x264_encoder_headers(x264_ctx.encoder, &nals, &nnal);
return encode_nals(nals, nnal);
}
static int x264_encode(struct YuvFrame *i420_frame, long pts) {
int out_len, nnal;
x264_nal_t *nal;
Loading
Loading
@@ -250,7 +248,7 @@ static jint libenc_NV21SoftEncode(JNIEnv* env, jobject thiz, jbyteArray frame, j
return JNI_ERR;
}
int es_len = x264_encode(&i420_scaled_frame, pts);
int es_len = x264_ctx.global_nal_header ? encode_global_nal_header() : x264_encode(&i420_scaled_frame, pts);
if (es_len <= 0) {
LIBENC_LOGE("Fail to encode nalu");
return JNI_ERR;
Loading
Loading
@@ -285,11 +283,14 @@ static jboolean libenc_openSoftEncoder(JNIEnv* env, jobject thiz) {
// Presetting
x264_param_default_preset(&x264_ctx.params, "veryfast", "zerolatency");
x264_ctx.params.b_repeat_headers = 0;
x264_ctx.global_nal_header = true;
// Resolution
x264_ctx.params.i_width = x264_ctx.width;
x264_ctx.params.i_height = x264_ctx.height;
// Default setting i_rc_method as X264_RC_CRF which is better than X264_RC_ABR
// Default setting of i_rc_method as X264_RC_CRF which is better than X264_RC_ABR
//x264_ctx.params.rc.i_bitrate = x264_ctx.bitrate; // kbps
//x264_ctx.params.rc.i_rc_method = X264_RC_ABR;
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment