# Patent

## Title
Methods for determining frame resolution and apparatuses using the same

## Abstract

The invention introduces a method for determining frame resolution, performed by a processing unit, which contains at least the following steps: obtaining a YUV video file, which contains a video stream; selecting a plurality of frame resolutions from a frame resolution table as frame resolution candidates according to the length of the video stream; repeatedly executing a loop m times, and in each iteration, obtaining at least two frames of the video stream according to one unexamined frame resolution candidate and calculating the correlation between the obtained frames, wherein m represents the quantity of frame resolution candidates; determining the best frame resolution from the frame resolution candidates according to the calculated correlations; and outputting the best frame resolution, thereby enabling a video decoder to segment the video stream into frames according to the best frame resolution and decode the segmented frames.

## Background
CROSS REFERENCE TO RELATED APPLICATIONS
This application claims the benefit of China Patent Application No. 201610813992.9, filed on Sep. 9, 2016, the entirety of which is incorporated by reference herein.
BACKGROUND
Technical Field
The present invention relates to video processing, and in particular, to methods for determining frame resolution and apparatuses using the same.
Description of the Related Art
The frame resolution is the number of distinct pixels in each dimension that can be displayed. It is usually quoted as width×height, with the units in pixels: for example, “1024×768” means that the width is 1024 pixels and the height is 768 pixels. However, the YUV video stream may not contain information pertaining to its frame resolution. The YUV video stream cannot be parsed or played back by a video decoder when its frame resolution is unknown. Thus, it is desirable to have methods for determining frame resolution and apparatuses using the same to address the aforementioned drawbacks.
BRIEF SUMMARY
An embodiment of the invention introduces a method for determining frame resolution, performed by a processing unit, which contains at least the following steps: obtaining a YUV video file, which comprises a video stream; selecting a plurality of frame resolutions from a frame resolution table as frame resolution candidates according to the length of the video stream; repeatedly executing a loop m times, and in each iteration, obtaining at least two frames of the video stream according to one unexamined frame resolution candidate and calculating the correlation between the obtained frames, wherein m represents the quantity of frame resolution candidates; determining the best frame resolution from the frame resolution candidates according to the calculated correlations; and outputting the best frame resolution, thereby enabling a video decoder to segment the video stream into frames according to the best frame resolution and decode the segmented frames.
An embodiment of the invention introduces an apparatus for determining frame resolution, at least containing a processing unit. The processing unit obtains a YUV video file, which comprises a video stream, selects a plurality of frame resolutions from a frame resolution table as frame resolution candidates according to the length of the video stream, and repeatedly executes a loop m times. The processing unit, in each iteration, obtains at least two frames of the video stream according to one unexamined frame resolution candidate and calculates the correlation between the obtained frames, wherein m represents the quantity of frame resolution candidates, determines the best frame resolution from the frame resolution candidates according to the calculated correlations; and outputs the best frame resolution, thereby enabling a video decoder to segment the video stream into frames according to the best frame resolution and decode the segmented frames.
A detailed description is given in the following embodiments with reference to the accompanying drawings.



BRIEF DESCRIPTION OF THE DRAWINGS
The present invention can be fully understood by reading the subsequent detailed description and examples with references made to the accompanying drawings, wherein:
FIG. 1 is the system architecture of a computer apparatus according to an embodiment of the invention;
FIG. 2 is a flowchart illustrating a method for determining frame resolution according to an embodiment of the invention; and
FIGS. 3A and 3B are flowcharts illustrating a method for determining frame resolution according to an embodiment of the invention.



DETAILED DESCRIPTION
The following description is of the best-contemplated mode of carrying out the invention. This description is made for the purpose of illustrating the general principles of the invention and should not be taken in a limiting sense. The scope of the invention is best determined by reference to the appended claims.
The present invention will be described with respect to particular embodiments and with reference to certain drawings, but the invention is not limited thereto and is only limited by the claims. It will be further understood that the terms “comprises,” “comprising,” “includes” and/or “including,” when used herein, specify the presence of stated features, integers, steps, operations, elements, and/or components, but do not preclude the presence or addition of one or more other features, integers, steps, operations, elements, components, and/or groups thereof.
Use of ordinal terms such as “first”, “second”, “third”, etc., in the claims to modify a claim element does not by itself connote any priority, precedence, or order of one claim element over another or the temporal order in which acts of a method are performed, but are used merely as labels to distinguish one claim element having a certain name from another element having the same name (but for use of the ordinal term) to distinguish the claim elements.
FIG. 1 is the system architecture of a computer apparatus according to an embodiment of the invention. The processing unit 110 can be implemented in numerous ways, such as with dedicated hardware, or with general-purpose hardware (e.g., a single processor, multiple processors or graphics processing units capable of parallel computations, or others) that is programmed using microcode or software instructions to perform the functions recited herein. The processing unit 110 may contain an ALU (Arithmetic and Logic Unit) and a bit shifter. The ALU is responsible for performing a Boolean operation, such as AND, OR, NOT, NAND, NOR, XOR, XNOR, etc. The bit shifter is responsible for performing a bitwise shift and a bit rotation. The system architecture further includes a memory 150 for storing necessary data in execution, such as variables, data tables, data abstracts, or others, and a storage unit 140 for storing a wide range of electronic files, such as a frame resolution table, YUV video files, and others. The memory may be a DRAM (Dynamic Random Access Memory) and the storage device 140 may be a hard disk drive, an optical disk drive, a SSD (solid state disk) drive, or others. A communications interface 160 is included in the system architecture and the processing unit 110 can thereby communicate with other electronic apparatuses. The communications interface 160 may be a LAN (Local Area Network) module, a WLAN (Wireless Local Area Network) module, or others with the communications capability. The system architecture further includes one or more input devices 130 to receive user input, such as a keyboard, a mouse, a touch panel, or others. A user may press hard keys on the keyboard to input characters, control a mouse pointer on a display by operating the mouse, or control an executed application with one or more gestures made on the touch panel. The gestures include, but are not limited to, a single-click, a double-click, a single-finger drag, and a multiple finger drag. A display unit 120, such as a TFT-LCD (Thin film transistor liquid-crystal display) panel, an OLED (Organic Light-Emitting Diode) panel, or another display unit, may also be included to display input letters, alphanumeric characters and symbols, dragged paths, drawings, or screens provided by an application for a user to view.
FIG. 2 is a flowchart illustrating a method for determining frame resolution according to an embodiment of the invention. The method is implemented by the processing unit 110 when loading and executing relevant program codes to determine the frame resolution of a YUV video file. Firstly, a YUV video file is obtained (step S210). The YUV video file may be read from the storage device 140 or obtained from another electronic apparatus via the communications interface 160. The YUV video file contains a header and a video stream organized in a format such as YUV444, YUV420, YUV422, etc. It should be noted that the header does not contain frame resolution information. Next, a plurality of frame resolutions are selected from the frame resolution table as frame resolution candidates according to the length of the video stream of the YUV video file (step S220). The processing unit 110 may read the frame resolution table from the storage device 140. An exemplary frame resolution table is shown in table 1:











