2012-11-21 5 views
10

Die App speichert die Kameraausgabe in einem mov. Datei, dann drehen Sie es in FLV-Format, das von AVPacket an rtmp Server gesendet. Es wechselt jedes Mal zwischen zwei Dateien, eine wird von der Kamera ausgegeben und die andere wird gesendet. Mein Problem ist, dass das Audio/Video nach einer Weile nicht mehr synchron ist.FFMpeg Nicht synchronisiertes Audio/Video in iOS-Anwendung

Der erste gesendete Puffer ist immer 100% sync, aber nach einer Weile wird es durcheinander gebracht. Ich glaube es ist ein DTS-PTS Problem ..

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); 

Antwort

0

Sie diese Probe recherchieren: http://unick-soft.ru/art/files/ffmpegEncoder-vs2008.zip

Aber diese Probe ist für Windows.

In diesem Beispiel pts Ich verwende nur für Audio-Stream:

if (pVideoCodec->coded_frame->pts != AV_NOPTS_VALUE) 
    { 
    pkt.pts = av_rescale_q(pVideoCodec->coded_frame->pts, 
     pVideoCodec->time_base, pVideoStream->time_base); 
    }