ios - Audio and video pts is not sync ffmpeg -
i'm trying write sort of rtsp ios streamer based on ffmpeg project. basically, i've got project https://github.com/durfu/dfurtspplayer. big creator of project, unfortunately has problems playing of streams decided write streaming player myself using author's developments.
of course, correctly stream playing need sync audio video , can comparing pts of frames. problem in huge gap between audio , video pts. have thoughts i'm getting pts audio , video wrong, couldn't find actual problem own. here's function:
- (void) decodeframe { int framefinished = 0; avpacket newpacket; while (framefinished == 0 && av_read_frame(formatctx, &newpacket) >= 0) { if (newpacket.stream_index == videostream) { avcodec_decode_video2(videocodecctx, videoframe, &framefinished, &newpacket); [self convertframetorgb]; uiimage *newimage = [self currentimage]; if (newpacket.pts != av_nopts_value) { newpacket.pts += av_rescale_q(0, av_time_base_q, formatctx->streams[audiostream]->time_base); } unsigned long tempvideopts = newpacket.pts; double presenttime = tempvideopts * av_q2d(formatctx->streams[videostream]->time_base); [_zfbuffer addnewimage:newimage withpts:tempvideopts withpresenttime:presenttime]; nslog(@"tempvideopts = %lu", tempvideopts); } else if (newpacket.stream_index == audiostream) { nsmutabledata *sounddata = [[nsmutabledata alloc] initwithbytes:newpacket.data length:newpacket.size]; if (newpacket.pts != av_nopts_value) { newpacket.pts += av_rescale_q(0, av_time_base_q, formatctx->streams[audiostream]->time_base); } unsigned long tempaudiopts = newpacket.pts; double presenttime = tempaudiopts * av_q2d(formatctx->streams[audiostream]->time_base); [_zfbuffer addnewsound:sounddata withpts:tempaudiopts withpresenttime:presenttime]; nslog(@"tempaudiopts = %lu", tempaudiopts); } av_free_packet(&newpacket); if(!streamisplaying && [_zfbuffer bufferedtime:formatctx->streams[audiostream]->time_base] > 2.0f) { streamisplaying = yes; //launch audio translation if (emptyaudiobuffer != nil) { [self unpacknextsound:emptyaudiobuffer]; } } } } i expecting pts more or less equal, here's log
2016-01-05 22:03:03.918 dfurtspplayer[1569:76194] tempvideopts = 180000 2016-01-05 22:03:03.959 dfurtspplayer[1569:76194] tempvideopts = 183780 2016-01-05 22:03:04.001 dfurtspplayer[1569:76194] tempvideopts = 187470 2016-01-05 22:03:04.042 dfurtspplayer[1569:76194] tempaudiopts = 58368 2016-01-05 22:03:04.042 dfurtspplayer[1569:76194] tempvideopts = 191250 2016-01-05 22:03:04.084 dfurtspplayer[1569:76194] tempvideopts = 195030 2016-01-05 22:03:04.126 dfurtspplayer[1569:76194] tempaudiopts = 59392 2016-01-05 22:03:04.126 dfurtspplayer[1569:76194] tempvideopts = 198720 2016-01-05 22:03:04.168 dfurtspplayer[1569:76194] tempvideopts = 202500 2016-01-05 22:03:04.209 dfurtspplayer[1569:76194] tempvideopts = 206280 2016-01-05 22:03:04.250 dfurtspplayer[1569:76194] tempaudiopts = 60416 2016-01-05 22:03:04.250 dfurtspplayer[1569:76194] tempaudiopts = 61440 2016-01-05 22:03:04.251 dfurtspplayer[1569:76194] tempvideopts = 209970 2016-01-05 22:03:04.292 dfurtspplayer[1569:76194] tempvideopts = 213750 2016-01-05 22:03:04.334 dfurtspplayer[1569:76194] tempaudiopts = 62464 2016-01-05 22:03:04.335 dfurtspplayer[1569:76194] tempvideopts = 217530 2016-01-05 22:03:04.375 dfurtspplayer[1569:76194] tempvideopts = 221220 2016-01-05 22:03:04.417 dfurtspplayer[1569:76194] tempaudiopts = 63488 2016-01-05 22:03:04.418 dfurtspplayer[1569:76194] tempvideopts = 225000 2016-01-05 22:03:04.459 dfurtspplayer[1569:76194] tempvideopts = 228780 2016-01-05 22:03:04.501 dfurtspplayer[1569:76194] tempvideopts = 232470 2016-01-05 22:03:04.541 dfurtspplayer[1569:76194] tempaudiopts = 64512 2016-01-05 22:03:04.542 dfurtspplayer[1569:76194] tempvideopts = 236250 2016-01-05 22:03:04.584 dfurtspplayer[1569:76194] tempvideopts = 240030 2016-01-05 22:03:04.626 dfurtspplayer[1569:76194] tempaudiopts = 65536 2016-01-05 22:03:04.626 dfurtspplayer[1569:76194] tempvideopts = 243720 2016-01-05 22:03:04.668 dfurtspplayer[1569:76194] tempvideopts = 247500 2016-01-05 22:03:04.709 dfurtspplayer[1569:76194] tempvideopts = 251280 2016-01-05 22:03:04.750 dfurtspplayer[1569:76194] tempaudiopts = 66560 2016-01-05 22:03:04.750 dfurtspplayer[1569:76194] tempvideopts = 254970 2016-01-05 22:03:04.792 dfurtspplayer[1569:76194] tempvideopts = 258750 2016-01-05 22:03:04.834 dfurtspplayer[1569:76194] tempaudiopts = 67584 2016-01-05 22:03:04.834 dfurtspplayer[1569:76194] tempaudiopts = 68608 if facing problem please me out. understand i'm missing can't understand exactly. appreciate time , help.
Comments
Post a Comment