TABLE 1







Standard
Width (W)
Height (H)




















SVGA
800
600



WSVGA
1024
600



XGA
1024
768



XGA+
1152
864



WXGA
1280
720



WXGA
1280
768



WXGA
1280
800



SXGA
1280
1024



HD
1360
768



HD
1366
768



WXGA+
1440
900



HD+
1600
900



UXGA
1600
1200



WSXGA+
1680
1050



FHD
1920
1080



WUXGA
1920
1200



WQHD
2560
1440



WQXGA
2560
1600



UHD
3840
2160










The frame resolution table may be implemented in an electronic file of a file system, one or more data tables of a relational database, an electronic document of a document database, etc. The frame resolution table contains multiple records and each record stores frame resolution information for a standard, including width, height, and the like. Specifically, in step S220, it is determined whether each frame resolution of the frame resolution table is a frame resolution candidate using Equation (1):

L/Wj/Hj/Rt=nj. . . rj  (1)

L represents the length of the video stream of the YUV video file (in bytes), Wj represents the width of the jth frame resolution, Hj represents the height of the jth frame resolution, Rt represents a default value associated with a particular video stream format, nj represents the calculated quotient associated with the jth frame resolution, and rj represents the calculated remainder associated with the jth frame resolution. For example, Rt may be set to 1 when the video stream format is YUV444. The variable j is an integer between 1 and k, and k represents the quantity of all frame resolutions of the frame resolution table. Rt may be set to 1 when the video stream format is YUV422. Rt may be set to 1.25 when the video stream format is YUV420. The processing unit 110 treats the frame resolutions with the calculated remainders being 0 as the frame resolution candidates. Next, the processing unit 110 determines whether the generation of the frame resolution candidates is successful (step S230). Specifically, the generation of the frame resolution candidates is unsuccessful if no frame resolution candidate can be found. When it is unsuccessful (the “No” path of step S230), the obtained file is designated as an incorrect YUV video file (step S240). In step S240, the processing unit 110 may store information indicates that this file is not correct YUV video file.

