Purpose: Electronic portal imaging devices (EPIDs) have been studied and used for pretreatment and in-vivo dosimetry applications for many years. The application of EPIDs for dosimetry in arc treatments requires accurate characterization of the mechanical sag of the EPID and gantry during rotation. Several studies have investigated the effects of gravity on the sag of these systems but each have limitations. In this study, an easy experiment setup and accurate algorithm have been introduced to characterize and correct for the effect of EPID and gantry sag during arc delivery. Methods: Three metallic ball bearings were used as markers in the beam: two of them fixed to the gantry head and the third positioned at the isocenter. EPID images were acquired during a 360 gantry rotation in cine imaging mode. The markers were tracked in EPID images and a robust in-house developed MATLAB code was used to analyse the images and find the EPID sag in three directions as well as the EPID gantry sag by comparison to the reference gantry zero image. The algorithm results were then tested against independent methods. The method was applied to compare the effect in clockwise and counter clockwise gantry rotations and different source-to-detector distances (SDDs). The results were monitored for one linear accelerator over a course of 15 months and six other linear-accelerators from two treatment centers were also investigated using this method. The generalized shift patterns were derived from the data and used in an image registration algorithm to correct for the effect of the mechanical sag in the system. The Gamma evaluation (3, 3 mm) technique was used to investigate the improvement in alignment of cine EPID images of a fixed field, by comparing both individual images and the sum of images in a series with the reference gantry zero image. Results: The mechanical sag during gantry rotation was dependent on the gantry angle and was larger in the in-plane direction, although the patterns were not identical for various linear-accelerators. The reproducibility of measurements was within 0.2 mm over a period of 15 months. The direction of gantry rotation and SDD did not affect the results by more than 0.3 mm. Results of independent tests agreed with the algorithm within the accuracy of the measurement tools. When comparing summed images, the percentage of points with Gamma index 1 increased from 85.4 to 94.1 after correcting for the EPID sag, and to 99.3 after correction for gantry EPID sag. Conclusions: The measurement method and algorithms introduced in this study use cine-images, are highly accurate, simple, fast, and reproducible. It tests all gantry angles and provides a suitable automatic analysis and correction tool to improve EPID dosimetry and perform comprehensive linac QA for arc treatments.