On H.264 stream EOF, the eof_reached flag is set, but av_read_frame() still provides a frame, so check the flag only afterwards. As a side-effect, it also fixes a memory leak (the very last packet was not unref).
On H.264 stream EOF, the eof_reached flag is set, but av_read_frame() still provides a frame, so check the flag only afterwards. As a side-effect, it also fixes a memory leak (the very last packet was not unref).