Since information carried between frames has dependency, the correlations between each two divided frames from the video stream are high if a correct frame resolution is used to perform the division. Embodiments of the invention anticipate the correct frame resolution for a YUV video file in view of the aforementioned characteristics. Specifically, the generation of frame resolution candidates is successful (the “Yes” path of step S230), a loop is repeated executed m times, and in each iteration, data of at least two frames of the video stream is obtained according to one unexamined frame resolution candidate, and the correlation between the obtained frames is calculated, where m represents the quantity of frame resolution candidates (step S250). It is attempted to select one from the frame resolution candidates as the best frame resolution according to the calculated correlations (step S260) and determined whether the selection is successful (step S270). If so (the “Yes” path of step S270), the best frame resolution is output, thereby enabling a video decoder to segment the video stream into frames according to the best frame resolution and decode the segmented frames (step S280). In step S280, the best frame resolution is written into the header or output to the video decoder. Otherwise (the “No” path of step S270), the obtained file is designated as an incorrect YUV video file (step S240). In some embodiments of each iteration of step S250, the processing unit 110 may calculate three correlations between the pth frame and the (p+1)th frame. The first correlation indicates the similar extent of Y, U and V components between this frame and the next frame and a higher value indicates a higher similarity than a lower one. The first correlation may be calculated in Equation (2):




  
    
      
        
          R
          ⁢
          
            
          
          ⁢
          1
        
        =
        
          
            
              
                
                  
                    
                      Σ
                      ⁡
                      
                        (
                        
                          
                            
                              X
                              i
                            
                            ⁡
                            
                              (
                              Y
                              )
                            
                          
                          -
                          
                            
                              X
                              ⁡
                              
                                (
                                Y
                                )
                              
                            
                            _
                          
                        
                        )
                      
                    
                    ⁢
                    
                      (
                      
                        
                          
                            Z
                            i
                          
                          ⁡
                          
                            (
                            Y
                            )
                          
                        
                        -
                        
                          
                            Z
                            ⁡
                            
                              (
                              Y
                              )
                            
                          
                          _
                        
                      
                      )
                    
                  
                  +
                
              
            
            
              
                
                  
                    
                      
                        
                          Σ
                          ⁢
                          
                            (
                            
                              
                                
                                  X
                                  i
                                
                                ⁡
                                
                                  (
                                  U
                                  )
                                
                              
                              -
                              
                                
                                  X
                                  ⁡
                                  
                                    (
                                    U
                                    )
                                  
                                
                                _
                              
                            
                            )
                          
                          ⁢
                          
                            (
                            
                              
                                
                                  Z
                                  i
                                
                                ⁡
                                
                                  (
                                  U
                                  )
                                
                              
                              -
                              
                                
                                  Z
                                  ⁡
                                  
                                    (
                                    U
                                    )
                                  
                                
                                _
                              
                            
                            )
                          
                        
                        +
                      
                    
                  
                  
                    
                      
                        
                          Σ
                          ⁡
                          
                            (
                            
                              
                                
                                  X
                                  i
                                
                                ⁡
                                
                                  (
                                  V
                                  )
                                
                              
                              -
                              
                                
                                  X
                                  ⁡
                                  
                                    (
                                    V
                                    )
                                  
                                
                                _
                              
                            
                            )
                          
                        
                        ⁢
                        
                          (
                          
                            
                              
                                Z
                                i
                              
                              ⁡
                              
                                (
                                V
                                )
                              
                            
                            -
                            
                              
                                Z
                                ⁡
                                
                                  (
                                  V
                                  )
                                
                              
                              _
                            
                          
                          )
                        
                      
                    
                  
                
              
            
          
          
            
              
                
                  
                    
                      
                        Σ
                        ⁡
                        
                          (
                          
                            
                              
                                X
                                i
                              
                              ⁡
                              
                                (
                                Y
                                )
                              
                            
                            -
                            
                              
                                X
                                ⁡
                                
                                  (
                                  Y
                                  )
                                
                              
                              _
                            
                          
                          )
                        
                      
                      2
                    
                    ⁢
                    
                      
                        Σ
                        ⁡
                        
                          (
                          
                            
                              
                                Z
                                i
                              
                              ⁡
                              
                                (
                                Y
                                )
                              
                            
                            -
                            
                              
                                Z
                                ⁡
                                
                                  (
                                  Y
                                  )
                                
                              
                              _
                            
                          
                          )
                        
                      
                      2
                    
                    ⁢
                    
                      
                        Σ
                        ⁡
                        
                          (
                          
                            
                              
                                X
                                i
                              
                              ⁡
                              
                                (
                                U
                                )
                              
                            
                            -
                            
                              
                                X
                                ⁡
                                
                                  (
                                  U
                                  )
                                
                              
                              _
                            
                          
                          )
                        
                      
                      2
                    
                  
                
              
              
                
                  
                    
                      
                        Σ
                        ⁡
                        
                          (
                          
                            
                              
                                Z
                                i
                              
                              ⁡
                              
                                (
                                U
                                )
                              
                            
                            -
                            
                              
                                Z
                                ⁡
                                
                                  (
                                  U
                                  )
                                
                              
                              _
                            
                          
                          )
                        
                      
                      2
                    
                    ⁢
                    
                      
                        Σ
                        ⁡
                        
                          (
                          
                            
                              
                                X
                                i
                              
                              ⁡
                              
                                (
                                V
                                )
                              
                            
                            -
                            
                              
                                X
                                ⁡
                                
                                  (
                                  V
                                  )
                                
                              
                              _
                            
                          
                          )
                        
                      
                      2
                    
                    ⁢
                    
                      
                        Σ
                        ⁡
                        
                          (
                          
                            
                              
                                Z
                                i
                              
                              ⁡
                              
                                (
                                V
                                )
                              
                            
                            -
                            
                              
                                Z
                                ⁡
                                
                                  (
                                  V
                                  )
                                
                              
                              _
                            
                          
                          )
                        
                      
                      2
                    
                  
                
              
            
          
        
      
    
    
      
        (
        2
        )
      
    
  




