SmutjeSanji
31st August 2010, 17:57
Hello,
I hope you can give me some hints. Till yet it was enough to use Google (to search forums etc) for learning but Iam really stuck right now and need your ideas.
-- What iam doing in general and what the problem is
Ive devoloped a server app so far that it is encoding a video with x264 - the video should be a live stream later, now I use videofiles -, packeting the encoded frames in NALs (x264) and sending it to a client who asks for a stream. And all steps happens in real time which means f.e. that after encoding 3-4 frames and packeting in NALs the server sends the NALs immediatly to the client.
The client is developed so far that it gets the stream - in form of NAL packets - and tries to decode it (with ffmpeg) - I give the NALs directly to ffmpeg without modifing them.
The problem is that on client side ffmpeg cant decode the NALs it gets - its telling me that no frame is found inside the NAL packets.
I know that you will answer me just in topics which involves x264, so Iam just asking you about that and not about the other parts of the program.
-- What I want to ask: Do I create NALs correctly?
As codebasis for the x264 encoding part of the server app I ve used x264.c and modified it so that the encoded frames are not written to harddisk anymore. Instead of that I create NAL packets of them and put them in a deque which another thread handles to send the NALs through network.
The modified "Encode_frame()" looks like this:
static int Encode_frame( x264_t *h, x264_picture_t *pic, int64_t *last_dts,
std::deque<NALBuffer>* nalQueue, pthread_mutex_t* lockQueue )
{
x264_picture_t pic_out;
x264_nal_t *nal;
int i_nal;
int i_frame_size = 0;
i_frame_size = x264_encoder_encode( h, &nal, &i_nal, pic, &pic_out );
if( i_frame_size < 0 )
{
fprintf( stderr, "x264 [error]: x264_encoder_encode failed\n" );
std::cout << "i_frame_size: " << i_frame_size << std::endl;
return -1;
}
if( i_frame_size )
{
for(int i = 0; i < i_nal; i++)
{
int long_startcode = !i || nal[i].i_type == NAL_SPS || nal[i].i_type == NAL_PPS;
NALBuffer nalBuffer;
nalBuffer.size = x264_nal_encode( h, nalBuffer.buffer, &nal[i], long_startcode );
nalBuffer.lastNAL = ((i+1) == i_nal) ? true : false;
// One NAL (of probably more) of a videoframe is created
pthread_mutex_lock(lockQueue);
nalQueue->push_front(nalBuffer);
pthread_mutex_unlock(lockQueue);
// NAL is added to (sending) queue - another thread is reading the queue and send the NALs
}
*last_dts = pic_out.i_dts;
}
return i_frame_size;
}
Its working. But as I ve said ffmpeg cant decode the NALs by telling me that there are no frames inside it.
The questions are now: Do the NALs are created correctly? Or do I have misconfigurations of ffmpeg on client side which cant decode the NALs? Or do the NALs get corrupt during transport - but right now Iam just testing at localhost, so that this shouldnt be the case?
:thanks:
I hope you can give me some hints. Till yet it was enough to use Google (to search forums etc) for learning but Iam really stuck right now and need your ideas.
-- What iam doing in general and what the problem is
Ive devoloped a server app so far that it is encoding a video with x264 - the video should be a live stream later, now I use videofiles -, packeting the encoded frames in NALs (x264) and sending it to a client who asks for a stream. And all steps happens in real time which means f.e. that after encoding 3-4 frames and packeting in NALs the server sends the NALs immediatly to the client.
The client is developed so far that it gets the stream - in form of NAL packets - and tries to decode it (with ffmpeg) - I give the NALs directly to ffmpeg without modifing them.
The problem is that on client side ffmpeg cant decode the NALs it gets - its telling me that no frame is found inside the NAL packets.
I know that you will answer me just in topics which involves x264, so Iam just asking you about that and not about the other parts of the program.
-- What I want to ask: Do I create NALs correctly?
As codebasis for the x264 encoding part of the server app I ve used x264.c and modified it so that the encoded frames are not written to harddisk anymore. Instead of that I create NAL packets of them and put them in a deque which another thread handles to send the NALs through network.
The modified "Encode_frame()" looks like this:
static int Encode_frame( x264_t *h, x264_picture_t *pic, int64_t *last_dts,
std::deque<NALBuffer>* nalQueue, pthread_mutex_t* lockQueue )
{
x264_picture_t pic_out;
x264_nal_t *nal;
int i_nal;
int i_frame_size = 0;
i_frame_size = x264_encoder_encode( h, &nal, &i_nal, pic, &pic_out );
if( i_frame_size < 0 )
{
fprintf( stderr, "x264 [error]: x264_encoder_encode failed\n" );
std::cout << "i_frame_size: " << i_frame_size << std::endl;
return -1;
}
if( i_frame_size )
{
for(int i = 0; i < i_nal; i++)
{
int long_startcode = !i || nal[i].i_type == NAL_SPS || nal[i].i_type == NAL_PPS;
NALBuffer nalBuffer;
nalBuffer.size = x264_nal_encode( h, nalBuffer.buffer, &nal[i], long_startcode );
nalBuffer.lastNAL = ((i+1) == i_nal) ? true : false;
// One NAL (of probably more) of a videoframe is created
pthread_mutex_lock(lockQueue);
nalQueue->push_front(nalBuffer);
pthread_mutex_unlock(lockQueue);
// NAL is added to (sending) queue - another thread is reading the queue and send the NALs
}
*last_dts = pic_out.i_dts;
}
return i_frame_size;
}
Its working. But as I ve said ffmpeg cant decode the NALs by telling me that there are no frames inside it.
The questions are now: Do the NALs are created correctly? Or do I have misconfigurations of ffmpeg on client side which cant decode the NALs? Or do the NALs get corrupt during transport - but right now Iam just testing at localhost, so that this shouldnt be the case?
:thanks: