[Libav-user] Real time camera IP RTSP H264
Renaud BOBIN
renaud.bobin at subsea-tech.com
Mon Feb 9 09:54:42 CET 2015
Hi,
I have a problem to get the video of my IP camera in real time or almost no
latency.
The camera stream an H264 full HD video (with no audio) on a rtsp link;
On the embedded web server in Internet Explorer with the ActiveX provided by
the camera, I got not latency.
On mplayer I got no latency (so I know it is possible).
But with my own program I got 300-400ms of latency.
I tried many things but is always the same results.
Im working on windows, with the Qt4 framework.
And I use SDL 1.2.1 for the display.
Im using ffmpeg-20150122.
I was following the Drangers tutorials, both single and multi thread
tutorial.
I even tried to get the packet with live555 and decode it with ffmpeg and
always the same results.
For single thread :
<code>
if(avformat_open_input(&pFormatCtx,serveur_ip,NULL, 0))
{
qDebug() << "c_ffmpeg_rtsp : " << "Pas de connexion à la
caméra" << endl;
return false;
}
if(avformat_find_stream_info(pFormatCtx,NULL))
{
qDebug() << "c_ffmpeg_rtsp : " << "Pas d'information
sur la stream de la caméra" << endl;
return false;
}
for(unsigned int i=0; i < pFormatCtx->nb_streams; i++)
{
if(pFormatCtx->streams[i]->codec->codec_type==AVMEDIA_TYPE_VIDEO)
{
videoStream=i;
pStream = pFormatCtx->streams[i];
break;
}
}
if(videoStream==-1)
{
qDebug() << "c_ffmpeg_rtsp : " << "Pas de flux video trouvé
sur la caméra" << endl;
return false;
}
pCodecCtx=pFormatCtx->streams[videoStream]->codec;
pCodec=avcodec_find_decoder(pCodecCtx->codec_id);
if(pCodec==NULL)
{
qDebug() << "c_ffmpeg_rtsp : " << "Codec inexistant pour
la caméra" << endl;
}
else
qDebug() << "c_ffmpeg_rtsp : " << "Codec found : " <<
pCodec->long_name << endl;
if(avcodec_open2(pCodecCtx, pCodec,NULL)<0)
{
qDebug() << "c_ffmpeg_rtsp : " << "Erreur d'ouverture du
codec pour la caméra" << endl;
return false;
}
// Hack to correct wrong frame rates that seem to be generated by some
// codecs
if(pCodecCtx->time_base.num>1000 && pCodecCtx->time_base.den==1)
pCodecCtx->time_base.den=1000;
pFrame=avcodec_alloc_frame();
pFrameRGB=avcodec_alloc_frame();
if(pFrameRGB==NULL)
{
qDebug() << "c_ffmpeg_rtsp : " << "Erreur Frame vide" << endl;
return false;
}
numBytes=avpicture_get_size(AV_PIX_FMT_RGB24,
pCodecCtx->width,pCodecCtx->height);
buffer=new uint8_t[numBytes];
avpicture_fill((AVPicture *)pFrameRGB, buffer,
PIX_FMT_YUV420P,pCodecCtx->width, pCodecCtx->height);
int w = pCodecCtx->width;
int h = pCodecCtx->height;
img_convert_affic = sws_getCachedContext(img_convert_affic,w, h,
pCodecCtx->pix_fmt, w, h, PIX_FMT_YUV420P, SWS_BICUBIC, NULL, NULL, NULL);
if(img_convert_affic == NULL)
{
qDebug() << "c_ffmpeg_rtsp : " << "Cannot initialize the
conversion context!" << endl;
return false;
}
screen = SDL_SetVideoMode(pCodecCtx->width, pCodecCtx->height, 0,
0);
if(!screen)
{
qDebug() << "SDL: could not set video mode - exiting" << endl;
return false;
}
bmp = SDL_CreateYUVOverlay(pCodecCtx->width,
pCodecCtx->height,SDL_YV12_OVERLAY, screen);
return true;
</code>
<code>
While( !iquit)
{
int result = av_read_frame(pFormatCtx, &packet);
if(result < 0)
{
qDebug() << "c_ffmpeg_rtsp : " << "packet non recu" << endl;
}
else
{
if(packet.stream_index == videoStream)
{
int gotPic = 0;
int checkSize = avcodec_decode_video2(pCodecCtx, pFrame, &gotPic, &packet);
if(gotPic)
{
ret = sws_scale(img_convert_affic, pFrame->data,
pFrame->linesize, 0, pCodecCtx->height, pFrameRGB->data,
pFrameRGB->linesize);
SDL_Rect rect;
SDL_LockYUVOverlay(bmp);
pFrameRGB->data[0] = bmp->pixels[0];
pFrameRGB->data[1] = bmp->pixels[2];
pFrameRGB->data[2] = bmp->pixels[1];
pFrameRGB->linesize[0] = bmp->pitches[0];
pFrameRGB->linesize[1] = bmp->pitches[2];
pFrameRGB->linesize[2] = bmp->pitches[1];
SDL_UnlockYUVOverlay(bmp);
rect.x = 0;
rect.y = 0;
rect.w = pCodecCtx->width;
rect.h = pCodecCtx->height;
SDL_DisplayYUVOverlay(bmp, &rect);
}
}
av_free_packet(&packet);
}
<\code>
When I use live555, the camera send the SDP description :
[URL:"rtsp://192.168.2.168:554/0/"]: Got a SDP description:
v=0
o=- 1422895493704585 1 IN IP4 0.0.0.0
s=RTSP/RTP stream from IPNC
i=0
t=0 0
a=tool:LIVE555 Streaming Media v2010.07.29
a=type:broadcast
a=control:*
a=range:npt=0-
a=x-qt-text-nam:RTSP/RTP stream from IPNC
a=x-qt-text-inf:0
m=video 0 RTP/AVP 96
c=IN IP4 0.0.0.0
b=AS:6000
a=rtpmap:96 H264/90000
a=framerate:30.00; a=fmtp:96
packetization-mode=1;profile-level-id=64001F;sprop-
parameter-sets=Z2QAKK2EBUViuKxUdCAqKxXFYqOhAVFYrisVHQgKisVxWKjoQFRWK4rFR0ICo
rFcV
io6ECSFITk8nyfk/k/J8nm5s00IEkKQnJ5Pk/J/J+T5PNzZprQDwBE/LKkAAAMAeAAAHCBgQAAW4
2AAB
m/yve+F4RCNQAAAAAE=,aO48sA==
a=control:track1
What can I do to improve the latency ?
Cordialement,
Renaud BOBIN
Project Engineer
Logo-miniSUBSEA TECH
Marine and Underwater Technologies
167 Plage de l'Estaque 13016 Marseille - France
Tel: +33 (0) 4 91 51 76 71
Web: <http://www.subsea-tech.com/> www.subsea-tech.com
---
Ce courrier électronique ne contient aucun virus ou logiciel malveillant parce que la protection avast! Antivirus est active.
http://www.avast.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://ffmpeg.org/pipermail/libav-user/attachments/20150209/5d168055/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/png
Size: 5531 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/libav-user/attachments/20150209/5d168055/attachment.png>
More information about the Libav-user
mailing list