R1 represents the first correlation, Xi(Y) represents the ith Y component of this frame, Xi(U) represents the ith U component of this frame, Xi(V) represents the ith V component of this frame, Zi(Y) represents the ith Y component of the next frame, Zi(U) represents the ith U component of the next frame, Zi(V) represents the ith V component of the next frame, X(Y) represents the average of all Y components of this frame, X(U) represents the average of all U components of this frame, X(V) represents the average of all V components of this frame, Z(Y) represents the average of all Y components of the next frame, Z(U) represents the average of all U components of the next frame, and Z(V) represents the average of all V components of the next frame. The second correlation indicates the similar extent of Y, U and V components between odd rows of this frame and even rows of the next frame and a higher value indicates a higher similarity than a lower one. The second correlation may be calculated in Equation (3):





  
    
      
        
          R
          ⁢
          
            
          
          ⁢
          2
        
        =
        
          
            
              
                
                  
                    
                      Σ
                      ⁡
                      
                        (
                        
                          
                            
                              X
                              i
                            
                            ⁡
                            
                              (
                              Y
                              )
                            
                          
                          -
                          
                            
                              X
                              ⁡
                              
                                (
                                Y
                                )
                              
                            
                            _
                          
                        
                        )
                      
                    
                    ⁢
                    
                      (
                      
                        
                          
                            Z
                            i
                          
                          ⁡
                          
                            (
                            Y
                            )
                          
                        
                        -
                        
                          
                            Z
                            ⁡
                            
                              (
                              Y
                              )
                            
                          
                          _
                        
                      
                      )
                    
                  
                  +
                
              
            
            
              
                
                  
                    
                      
                        
                          Σ
                          ⁢
                          
                            (
                            
                              
                                
                                  X
                                  i
                                
                                ⁡
                                
                                  (
                                  U
                                  )
                                
                              
                              -
                              
                                
                                  X
                                  ⁡
                                  
                                    (
                                    U
                                    )
                                  
                                
                                _
                              
                            
                            )
                          
                          ⁢
                          
                            (
                            
                              
                                
                                  Z
                                  i
                                
                                ⁡
                                
                                  (
                                  U
                                  )
                                
                              
                              -
                              
                                
                                  Z
                                  ⁡
                                  
                                    (
                                    U
                                    )
                                  
                                
                                _
                              
                            
                            )
                          
                        
                        +
                      
                    
                  
                  
                    
                      
                        
                          Σ
                          ⁡
                          
                            (
                            
                              
                                
                                  X
                                  i
                                
                                ⁡
                                
                                  (
                                  V
                                  )
                                
                              
                              -
                              
                                
                                  X
                                  ⁡
                                  
                                    (
                                    V
                                    )
                                  
                                
                                _
                              
                            
                            )
                          
                        
                        ⁢
                        
                          (
                          
                            
                              
                                Z
                                i
                              
                              ⁡
                              
                                (
                                V
                                )
                              
                            
                            -
                            
                              
                                Z
                                ⁡
                                
                                  (
                                  V
                                  )
                                
                              
                              _
                            
                          
                          )
                        
                      
                    
                  
                
              
            
          
          
            
              
                
                  
                    
                      
                        Σ
                        ⁡
                        
                          (
                          
                            
                              
                                X
                                i
                              
                              ⁡
                              
                                (
                                Y
                                )
                              
                            
                            -
                            
                              
                                X
                                ⁡
                                
                                  (
                                  Y
                                  )
                                
                              
                              _
                            
                          
                          )
                        
                      
                      2
                    
                    ⁢
                    
                      
                        Σ
                        ⁡
                        
                          (
                          
                            
                              
                                Z
                                i
                              
                              ⁡
                              
                                (
                                Y
                                )
                              
                            
                            -
                            
                              
                                Z
                                ⁡
                                
                                  (
                                  Y
                                  )
                                
                              
                              _
                            
                          
                          )
                        
                      
                      2
                    
                    ⁢
                    
                      
                        Σ
                        ⁡
                        
                          (
                          
                            
                              
                                X
                                i
                              
                              ⁡
                              
                                (
                                U
                                )
                              
                            
                            -
                            
                              
                                X
                                ⁡
                                
                                  (
                                  U
                                  )
                                
                              
                              _
                            
                          
                          )
                        
                      
                      2
                    
                  
                
              
              
                
                  
                    
                      
                        Σ
                        ⁡
                        
                          (
                          
                            
                              
                                Z
                                i
                              
                              ⁡
                              
                                (
                                U
                                )
                              
                            
                            -
                            
                              
                                Z
                                ⁡
                                
                                  (
                                  U
                                  )
                                
                              
                              _
                            
                          
                          )
                        
                      
                      2
                    
                    ⁢
                    
                      
                        Σ
                        ⁡
                        
                          (
                          
                            
                              
                                X
                                i
                              
                              ⁡
                              
                                (
                                V
                                )
                              
                            
                            -
                            
                              
                                X
                                ⁡
                                
                                  (
                                  V
                                  )
                                
                              
                              _
                            
                          
                          )
                        
                      
                      2
                    
                    ⁢
                    
                      
                        Σ
                        ⁡
                        
                          (
                          
                            
                              
                                Z
                                i
                              
                              ⁡
                              
                                (
                                V
                                )
                              
                            
                            -
                            
                              
                                Z
                                ⁡
                                
                                  (
                                  V
                                  )
                                
                              
                              _
                            
                          
                          )
                        
                      
                      2
                    
                  
                
              
            
          
        
      
    
    
      
        (
        3
        )
      
    
  




R2 represents the second correlation, Xi(Y) represents the ith Y component of even rows of this frame, Xi(U) represents the ith U component of even rows of this frame, Xi(V) represents the ith V component of even rows of this frame, Zi(Y) represents the ith Y component of odd rows of the next frame, Zi(U) represents the ith U component of odd rows of the next frame, Zi(V) represents the ith V component of odd rows of the next frame, X(Y) represents the average of all Y components of even rows of this frame, X(U) represents the average of all U components of even rows of this frame, X(V) represents the average of all V components of even rows of this frame, Z(Y) represents the average of all Y components of odd rows of the next frame, Z(U) represents the average of all U components of odd rows of the next frame, and Z(V) represents the average of all V components of odd rows of the next frame. The third correlation indicates the similar extent of Y components between odd columns of this frame and even columns of the next frame and a higher value indicates a higher similarity than a lower one. The third correlation may be calculated in Equation (4):





  
    
      
        
          R
          ⁢
          
            
          
          ⁢
          3
        
        =
        
          
            
              Σ
              ⁡
              
                (
                
                  
                    
                      X
                      i
                    
                    ⁡
                    
                      (
                      Y
                      )
                    
                  
                  -
                  
                    
                      X
                      ⁡
                      
                        (
                        Y
                        )
                      
                    
                    _
                  
                
                )
              
            
            ⁢
            
              (
              
                
                  
                    Z
                    i
                  
                  ⁡
                  
                    (
                    Y
                    )
                  
                
                -
                
                  
                    Z
                    ⁡
                    
                      (
                      Y
                      )
                    
                  
                  _
                
              
              )
            
          
          
            
              
                
                  Σ
                  ⁡
                  
                    (
                    
                      
                        
                          X
                          i
                        
                        ⁡
                        
                          (
                          Y
                          )
                        
                      
                      -
                      
                        
                          X
                          ⁡
                          
                            (
                            Y
                            )
                          
                        
                        _
                      
                    
                    )
                  
                
                2
              
              ⁢
              
                
                  Σ
                  ⁡
                  
                    (
                    
                      
                        
                          Z
                          i
                        
                        ⁡
                        
                          (
                          Y
                          )
                        
                      
                      -
                      
                        
                          Z
                          ⁡
                          
                            (
                            Y
                            )
                          
                        
                        _
                      
                    
                    )
                  
                
                2
              
            
          
        
      
    
    
      
        (
        4
        )
      
    
  




R3 represents the third correlation, Xi(Y) represents the ith Y component of even columns of this frame, Zi(Y) represents the ith Y component of odd columns of the next frame, X(Y) represents the average of all Y components of even columns of this frame, and Z(Y) represents the average of all Y components of odd columns of the next frame. In step S260, one frame resolution candidate with the highest correlations R1 to R3 between the pth frame and the (p+1)th frame, each of which is greater than a threshold (e.g. 0.4), is selected as the best frame resolution. That is, the correlation R1 between the pth frame and the (p+1)th frame for the best frame resolution is higher than that for the other frame resolution candidates and greater than the threshold. The correlation R2 between the pth frame and the (p+1)th frame for the best frame resolution is higher than that for the other frame resolution candidates and greater than the threshold. The correlation R3 between the pth frame and the (p+1)th frame for the best frame resolution is higher than that for the other frame resolution candidates and greater than the threshold. In step S270, it is determined that the selection is unsuccessful when no frame resolution candidate is found to have the highest correlations R1 to R3 between the pth frame and the (p+1)th frame, each of which is greater than the threshold.

