1
H.264/AVC / Re: x264 input buffering
« Last post by Aries86 on June 18, 2013, 09:18:37 PM »Its really amazing and nice.Thanx for sharing it.
lookupServerMediaSession(char const* streamName){
//
//lookUp for the session with the name
ServerMediaSession* sms = RTSPServer::lookupServerMediaSession(streamName);
if (!sms){
//create the session if this is't exist
sms = ServerMediaSession::createNew(envir(), streamName,"send server","sending the camera");
if (sms){
//add a subsession
sms->addSubsession( CameraServerMediaSubsession::createNew(envir(),true) );
}
}
return sms;
}FramedSource* CameraServerMediaSubsession::createNewStreamSource(unsigned clientSessionId,
unsigned& estBitrate)
{
//
return new CameraStream(this->envir());
}
RTPSink* CameraServerMediaSubsession::createNewRTPSink(Groupsock* rtpGroupsock,
unsigned char rtpPayloadTypeIfDynamic,
FramedSource* inputSource){
//
return CameraVideoRTPSink::createNew(this->envir(),
rtpGroupsock,
rtpPayloadTypeIfDynamic);
}
void CameraStream::doGetNextFrame(){
//
if (!isCurrentlyAwaitingData()) return; // we're not ready for the data yet
//get the size of the x264 frame
unsigned newFrameSize = cameraSize;
//create the frame
u_int8_t* newFrameDataStart = new u_int8_t[newFrameSize];
//copy the frame data
memcpy(newFrameDataStart,camera,cameraSize);
//This I found in the example
if (newFrameSize > fMaxSize) {
fFrameSize = fMaxSize;
fNumTruncatedBytes = newFrameSize - fMaxSize;
} else {
fFrameSize = newFrameSize;
}
//move the frame to FTO
memmove(fTo, newFrameDataStart, fFrameSize);
//Inform the reader it's now avaliable
FramedSource::afterGetting(this);
}
unsigned int widthXheight = frameDefault.total();//matYUV total is diferent from frameDefault
memcpy(pic_in.img.plane[0], matYUV.data, widthXheight);
memcpy(pic_in.img.plane[1], matYUV.data + widthXheight, (widthXheight / 4));
memcpy(pic_in.img.plane[2], matYUV.data + widthXheight + (widthXheight / 4), (widthXheight / 4));I test with X264CSP_RGB and x264 return a error message.
the encode function return a int with value == 850 (the first time). After this the i_frame_size is 120.
Is this the frame size?
How can I get the frame data to send?
1ยบ I compile latest x264 on minGW (version 125) and the compiler can't find "x264_encoder_open_125()";
int widthXheight = width * height;
x264_nal_t* pNals = NULL;
x264_param_default(¶m);
param.i_width = width;
param.i_height = height;
param.i_bframe = 3;
param.i_fps_num = fps;
param.i_fps_den = 1;
param.b_vfr_input = 0;
param.i_keyint_max = 250;
param.rc.i_bitrate = 1500;
param.i_scenecut_threshold = 40;
param.i_level_idc = 51;
unsigned long int frames=0u;
param.rc.i_rc_method = X264_RC_CRF;
param.rc.f_rf_constant = 25;
param.rc.f_rf_constant_max = 35;
x264_param_apply_profile(¶m, "high");
h = x264_encoder_open( ¶m );
//Cria a imagem x264
x264_picture_init( &pic_in );
x264_picture_alloc(&pic_in, X264_CSP_YV12, width, height);
pic_in.img.i_csp = X264_CSP_YV12;
pic_in.img.i_plane = 3;camYUVData[frameDefault.total()*3u]=0u;
//cria a matriz para o YUV
cv::Mat matYUV(frameDefault.size(),CV_8UC3,camYUVData);
//converte de RGB para YUV12
cv::cvtColor(frameRGBA, matYUV, CV_RGB2YUV_YV12);
unsigned int widthXheight = frameDefault.total();
memcpy(pic_in.img.plane[0], camYUVData, widthXheight);
memcpy(pic_in.img.plane[1], camYUVData + widthXheight, widthXheight >> 2);
memcpy(pic_in.img.plane[2], camYUVData + widthXheight + (widthXheight >> 2), widthXheight >> 2);
pic_in.i_type = X264_TYPE_KEYFRAME;
//comprime usando x264
i_frame_size = x264_encoder_encode( h, &nal, &i_nal, &pic_in, &pic_out );
printf(" i_frame_size == %u"
,i_frame_size
);
frames++;