[Libav-user] How to set the video and audio's timestamp

2016-08-09 Thread Tony
In my application , I used  ffmpeg to publish my camera and microphone 's av 
stream as rtmp stream to nginx server.
I use following code to publish stream:
void RtmpLiveEncoder::Run()
{
AVBitStreamFilterContext* aacbsfc =  av_bitstream_filter_init("aac_adtstoasc");
start_time = av_gettime();
while(1)
{
do
{
 int ret = 0;
 AVPacket pkt;
av_init_packet();
ret = av_read_frame(ifmt_ctx,);
if(ret<0 )
{
printf("read video frame failed\n");
break;
}


if(pkt.pts==AV_NOPTS_VALUE)
{
if(_frameduration==0)
{
pkt.dts = pkt.pts=(av_gettime()-start_time)/1000;
}
else
{
pkt.dts = pkt.pts = _lastvideopts;
pkt.duration = _frameduration;
pkt.pos = -1;
_lastvideopts += _frameduration;
}

}

if(av_write_frame(ofmt_ctx,)<0)
{
   printf("write video frame failed\n");
}

av_packet_unref();
}while(0);

do
{
if(!_hasaudio)
{
break;
}
if((_lastaudiopts-_lastvideopts)>0)
{
printf("the audio is faster than video, the audio pts is %d, the 
video pts is %d\n",_lastaudiopts,_lastvideopts);
break;
}

int ret = 0;
AVPacket audiopacket;
av_init_packet();
ret = av_read_frame(aifmt_ctx,);
if(ret<0)
{
  break;
}

AVStream* out_stream = ofmt_ctx->streams[1];
if(av_bitstream_filter_filter(aacbsfc, out_stream->codec, NULL, 
, , audiopacket.data, audiopacket.size, 0)<0)
{
printf("remove adts header failed\n");
}

if(av_bitstream_filter_filter(aacbsfc, out_stream->codec, NULL, 
>data, >size, audiopacket.buf->data, 
audiopacket.buf->size, 0)<0)
{
   printf("remove adts header failed\n");

}

audiopacket.stream_index=1;
audiopacket.dts = audiopacket.pts=_lastaudiopts;
audiopacket.duration = 
(double)1024/out_stream->codecpar->sample_rate*1000;
_lastaudiopts += audiopacket.duration;
audiopacket.pos = -1;


if(av_write_frame(ofmt_ctx,)<0)
{
printf("write audio failed.\n");
}

av_packet_unref();

}while(0);

}
I used vlc to access the hls stream, but after some minutes, the audio 
isn't sync any more.
How could I do?
THANKS IN ADVANCE!___
Libav-user mailing list
Libav-user@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/libav-user


Re: [Libav-user] Need to understand where demuxer for mp4 is hooked with h264 decoder ?

2016-08-09 Thread ssshukla26
Ok, will provide you the patch soon. Till then can you tell me that where
*demuxer for mp4* is hooked with the *default h264 decoder* in the source Or
its hooked via *isom.c* ? Can you please clear that doubt of mine !

P.S. :- My decoder is able to decode H264 files and it is using
"*AV_CODEC_ID_H264*" as *id*. 



--
View this message in context: 
http://libav-users.943685.n4.nabble.com/Libav-user-Need-to-understand-where-demuxer-for-mp4-is-hooked-with-h264-decoder-tp4662406p4662408.html
Sent from the libav-users mailing list archive at Nabble.com.
___
Libav-user mailing list
Libav-user@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/libav-user