In some embodiments of each iteration of step S250, the processing unit 110 may calculate the correlations R3 between the pth frame and the (p+1)th frame, the (p+1)th frame and the (p+2)th frame, and the (p+2)th frame and the (p+3)th frame. In step S260, one frame resolution candidate with the highest correlations R3 between the pth frame and the (p+1)th frame, the (p+1)th frame and the (p+2)th frame, and the (p+2)th frame and the (p+3)th frame is determined as the best frame resolution. That is, the correlation R3 between the pth frame and the (p+1)th frame for the best frame resolution is higher than that for the other frame resolution candidates. The correlation R3 between the (p+1)th frame and the (p+2)th frame for the best frame resolution is higher than that for the other frame resolution candidates. The correlation R3 between the (p+2)th frame and the (p+3)th frame for the best frame resolution is higher than that for the other frame resolution candidates. In step S270, it is determined that the selection is unsuccessful when no frame resolution candidate is found to have the highest correlations R3 between the pth frame and the (p+1)th frame, the (p+1)th frame and the (p+2)th frame, and the (p+2)th frame and the (p+3)th frame.
In some embodiments, the calculations of correlations (step S250) and the selection for the best frame resolution (step S260) may be divided into two phases. FIGS. 3A and 3B are flowcharts illustrating a method for determining frame resolution according to an embodiment of the invention. Specifically, the processing unit 110 may repeatedly execute a loop m times, and in each iteration, data of the pth frame and the (p+1)th frame of the video stream is obtained according to one unexamined frame resolution candidate, and correlations R1 to R3 between the pth frame and the (p+1)th frame are calculated, where m represents the quantity of frame resolution candidates (step S250a). Next, the processing unit 110 attempts to select one frame resolution candidate with the highest correlations R1 to R3 between the pth frame and the (p+1)th frame, each of which is greater than 0.4, as the best frame resolution (step S260a). If the selection is successful (the “Yes” path of step S270a), the process proceeds to step S280. If the selection is not successful (the “No” path of step S270a), the processing unit 110 may repeatedly execute a loop m times, and in each iteration, data of the (p+2)th frame and the (p+3)th frame of the video stream is obtained according to one unexamined frame resolution candidate, and correlations R3 between the (p+1)th frame and the (p+2)th frame, and the (p+2)th frame and the (p+3)th frame are calculated (step S250b). Next, the processing unit 110 attempts to select one frame resolution candidate with the highest correlations R3 between the pth frame and the (p+1)th frame, the (p+1)th frame and the (p+2)th frame, and the (p+2)th frame and the (p+3)th frame as the best frame resolution (step S260b). If the selection is successful (the “Yes” path of step S270b), the process proceeds to step S280. If the selection is not successful (the “No” path of step S270b), the process proceeds to step S240.
In some implementations, the method may divide video stream into frames according every frame resolution of the frame resolution table and determine whether every divided result is correct using an algorithm. Embodiments of the invention employ a calculation in step S220 to remove most of the improper frame resolutions in the frame resolution table from further consideration, so as to improve calculation efficiency.
Although the embodiment has been described as having specific elements in FIG. 1, it should be noted that additional elements may be included to achieve better performance without departing from the spirit of the invention. While the process flows described in FIGS. 2 and 3 include a number of operations that appear to occur in a specific order, it should be apparent that these processes can include more or fewer operations, which can be executed serially or in parallel (e.g., using parallel processors or a multi-threading environment).
While the invention has been described by way of example and in terms of the preferred embodiments, it should be understood that the invention is not limited to the disclosed embodiments. On the contrary, it is intended to cover various modifications and similar arrangements (as would be apparent to those skilled in the art). Therefore, the scope of the appended claims should be accorded the broadest interpretation so as to encompass all such modifications and similar arrangements.

## Claims

1. A method for determining frame resolution, performed by a processing unit, comprising:
obtaining a YUV video file, which comprises a video stream;
selecting a plurality of frame resolutions from a frame resolution table as frame resolution candidates according to length of the video stream;
repeatedly executing a loop m times, and in each iteration, obtaining at least two frames of the video stream according to one unexamined frame resolution candidate and calculating a correlation between the obtained frames, wherein m represents quantity of the frame resolution candidates;
determining best frame resolution from the frame resolution candidates according to the calculated correlations; and
outputting the best frame resolution, thereby enabling a video decoder to segment the video stream into frames according to the best frame resolution and decode the segmented frame,
wherein the step for selecting a plurality of frame resolutions from a frame resolution table as frame resolution candidates according to length of the video stream comprises:
calculating the jth frame resolution of the frame resolution table using an Equation, wherein j is an integer between 1 to k, and k represents quantity of all frame resolutions of the frame resolution table:


L/Wj/Hj/Rt=nj. . . rj 


L represents the length of the video stream of the YUV video file, Wj represents a width of the jth frame resolution, Hj represents a height of the jth frame resolution, Rt represents a default value associated with a particular video stream format, nj represents a quotient associated with the jth frame resolution, and rj represents a remainder associated with the jth frame resolution; and
treating the frame resolutions with the remainder being 0 as the frame resolution candidates.

2. The method of claim 1, wherein the YUV video file comprises a header and the header does not contain frame resolution information.

3. The method of claim 2, wherein the step for outputting the best frame resolution comprises:
writing the best frame resolution into the header or outputting the best frame resolution to the video decoder.

