Improve video quality on iOS
This commit is contained in:
parent
77f60dc9c6
commit
eae9a98a3b
|
@ -112,7 +112,6 @@ int tdav_codec_h263_open(tmedia_codec_t* self)
|
|||
{
|
||||
int ret;
|
||||
int size;
|
||||
float bitRate = 64000.f;
|
||||
|
||||
tdav_codec_h263_t* h263 = (tdav_codec_h263_t*)self;
|
||||
|
||||
|
@ -137,30 +136,14 @@ int tdav_codec_h263_open(tmedia_codec_t* self)
|
|||
|
||||
/*h263->encoder.context->mb_qmin =*/ h263->encoder.context->qmin = 4;
|
||||
/*h263->encoder.context->mb_qmax =*/ h263->encoder.context->qmax = 31;
|
||||
h263->encoder.context->mb_decision = FF_MB_DECISION_SIMPLE;
|
||||
//h263->encoder.context->me_method = ME_EPZS;
|
||||
//h263->encoder.context->flags |= CODEC_FLAG_INPUT_PRESERVED | CODEC_FLAG_PASS1;
|
||||
|
||||
switch(self->bl){
|
||||
case tmedia_bl_low:
|
||||
default:
|
||||
bitRate = 64000.f;
|
||||
break;
|
||||
case tmedia_bl_medium:
|
||||
case tmedia_bl_hight:
|
||||
case tmedia_bl_unrestricted:
|
||||
bitRate = 128000.f;
|
||||
break;
|
||||
}
|
||||
h263->encoder.context->mb_decision = FF_MB_DECISION_RD;
|
||||
|
||||
h263->encoder.context->thread_count = 1;
|
||||
h263->encoder.context->rtp_payload_size = RTP_PAYLOAD_SIZE;
|
||||
h263->encoder.context->opaque = tsk_null;
|
||||
h263->encoder.context->bit_rate = (int)(bitRate * 0.80f);
|
||||
h263->encoder.context->bit_rate_tolerance = (int) (bitRate * 0.20f);
|
||||
h263->encoder.context->rc_min_rate = 0;
|
||||
h263->encoder.context->gop_size = TMEDIA_CODEC_VIDEO(h263)->fps*3; /* each 3 seconds */
|
||||
|
||||
h263->encoder.context->gop_size = TMEDIA_CODEC_VIDEO(h263)->fps*2; /* each 2 seconds */
|
||||
h263->encoder.context->flags |= CODEC_FLAG_QSCALE;
|
||||
h263->encoder.context->global_quality = FF_QP2LAMBDA * tmedia_get_video_qscale(self->bl);
|
||||
|
||||
// Picture (YUV 420)
|
||||
if(!(h263->encoder.picture = avcodec_alloc_frame())){
|
||||
|
@ -311,6 +294,7 @@ tsk_size_t tdav_codec_h263_encode(tmedia_codec_t* self, const void* in_data, tsk
|
|||
#endif
|
||||
|
||||
h263->encoder.picture->pts = AV_NOPTS_VALUE;
|
||||
h263->encoder.picture->quality = h263->encoder.context->global_quality;
|
||||
ret = avcodec_encode_video(h263->encoder.context, h263->encoder.buffer, size, h263->encoder.picture);
|
||||
if(ret > 0){
|
||||
tdav_codec_h263_encap(h263, h263->encoder.buffer, (tsk_size_t)ret);
|
||||
|
@ -505,6 +489,11 @@ tsk_bool_t tdav_codec_h263_fmtp_match(const tmedia_codec_t* codec, const char* f
|
|||
h263->width = 128, h263->height = 96;
|
||||
ret = tsk_true;
|
||||
}
|
||||
else { // Default: to be fixed
|
||||
h263->width = 352, h263->height = 288;
|
||||
ret = tsk_true;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -59,7 +59,7 @@ int tdav_codec_h264_open(tmedia_codec_t* self)
|
|||
{
|
||||
int ret;
|
||||
int size;
|
||||
float bitRate;
|
||||
|
||||
|
||||
tdav_codec_h264_t* h264 = (tdav_codec_h264_t*)self;
|
||||
|
||||
|
@ -114,17 +114,14 @@ int tdav_codec_h264_open(tmedia_codec_t* self)
|
|||
default:
|
||||
h264->encoder.context->profile = FF_PROFILE_H264_BASELINE;
|
||||
h264->encoder.context->level = 10;
|
||||
bitRate = 128000.f;
|
||||
break;
|
||||
case tdav_codec_h264_bp20:
|
||||
h264->encoder.context->profile = FF_PROFILE_H264_BASELINE;
|
||||
h264->encoder.context->level = 20;
|
||||
bitRate = 491400.f;
|
||||
break;
|
||||
case tdav_codec_h264_bp30:
|
||||
h264->encoder.context->profile = FF_PROFILE_H264_BASELINE;
|
||||
h264->encoder.context->level = 30;
|
||||
bitRate = 2725300.f;
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -132,10 +129,7 @@ int tdav_codec_h264_open(tmedia_codec_t* self)
|
|||
h264->encoder.context->thread_count = 0;
|
||||
h264->encoder.context->rtp_payload_size = H264_RTP_PAYLOAD_SIZE;
|
||||
h264->encoder.context->opaque = tsk_null;
|
||||
//h264->encoder.context->bit_rate = (int) (bitRate * 0.80f);
|
||||
//h264->encoder.context->bit_rate_tolerance = (int) (bitRate * 0.20f);
|
||||
h264->encoder.context->gop_size = TMEDIA_CODEC_VIDEO(h264)->fps*4; // Each 4 second(s)
|
||||
// h264->encoder.context->keyint_min = TMEDIA_CODEC_VIDEO(h264)->fps;
|
||||
|
||||
|
||||
// Picture (YUV 420)
|
||||
|
|
|
@ -121,7 +121,6 @@ int tdav_codec_mp4ves_open(tmedia_codec_t* self)
|
|||
{
|
||||
int ret;
|
||||
int size;
|
||||
float bitRate = 64000.f;
|
||||
|
||||
tdav_codec_mp4ves_t* mp4v = (tdav_codec_mp4ves_t*)self;
|
||||
|
||||
|
@ -147,27 +146,16 @@ int tdav_codec_mp4ves_open(tmedia_codec_t* self)
|
|||
mp4v->encoder.context->time_base.den = TMEDIA_CODEC_VIDEO(mp4v)->fps;
|
||||
mp4v->encoder.context->width = TMEDIA_CODEC_VIDEO(mp4v)->width;
|
||||
mp4v->encoder.context->height = TMEDIA_CODEC_VIDEO(mp4v)->height;
|
||||
mp4v->encoder.context->mb_decision = FF_MB_DECISION_SIMPLE;
|
||||
|
||||
switch(self->bl){
|
||||
case tmedia_bl_low:
|
||||
default:
|
||||
bitRate = 64000.f;
|
||||
break;
|
||||
case tmedia_bl_medium:
|
||||
bitRate = 128000.f;
|
||||
break;
|
||||
case tmedia_bl_hight:
|
||||
case tmedia_bl_unrestricted:
|
||||
bitRate = 250000.f;
|
||||
break;
|
||||
}
|
||||
mp4v->encoder.context->mb_decision = FF_MB_DECISION_RD;
|
||||
mp4v->encoder.context->noise_reduction = 250;
|
||||
mp4v->encoder.context->flags |= CODEC_FLAG_QSCALE;
|
||||
mp4v->encoder.context->global_quality = FF_QP2LAMBDA * tmedia_get_video_qscale(self->bl);
|
||||
|
||||
mp4v->encoder.context->thread_count = 1;
|
||||
mp4v->encoder.context->rtp_payload_size = MP4V_RTP_PAYLOAD_SIZE;
|
||||
mp4v->encoder.context->opaque = tsk_null;
|
||||
mp4v->encoder.context->bit_rate = (int) (bitRate * 0.80f);
|
||||
mp4v->encoder.context->bit_rate_tolerance = (int) (bitRate * 0.20f);
|
||||
//mp4v->encoder.context->bit_rate = (int) (bitRate * 0.80f);
|
||||
//mp4v->encoder.context->bit_rate_tolerance = (int) (bitRate * 0.20f);
|
||||
mp4v->encoder.context->profile = mp4v->profile>>4;
|
||||
mp4v->encoder.context->level = mp4v->profile & 0x0F;
|
||||
mp4v->encoder.context->gop_size = TMEDIA_CODEC_VIDEO(mp4v)->fps*2; // each 2 seconds
|
||||
|
@ -308,6 +296,7 @@ tsk_size_t tdav_codec_mp4ves_encode(tmedia_codec_t* self, const void* in_data, t
|
|||
#endif
|
||||
|
||||
mp4v->encoder.picture->pts = AV_NOPTS_VALUE;
|
||||
mp4v->encoder.picture->quality = mp4v->encoder.context->global_quality;
|
||||
ret = avcodec_encode_video(mp4v->encoder.context, mp4v->encoder.buffer, size, mp4v->encoder.picture);
|
||||
if(ret > 0){
|
||||
tdav_codec_mp4ves_encap(mp4v, mp4v->encoder.buffer, (tsk_size_t)ret);
|
||||
|
|
|
@ -114,6 +114,8 @@ tmedia_bandwidth_level_t;
|
|||
TINYMEDIA_API tmedia_type_t tmedia_type_from_sdp(const tsdp_message_t* sdp);
|
||||
TINYMEDIA_API int tmedia_parse_rtpmap(const char* rtpmap, char** name, int32_t* rate, int32_t* channels);
|
||||
TINYMEDIA_API const tmedia_video_size_t* tmedia_get_video_size(tmedia_chroma_t chroma, tsk_size_t size);
|
||||
TINYMEDIA_API int tmedia_get_video_quality(tmedia_bandwidth_level_t bl);
|
||||
#define tmedia_get_video_qscale tmedia_get_video_quality
|
||||
|
||||
TMEDIA_END_DECLS
|
||||
|
||||
|
|
|
@ -181,4 +181,16 @@ const tmedia_video_size_t* tmedia_get_video_size(tmedia_chroma_t chroma, tsk_siz
|
|||
}
|
||||
|
||||
return &tmedia_video_sizes[0];;
|
||||
}
|
||||
|
||||
// #retval: 1(best)-31(worst) */
|
||||
int tmedia_get_video_quality(tmedia_bandwidth_level_t bl)
|
||||
{
|
||||
switch(bl){
|
||||
case tmedia_bl_low:
|
||||
default: return 13;
|
||||
case tmedia_bl_medium: return 9;
|
||||
case tmedia_bl_hight: return 5;
|
||||
case tmedia_bl_unrestricted: return 1;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue