I am currently working with FFmpeg in a video streaming solution over RTP. What bugs me is how to stream at a correct framerate. Currently I am using a sleep in the main streaming loop:
while (av_read_frame (input_format_ctx, &packet) >= 0) { // Read a video packet as long as EOF is not reached or an error occurr
if(packet.stream_index == 0) {
if (av_interleaved_write_frame(output_format_ctx, &packet) < 0) { // Write the packet to the output stream
av_packet_unref(&packet); // Wipe the packet
av_free_packet(&packet); // Release the packet and finishes if a problem occured
break;
}
av_packet_unref(&packet); // Wipe the packet
av_free_packet(&packet); // Release the packet
}
current_time = getSystemTime(); // Get system time
adaptativeSleep ((last_time + 1/(output_framerate)) - current_time); // Sleep according to framerate
last_time = getSystemTime(); // Get finish
}
Is there a correct way of letting FFmpeg handle the framerate?
Thanks in advance
P.S.: I only remux the stream, as a result FFmpeg runs through the file in a few seconds witought my "sleep".
Aucun commentaire:
Enregistrer un commentaire