4. The method of claim 1, wherein the step for repeatedly executing a loop m times comprises:
in each iteration, obtaining data of a pth frame and a (p+1)th frame from the video stream according to one unexamined frame resolution candidate; and
calculating a first correlation, a second correlation and a third correlation between the pth frame and the (p+1)th frame, and
wherein the step for determining the best frame resolution from the frame resolution candidates according to the calculated correlations comprises:
selecting one frame resolution candidate with the highest first, second and third correlations between the pth frame and the (p+1)th frame, each of which is greater than a threshold, as the best frame resolution.

5. The method of claim 4, wherein the first correlation indicates the similar extent of Y, U and V components between the pth frame and the (p+1)th frame, the second correlation indicates the similar extent of Y, U and V components between odd rows of the pth frame and even rows of the (p+1)th frame, and the third correlation indicates the similar extent of Y components between odd columns of the pth frame and even columns of the (p+1)th frame.

6. The method of claim 5, wherein the first correlation is calculated in an Equation:




  
    R
    ⁢
    
      
    
    ⁢
    1
  
  =
  
    
      
        
          
            
              
                Σ
                ⁡
                
                  (
                  
                    
                      
                        X
                        i
                      
                      ⁡
                      
                        (
                        Y
                        )
                      
                    
                    -
                    
                      
                        X
                        ⁡
                        
                          (
                          Y
                          )
                        
                      
                      _
                    
                  
                  )
                
              
              ⁢
              
                (
                
                  
                    
                      Z
                      i
                    
                    ⁡
                    
                      (
                      Y
                      )
                    
                  
                  -
                  
                    
                      Z
                      ⁡
                      
                        (
                        Y
                        )
                      
                    
                    _
                  
                
                )
              
            
            +
          
        
      
      
        
          
            
              
                
                  
                    Σ
                    ⁢
                    
                      (
                      
                        
                          
                            X
                            i
                          
                          ⁡
                          
                            (
                            U
                            )
                          
                        
                        -
                        
                          
                            X
                            ⁡
                            
                              (
                              U
                              )
                            
                          
                          _
                        
                      
                      )
                    
                    ⁢
                    
                      (
                      
                        
                          
                            Z
                            i
                          
                          ⁡
                          
                            (
                            U
                            )
                          
                        
                        -
                        
                          
                            Z
                            ⁡
                            
                              (
                              U
                              )
                            
                          
                          _
                        
                      
                      )
                    
                  
                  +
                
              
            
            
              
                
                  
                    Σ
                    ⁡
                    
                      (
                      
                        
                          
                            X
                            i
                          
                          ⁡
                          
                            (
                            V
                            )
                          
                        
                        -
                        
                          
                            X
                            ⁡
                            
                              (
                              V
                              )
                            
                          
                          _
                        
                      
                      )
                    
                  
                  ⁢
                  
                    (
                    
                      
                        
                          Z
                          i
                        
                        ⁡
                        
                          (
                          V
                          )
                        
                      
                      -
                      
                        
                          Z
                          ⁡
                          
                            (
                            V
                            )
                          
                        
                        _
                      
                    
                    )
                  
                
              
            
          
        
      
    
    
      
        
          
            
              
                
                  Σ
                  ⁡
                  
                    (
                    
                      
                        
                          X
                          i
                        
                        ⁡
                        
                          (
                          Y
                          )
                        
                      
                      -
                      
                        
                          X
                          ⁡
                          
                            (
                            Y
                            )
                          
                        
                        _
                      
                    
                    )
                  
                
                2
              
              ⁢
              
                
                  Σ
                  ⁡
                  
                    (
                    
                      
                        
                          Z
                          i
                        
                        ⁡
                        
                          (
                          Y
                          )
                        
                      
                      -
                      
                        
                          Z
                          ⁡
                          
                            (
                            Y
                            )
                          
                        
                        _
                      
                    
                    )
                  
                
                2
              
              ⁢
              
                
                  Σ
                  ⁡
                  
                    (
                    
                      
                        
                          X
                          i
                        
                        ⁡
                        
                          (
                          U
                          )
                        
                      
                      -
                      
                        
                          X
                          ⁡
                          
                            (
                            U
                            )
                          
                        
                        _
                      
                    
                    )
                  
                
                2
              
            
          
        
        
          
            
              
                
                  Σ
                  ⁡
                  
                    (
                    
                      
                        
                          Z
                          i
                        
                        ⁡
                        
                          (
                          U
                          )
                        
                      
                      -
                      
                        
                          Z
                          ⁡
                          
                            (
                            U
                            )
                          
                        
                        _
                      
                    
                    )
                  
                
                2
              
              ⁢
              
                
                  Σ
                  ⁡
                  
                    (
                    
                      
                        
                          X
                          i
                        
                        ⁡
                        
                          (
                          V
                          )
                        
                      
                      -
                      
                        
                          X
                          ⁡
                          
                            (
                            V
                            )
                          
                        
                        _
                      
                    
                    )
                  
                
                2
              
              ⁢
              
                
                  Σ
                  ⁡
                  
                    (
                    
                      
                        
                          Z
                          i
                        
                        ⁡
                        
                          (
                          V
                          )
                        
                      
                      -
                      
                        
                          Z
                          ⁡
                          
                            (
                            V
                            )
                          
                        
                        _
                      
                    
                    )
                  
                
                2
              
            
          
        
      
    
  



