I have this situation: a video must be processed frame by frame but as frames are being processed, the output have to be write to file in sequence.

I want to fire asynchronous blocks using dispatch_async to a concurrent queue to speed the process but because this queue is asynchronous I don't see how I will coordinate to write the frames serially to the output.

Suppose this situation: frames 1, 2, 3, 4 and 5 are sent to concurrent queues for processing. Because any block can finish at any time, frame 4 may be the first to finish, followed by 5, 3, 1, 2. So how will I manage to write the frames in the sequential order to the output?

I have a code like this:

dispatch_queue_t aQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);

while (true) {

    video >> frame;  // read a frame from the video

    dispatch_async(aQueue, ^{
         processVideo(frame, outputFrame);
         writeToVideo(outputFrame); // this is here just to show what needs to be done

    // bla bla


any clues?


Related posts

Recent Viewed