Andrey, I'm not sure what you suggest would work since your solution seems to assume that video and audio is synced directly out of the demuxer, which isn't always the case. Also how would cases where "(total_audio_samples) % (audio_samples_per_frame * total_frames) != 0" work when looping?