R1 represents the first correlation, Xi(Y) represents an ith Y component of the pth frame, Xi(U) represents an ith U component of the pth frame, Xi(V) represents an ith V component of the pth frame, Zi(Y) represents an ith Y component of the (p+1)th frame, Zi(U) represents an ith U component of the (p+1)th frame, Zi(V) represents an ith V component of the (p+1)th frame, X(Y) represents an average of all Y components of the pth frame, X(U) represents an average of all U components of the pth frame, X(V) represents an average of all V components of the pth frame, Z(Y) represents an average of all Y components of the (p+1)th frame, Z(U) represents an average of all U components of the (p+1)th IP frame, and Z(V) represents an average of all V components of the (p+1)th frame,
the second correlation is calculated in an Equation:





  
    R
    ⁢
    
      
    
    ⁢
    2
  
  =
  
    
      
        
          
            
              
                Σ
                ⁡
                
                  (
                  
                    
                      
                        X
                        i
                      
                      ⁡
                      
                        (
                        Y
                        )
                      
                    
                    -
                    
                      
                        X
                        ⁡
                        
                          (
                          Y
                          )
                        
                      
                      _
                    
                  
                  )
                
              
              ⁢
              
                (
                
                  
                    
                      Z
                      i
                    
                    ⁡
                    
                      (
                      Y
                      )
                    
                  
                  -
                  
                    
                      Z
                      ⁡
                      
                        (
                        Y
                        )
                      
                    
                    _
                  
                
                )
              
            
            +
          
        
      
      
        
          
            
              
                
                  
                    Σ
                    ⁢
                    
                      (
                      
                        
                          
                            X
                            i
                          
                          ⁡
                          
                            (
                            U
                            )
                          
                        
                        -
                        
                          
                            X
                            ⁡
                            
                              (
                              U
                              )
                            
                          
                          _
                        
                      
                      )
                    
                    ⁢
                    
                      (
                      
                        
                          
                            Z
                            i
                          
                          ⁡
                          
                            (
                            U
                            )
                          
                        
                        -
                        
                          
                            Z
                            ⁡
                            
                              (
                              U
                              )
                            
                          
                          _
                        
                      
                      )
                    
                  
                  +
                
              
            
            
              
                
                  
                    Σ
                    ⁡
                    
                      (
                      
                        
                          
                            X
                            i
                          
                          ⁡
                          
                            (
                            V
                            )
                          
                        
                        -
                        
                          
                            X
                            ⁡
                            
                              (
                              V
                              )
                            
                          
                          _
                        
                      
                      )
                    
                  
                  ⁢
                  
                    (
                    
                      
                        
                          Z
                          i
                        
                        ⁡
                        
                          (
                          V
                          )
                        
                      
                      -
                      
                        
                          Z
                          ⁡
                          
                            (
                            V
                            )
                          
                        
                        _
                      
                    
                    )
                  
                
              
            
          
        
      
    
    
      
        
          
            
              
                
                  Σ
                  ⁡
                  
                    (
                    
                      
                        
                          X
                          i
                        
                        ⁡
                        
                          (
                          Y
                          )
                        
                      
                      -
                      
                        
                          X
                          ⁡
                          
                            (
                            Y
                            )
                          
                        
                        _
                      
                    
                    )
                  
                
                2
              
              ⁢
              
                
                  Σ
                  ⁡
                  
                    (
                    
                      
                        
                          Z
                          i
                        
                        ⁡
                        
                          (
                          Y
                          )
                        
                      
                      -
                      
                        
                          Z
                          ⁡
                          
                            (
                            Y
                            )
                          
                        
                        _
                      
                    
                    )
                  
                
                2
              
              ⁢
              
                
                  Σ
                  ⁡
                  
                    (
                    
                      
                        
                          X
                          i
                        
                        ⁡
                        
                          (
                          U
                          )
                        
                      
                      -
                      
                        
                          X
                          ⁡
                          
                            (
                            U
                            )
                          
                        
                        _
                      
                    
                    )
                  
                
                2
              
            
          
        
        
          
            
              
                
                  Σ
                  ⁡
                  
                    (
                    
                      
                        
                          Z
                          i
                        
                        ⁡
                        
                          (
                          U
                          )
                        
                      
                      -
                      
                        
                          Z
                          ⁡
                          
                            (
                            U
                            )
                          
                        
                        _
                      
                    
                    )
                  
                
                2
              
              ⁢
              
                
                  Σ
                  ⁡
                  
                    (
                    
                      
                        
                          X
                          i
                        
                        ⁡
                        
                          (
                          V
                          )
                        
                      
                      -
                      
                        
                          X
                          ⁡
                          
                            (
                            V
                            )
                          
                        
                        _
                      
                    
                    )
                  
                
                2
              
              ⁢
              
                
                  Σ
                  ⁡
                  
                    (
                    
                      
                        
                          Z
                          i
                        
                        ⁡
                        
                          (
                          V
                          )
                        
                      
                      -
                      
                        
                          Z
                          ⁡
                          
                            (
                            V
                            )
                          
                        
                        _
                      
                    
                    )
                  
                
                2
              
            
          
        
      
    
  



R2 represents the second correlation, Xi(Y) represents an ith Y component of even rows of the pth frame, Xi(U) represents an ith U component of even rows of the pth frame, Xi(V) represents an ith V component of even rows of the pth frame, Zi(Y) represents an ith Y component of odd rows of the (p+1)th frame, Zi(U) represents an ith U component of odd rows of the (p+1)th frame, Zi(V) represents an ith V component of odd rows of the (p+1)th frame, X(Y) represents an average of all Y components of even rows of the pth frame, X(U) represents an average of all U components of even rows of the pth frame, X(V) represents an average of all V components of even rows of the pth frame, Z(Y) represents an average of all Y components of odd rows of the (p+1)th frame, Z(U) represents an average of all U components of odd rows of the (p+1)th frame, and Z(V) represents an average of all V components of odd rows of the (p+1)th frame, and
the third correlation is calculated in an Equation:





  
    R
    ⁢
    
      
    
    ⁢
    3
  
  =
  
    
      
        Σ
        ⁡
        
          (
          
            
              
                X
                i
              
              ⁡
              
                (
                Y
                )
              
            
            -
            
              
                X
                ⁡
                
                  (
                  Y
                  )
                
              
              _
            
          
          )
        
      
      ⁢
      
        (
        
          
            
              Z
              i
            
            ⁡
            
              (
              Y
              )
            
          
          -
          
            
              Z
              ⁡
              
                (
                Y
                )
              
            
            _
          
        
        )
      
    
    
      
        
          
            Σ
            ⁡
            
              (
              
                
                  
                    X
                    i
                  
                  ⁡
                  
                    (
                    Y
                    )
                  
                
                -
                
                  
                    X
                    ⁡
                    
                      (
                      Y
                      )
                    
                  
                  _
                
              
              )
            
          
          2
        
        ⁢
        
          
            Σ
            ⁡
            
              (
              
                
                  
                    Z
                    i
                  
                  ⁡
                  
                    (
                    Y
                    )
                  
                
                -
                
                  
                    Z
                    ⁡
                    
                      (
                      Y
                      )
                    
                  
                  _
                
              
              )
            
          
          2
        
      
    
  



