该应用程序将相机输出保存到 mov 中。文件,然后将其转换为由 AVPacket 发送到 rtmp 服务器的 flv 格式。它每次在两个文件之间切换,一个由相机输出写入,另一个被发送。我的问题是一段时间后音频/视频不同步。
发送的第一个缓冲区始终是 100% 同步的,但一段时间后它会变得混乱。我相信它是一个 DTS-PTS 问题..
if(isVideo)
{
packet->stream_index = VIDEO_STREAM;
packet->dts = packet->pts = videoPosition;
videoPosition += packet->duration = FLV_TIMEBASE * packet->duration * videoCodec->ticks_per_frame * videoCodec->time_base.num / videoCodec->time_base.den;
}
else
{
packet->stream_index = AUDIO_STREAM;
packet->dts = packet->pts = audioPosition;
audioPosition += packet->duration = FLV_TIMEBASE * packet->duration / audioRate;
//NSLog(@"audio position = %lld", audioPosition);
}
packet->pos = -1;
packet->convergence_duration = AV_NOPTS_VALUE;
// This sometimes fails without being a critical error, so no exception is raised
if((code = av_interleaved_write_frame(file, packet)))
{
NSLog(@"Streamer::Couldn't write frame");
}
av_free_packet(packet);