Detecting end of GOP

Hi,

I’ve distilled what I think is the essence of encoding from the CUDA sample (AppEncCuda) in the psuedo-code below. If, for example, I wanted 1 second GOPs (such that my output consists of a series of files containing each 1 second GOP), and assuming I had configured the encoder appropriately, is this what the loop would look like? If I was running at 60, I submit 60 frames and then on the 60th I call EndEncode? Or do I simply keep running frames through the encoder and discover when the end of the GOP has arrived in some other manner? Perhaps, for example, I should count events and when I reach 60 my output buffer will contain the next GOP?

Any advice you can give me would be greatly appreciated.

Thank you.

while (true)
{
// Acquire a new frame

...

if (acquired_a_new_frame)
{	    
      ...

     // Encode it.

     enc.EncodeFrame(packet);
}
else
{
     ...

     // Last frame.
    
     enc.EndEncode(packet);
}

 // Write packets...

...

if (!acquired_a_new_frame)
{
     // Finished

     break;
}

}