R3 represents the third correlation, Xi(Y) represents an ith Y component of even columns of the pth frame, Zi(Y) represents an ith Y component of odd columns of the (p+1)th frame, X(Y) represents an average of all Y components of even columns of the pth frame, and Z(Y) represents an average of all Y components of odd columns of the (p+1)th IP frame.

7. The method of claim 1, wherein the step for repeatedly executing a loop m times comprises:
in each iteration, obtaining data of a pth frame, a (p+1)th frame, a (p+2)th frame and a (p+3)th frame from the video stream according to one unexamined frame resolution candidate; and
calculating a third correlation between the pth frame and the (p+1)th frame, a third correlation between (p+1)th frame and the (p+2)th frame, and a third correlation between (p+2)th frame and the (p+3)th frame, and
wherein the step for determining the best frame resolution from the frame resolution candidates according to the calculated correlations comprises:
selecting one frame resolution candidate with the highest third correlation between the pth frame and the (p+1)th frame, the highest third correlation between (p+1)th frame and the (p+2)th frame, and the highest third correlation between (p+2)th frame and the (p+3)th frame as the best frame resolution.

8. The method of claim 7, wherein the third correlation between the pth frame and the (p+1)th frame indicates the similar extent of Y components between odd columns of the pth frame and even columns of the (p+1)th frame, the third correlation between the (p+1)th frame and the (p+2)th frame indicates the similar extent of Y components between odd columns of the (p+1)th frame and even columns of the (p+2)th frame, and the third correlation between the (p+2)th frame and the (p+3)th frame indicates the similar extent of Y components between odd columns of the (p+2)th frame and even columns of the (p+3)th frame.

9. An apparatus for determining frame resolution, comprising:
a processing unit and associated memory, obtaining a YUV video file, which comprises a video stream; selecting a plurality of frame resolutions from a frame resolution table as frame resolution candidates according to length of the video stream; repeatedly executing a loop m times, and in each iteration, obtaining at least two frames of the video stream according to one unexamined frame resolution candidate and calculating a correlation between the obtained frames, wherein m represents quantity of frame resolution candidates; determining the best frame resolution from the frame resolution candidates according to the calculated correlations; and outputting the best frame resolution, thereby enabling a video decoder to segment the video stream into frames according to the best frame resolution and decode the segmented frame,
wherein the operation of selecting a plurality of frame resolutions from a frame resolution table as frame resolution candidates according to length of the video stream comprises:
calculating the jth frame resolution of the frame resolution table using an Equation, wherein j is an integer between 1 to k, and k represents quantity of all frame resolutions of the frame resolution table:


L/Wj/Hj/Rt=nj. . . rj 


L represents the length of the video stream of the YUV video file, Wj represents a width of the jth frame resolution, Hj represents a height of the jth frame resolution, Rt represents a default value associated with a particular video stream format, nj represents a quotient associated with the jth frame resolution, and rj represents a remainder associated with the jth frame resolution; and
treating the frame resolutions with the remainder being 0 as the frame resolution candidates.

10. The apparatus of claim 9, comprising:
a storage device, storing the YUV video file and the frame resolution table,
wherein the processing unit reads the YUV video file and the frame resolution table from the storage device.

11. The apparatus of claim 9, comprising:
a storage device, storing the frame resolution table; and
a communications interface,
wherein the processing unit reads the frame resolution table from the storage device and obtains the YUV video file from an electronic apparatus via the communications interface.

12. The apparatus of claim 9, wherein the YUV video file comprises a header and the header does not contain frame resolution information.

13. The apparatus of claim 12, wherein the processing unit writes the best frame resolution into the header or outputs the best frame resolution to the video decoder.

14. The apparatus of claim 9, wherein the processing unit, in each iteration, obtains data of a pth frame and a (p+1)th frame from the video stream according to one unexamined frame resolution candidate; calculates a first correlation, a second correlation and a third correlation between the pth frame and the (p+1)th frame; and selects one frame resolution candidate with the highest first, second and third correlations between the pth frame and the (p+1)th frame, each of which is greater than a threshold, as the best frame resolution.

15. The apparatus of claim 14, wherein the first correlation indicates the similar extent of Y, U and V components between the pth frame and the (p+1)th frame, the second the pth frame and even rows of the (p+1)th frame, and the third correlation indicates the similar extent of Y components between odd columns of the pth frame and even columns of the (p+1)th frame.

16. The apparatus of claim 9, wherein the processing unit, in each iteration, obtains data of a pth frame, a (p+1)th frame, a (p+2)th frame and a (p+3)th frame from the video stream according to one unexamined frame resolution candidate; calculates a third correlation between the pth frame and the (p+1)th frame, a third correlation between (p+1)th frame and the (p+2)th frame, and a third correlation between (p+2)th frame and the (p+3)th frame; and selects one frame resolution candidate with the highest third correlation between the pth frame and the (p+1)th frame, the highest third correlation between (p+1)th frame and the (p+2)th frame, and the highest third correlation between (p+2)th frame and the (p+3)th frame as the best frame resolution.

17. The apparatus of claim 16, wherein the third correlation between the pth frame and the (p+1)th frame indicates the similar extent of Y components between odd columns of the pth frame and even columns of the (p+1)th frame, the third correlation between the (p+1)th frame and the (p+2)th frame indicates the similar extent of Y components between odd columns of the (p+1)th frame and even columns of the (p+2)th frame, and the third correlation between the (p+2)th frame and the (p+3)th frame indicates the similar extent of Y components between odd columns of the (p+2)th frame and even columns of the (p+3)th frame.