Class Utils


  • public class Utils
    extends java.lang.Object
    A collection of useful utilities for creating blank IVideoPicture objects and managing audio time stamp to sample conversions.
    Author:
    aclarke
    • Constructor Detail

    • Method Detail

      • getBlankFrame

        public static IVideoPicture getBlankFrame​(int w,
                                                  int h,
                                                  int yColor,
                                                  int uColor,
                                                  int vColor,
                                                  long pts,
                                                  int crossHatchW,
                                                  int crossHatchH,
                                                  int crossHatchYColor,
                                                  int crossHatchUColor,
                                                  int crossHatchVColor)
        Get a new blank frame object encoded in IPixelFormat.Type.YUV420P format. If crossHatchW and crossHatchH are greater than zero, then we'll draw a cross-hatch pattern with boxes of those sizes alternating on the screen. This can be useful to spot coding and translation errors. Word of warning though -- due to how the YUV420P colorspace works, you'll need to make sure crossHatchW and crossHatchH are even numbers to avoid unslightly u/v lines at box edges.
        Parameters:
        w - width of object
        h - height of object
        yColor - Y component of background color.
        uColor - U component of background color.
        vColor - V component of background color.
        pts - The time stamp, in microseconds, you want this frame to have, or Global.NO_PTS for none.
        crossHatchW - width of cross hatch on image, or <=0 for none
        crossHatchH - height of cross hatch on image, or <= 0 for none
        crossHatchYColor - Y component of cross-hatch color.
        crossHatchUColor - U component of cross-hatch color.
        crossHatchVColor - V component of cross-hatch color.
        Returns:
        A new frame, or null if we can't create it.
      • getBlankFrame

        public static IVideoPicture getBlankFrame​(int w,
                                                  int h,
                                                  int y,
                                                  int u,
                                                  int v,
                                                  long pts)
        Get a new blank frame object encoded in IPixelFormat.Type.YUV420P format.
        Parameters:
        w - width of object
        h - height of object
        y - Y component of background color.
        u - U component of background color.
        v - V component of background color.
        pts - The time stamp, in microseconds, you want this frame to have, or Global.NO_PTS for none.
        Returns:
        A new frame, or null if we can't create it.
      • samplesToTimeValue

        public static ITimeValue samplesToTimeValue​(long numSamples,
                                                    int sampleRate)
        For a given sample rate, returns how long it would take to play a number of samples.
        Parameters:
        numSamples - The number of samples you want to find the duration for
        sampleRate - The sample rate in Hz
        Returns:
        The duration it would take to play numSamples of sampleRate audio
      • timeValueToSamples

        public static long timeValueToSamples​(ITimeValue duration,
                                              int sampleRate)
        For a given time duration and sample rate, return the number of samples it would take to fill.
        Parameters:
        duration - duration
        sampleRate - sample rate of audio
        Returns:
        number of samples required to fill that duration
      • videoPictureToImage

        @Deprecated
        public static java.awt.image.BufferedImage videoPictureToImage​(IVideoPicture picture)
        Deprecated.
        Image and picture conversion functionality has been replaced by ConverterFactory. The current implementation of videoPictureToImage(com.avpkit.core.IVideoPicture) creates a new IConverter on each call, which is not very efficient.
        Convert an IVideoPicture to a BufferedImage. The input picture should be of type IPixelFormat.Type.BGR24 to avoid making unnecessary copies. The image data ultimately resides in java memory space, which means the caller does not need to concern themselves with memory management issues.
        Parameters:
        picture - The IVideoPicture to be converted.
        Returns:
        the resultant BufferedImage which will contain the video frame.
        Throws:
        java.lang.IllegalArgumentException - if the passed IVideoPicture is NULL;
        java.lang.IllegalArgumentException - if the passed IVideoPicture is not complete.
      • imageToVideoPicture

        @Deprecated
        public static IVideoPicture imageToVideoPicture​(java.awt.image.BufferedImage image,
                                                        long pts)
        Deprecated.
        Image and picture conversion functionality has been replaced by ConverterFactory. The current implementation of imageToVideoPicture(java.awt.image.BufferedImage, long) creates a new IConverter on each call, which is not very efficient.
        Convert a BufferedImage to an IVideoPicture of type IPixelFormat.Type.BGR24. The BufferedImage must be a BufferedImage.TYPE_3BYTE_BGR type.
        Parameters:
        image - The source BufferedImage.
        pts - The presentation time stamp of the picture.
        Returns:
        An IVideoPicture in IPixelFormat.Type.BGR24 format.
        Throws:
        java.lang.IllegalArgumentException - if the passed BufferedImage is NULL;
        java.lang.IllegalArgumentException - if the passed BufferedImage is not of type BufferedImage.TYPE_3BYTE_BGR.
        java.lang.IllegalArgumentException - if the underlying data buffer of the BufferedImage is composed of types other bytes or integers.