Package com.avpkit.core
Class Utils
- java.lang.Object
-
- com.avpkit.core.Utils
-
public class Utils extends java.lang.Object
A collection of useful utilities for creating blankIVideoPictureobjects and managing audio time stamp to sample conversions.- Author:
- aclarke
-
-
Constructor Summary
Constructors Constructor Description Utils()
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static IVideoPicturegetBlankFrame(int w, int h, int pts)Returns a blank frame with a green-screen background.static IVideoPicturegetBlankFrame(int w, int h, int y, int u, int v, long pts)Get a new blank frame object encoded inIPixelFormat.Type.YUV420Pformat.static IVideoPicturegetBlankFrame(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 inIPixelFormat.Type.YUV420Pformat.static IVideoPictureimageToVideoPicture(java.awt.image.BufferedImage image, long pts)Deprecated.Image and picture conversion functionality has been replaced byConverterFactory.static ITimeValuesamplesToTimeValue(long numSamples, int sampleRate)For a given sample rate, returns how long it would take to play a number of samples.static longtimeValueToSamples(ITimeValue duration, int sampleRate)For a given time duration and sample rate, return the number of samples it would take to fill.static java.awt.image.BufferedImagevideoPictureToImage(IVideoPicture picture)Deprecated.Image and picture conversion functionality has been replaced byConverterFactory.
-
-
-
Constructor Detail
-
Utils
public Utils()
-
-
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 inIPixelFormat.Type.YUV420Pformat. 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 objecth- height of objectyColor- 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, orGlobal.NO_PTSfor none.crossHatchW- width of cross hatch on image, or <=0 for nonecrossHatchH- height of cross hatch on image, or <= 0 for nonecrossHatchYColor- 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 inIPixelFormat.Type.YUV420Pformat.- Parameters:
w- width of objecth- height of objecty- 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, orGlobal.NO_PTSfor none.- Returns:
- A new frame, or null if we can't create it.
-
getBlankFrame
public static IVideoPicture getBlankFrame(int w, int h, int pts)
Returns a blank frame with a green-screen background.- Parameters:
w- width in pixelsh- height in pixelspts- presentation timestamp (inTimeUnit.MICROSECONDSyou want set- Returns:
- a new blank frame
- See Also:
getBlankFrame(int, int, int, int, int, long)
-
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 forsampleRate- 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- durationsampleRate- 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 byConverterFactory. The current implementation ofvideoPictureToImage(com.avpkit.core.IVideoPicture)creates a newIConverteron each call, which is not very efficient.Convert anIVideoPictureto aBufferedImage. The input picture should be of typeIPixelFormat.Type.BGR24to 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- TheIVideoPictureto be converted.- Returns:
- the resultant
BufferedImagewhich will contain the video frame. - Throws:
java.lang.IllegalArgumentException- if the passedIVideoPictureis NULL;java.lang.IllegalArgumentException- if the passedIVideoPictureis not complete.
-
imageToVideoPicture
@Deprecated public static IVideoPicture imageToVideoPicture(java.awt.image.BufferedImage image, long pts)
Deprecated.Image and picture conversion functionality has been replaced byConverterFactory. The current implementation ofimageToVideoPicture(java.awt.image.BufferedImage, long)creates a newIConverteron each call, which is not very efficient.Convert aBufferedImageto anIVideoPictureof typeIPixelFormat.Type.BGR24. TheBufferedImagemust be aBufferedImage.TYPE_3BYTE_BGRtype.- Parameters:
image- The sourceBufferedImage.pts- The presentation time stamp of the picture.- Returns:
- An
IVideoPictureinIPixelFormat.Type.BGR24format. - Throws:
java.lang.IllegalArgumentException- if the passedBufferedImageis NULL;java.lang.IllegalArgumentException- if the passedBufferedImageis not of typeBufferedImage.TYPE_3BYTE_BGR.java.lang.IllegalArgumentException- if the underlying data buffer of theBufferedImageis composed of types other bytes or integers.
-
-