Digital Signal Processing
DSP Tools and Techniques
Wednesday, September 8, 2021
Tuesday, March 19, 2019
YUV files
YUV files for various image and video processing algorithms can be downloaded from here
Thursday, November 22, 2018
Monday, May 21, 2018
YUV Pixel Values
Y | U/ Cb |
V/ Cr |
color | notes |
---|---|---|---|---|
0x00 | 0x00 | 0x00 | ||
0x00 | 0x00 | 0xFF | ||
0x00 | 0xFF | 0x00 | ||
0x00 | 0xFF | 0xFF | ||
0xFF | 0x00 | 0x00 | full green | |
0xFF | 0x00 | 0xFF | ||
0xFF | 0xFF | 0x00 | ||
0xFF | 0xFF | 0xFF | ||
0x00 | 0x80 | 0x80 | full black | |
0x80 | 0x80 | 0x80 | ||
0xFF | 0x80 | 0x80 | full white |
Courtesy: https://multimedia.cx/eggs/yuv-and-rgb/
Friday, March 30, 2018
Google Test Tutorial
Building Google Test from source
git clone https://github.com/google/googletest
cd googletest
mkdir build
cd build
cmake ..
make
sudo make install
Writing GTest
mkdir example01
cd example01
squareroot.h
#include
double squareRoot(const double a) {
double b = sqrt(a);
if(b != b) { // nan check
return -1.0;
}else{
return sqrt(a);
}
}
tests.cpp
#include "squareroot.h"
#include
TEST(SquareRootTest, PositiveNos) {
ASSERT_EQ(6, squareRoot(36.0));
ASSERT_EQ(18.0, squareRoot(324.0));
ASSERT_EQ(25.4, squareRoot(645.16));
ASSERT_EQ(0, squareRoot(0.0));
}
TEST(SquareRootTest, NegativeNos) {
ASSERT_EQ(-1.0, squareRoot(-15.0));
ASSERT_EQ(-1.0, squareRoot(-0.2));
}
int main(int argc, char **argv) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
CMakeLists.txt
cmake_minimum_required(VERSION 2.6)
# Locate GTest
find_package(GTest REQUIRED)
include_directories(${GTEST_INCLUDE_DIRS})
# Link runTests with what we want to test and the GTest and pthread library
add_executable(runTests tests.cpp)
target_link_libraries(runTests ${GTEST_LIBRARIES} pthread)
Building GTest
mkdir build
cd build
cmake ..
make
./runTests
git clone https://github.com/google/googletest
cd googletest
mkdir build
cd build
cmake ..
make
sudo make install
Writing GTest
mkdir example01
cd example01
squareroot.h
#include
double squareRoot(const double a) {
double b = sqrt(a);
if(b != b) { // nan check
return -1.0;
}else{
return sqrt(a);
}
}
tests.cpp
#include "squareroot.h"
#include
TEST(SquareRootTest, PositiveNos) {
ASSERT_EQ(6, squareRoot(36.0));
ASSERT_EQ(18.0, squareRoot(324.0));
ASSERT_EQ(25.4, squareRoot(645.16));
ASSERT_EQ(0, squareRoot(0.0));
}
TEST(SquareRootTest, NegativeNos) {
ASSERT_EQ(-1.0, squareRoot(-15.0));
ASSERT_EQ(-1.0, squareRoot(-0.2));
}
int main(int argc, char **argv) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
CMakeLists.txt
cmake_minimum_required(VERSION 2.6)
# Locate GTest
find_package(GTest REQUIRED)
include_directories(${GTEST_INCLUDE_DIRS})
# Link runTests with what we want to test and the GTest and pthread library
add_executable(runTests tests.cpp)
target_link_libraries(runTests ${GTEST_LIBRARIES} pthread)
Building GTest
mkdir build
cd build
cmake ..
make
./runTests
Friday, December 8, 2017
Halide - A language for Image Processing and Computational Photography
Halide is a new programming language designed to make it easier to write
high-performance image processing code on modern machines. Its current
front end is embedded in C++. Compiler targets include x86/SSE, ARM
v7/NEON, CUDA, and OpenCL.
http://halide-lang.org/
Halide source code can be found at: https://github.com/halide/Halide
Halide tutorials are located at: https://github.com/halide/Halide/tree/master/tutorial
http://halide-lang.org/
Halide source code can be found at: https://github.com/halide/Halide
Halide tutorials are located at: https://github.com/halide/Halide/tree/master/tutorial
Thursday, October 27, 2016
Cost effective video source for development
We all know that Raspberry Pi is very powerful Single board Linux computer that is not much bigger than credit card and can be used to learn programming, develop products quickly. It is also capable of many of the things that the desktop PC does like spreadsheets, word processing and playing high definition video and games. It also has Bluetooth Low Energy and WiFi connectivity on board.
Raspberry Pi can also be used as a video player/source and can provide output video resolutions till 1080p with different display timings. By default it will output at 1080p60. It has a default application 'omxplayer' to decode audio/video bitstreams from most of the container formats like MP4, MKV, AVI etc., Raspberry Pi foundation provides Linux based Raspbian OS distribution which can be installed on SD card and can be used to boot the Raspberry Pi hardware.
To get different output display timing we just need to modify the /boot/config.txt file after booting the Raspberry Pi with Raspbian OS and reboot the board, Add the below lines in the /boot/config.txt file to get 1080p24
-
hdmi_group=1
hdmi_mode=32
-
hdmi_group=34
https://www.raspberrypi.org/documentation/configuration/config-txt.md https://www.raspberrypi.org/forums/viewtopic.php?t=5851 To change the output display timing without reboot use the following commands. You may not be able to see the command console after issuing the below commands and hence it is advised to SSH to the board and issue the commands.
- tvservice -e "CEA 16" --------> to set 1080p60
- tvservice -e "CEA 31" --------> to set 1080p50
- tvservice -e "CEA 34" --------> to set 1080p30
- tvservice -e "CEA 33" --------> to set 1080p25
Example: omxplayer /opt/vc/src/hello_pi/hello_video/test.h264
Friday, October 30, 2015
Multimedia Processing with FFMPEG
FFMPEG is a set of libraries and a command line tool for encoding and decoding audio and video in many different formats. It is a free software project for manipulating/processing multimedia data. Many open source media players are based on FFMPEG libraries.
FFMPEG is developed under Linux but it can be compiled under most operating systems including Mac OS, Microsoft Windows.
For more details about FFMPEG please refer here
For windows operating system, it is preferred to download the pre-built binary from here. It is preferred to download the static build.
For Linux operating system, we can either build from the source by following the instruction given here or can install on Ubuntu using the following command
sudo apt-get install ffmpeg
YUV
There are lot of color spaces available like RGB, CMYK, HSV, YUV, CIELAB etc., The one that is widely used for video processing is YUV color space. YUV was invented when engineers wanted color television in a black and white infrastructure. They needed a signal transmission method that was compatible with black-and-white TV being able to add color. The luma component already existed as the black-and-white signal, they added the UV signal to this as a solution. More details here.
Inputs to the Image and Video Processing will be generally YUV files. Input video will be usually in YUV 4:2:0 chroma subsampled format. More details here.
Sample YUV sequences can be downloaded from here.
Video Processing with FFMPEG
The below command resizes the input YUV video of resolution 1920x1080 in YUV 4:2:0 format to 1280x720 YUV video
ffmpeg -s:v 1920x1080 -i input.yuv -vf scale=1280:720 -c:v rawvideo -pix_fmt yuv420p output.yuv
The below command decodes the video file in YUV 4:2:2 (YUYV) format
ffmpeg -i input.mp4 -pix_fmt yuyv422 output.yuv
The below command decodes the video file in YUV 4:2:2 (YUYV) format and scales to 1280x720
ffmpeg -i input.mp4 -pix_fmt yuyv422 -vf scale=1280:720 output.yuv
The below command decodes the video file in YUV 4:2:0 format
ffmpeg -i input.mp4 -pix_fmt yuv420p output.yuv
The below command decodes the video file in YUV 4:2:0 format and scales to 1280x720
ffmpeg -i input.mp4 -pix_fmt yuv420p -vf scale=1280:720 output.yuv
If you want to resize to some other resolution change the width and height assigned to the parameter scale.
To compress the YUV file of resolution 1280x720, frame rate 30 fps in H.264 video format at 5 Mbps
ffmpeg -s:v 1280x720 -i input.yuv -vcodec h264 -r 30 -pix_fmt yuv420p -b:v 5000k output.h264
To compress the above video in MPEG4 video format
ffmpeg -s:v 1280x720 -i input.yuv -vcodec mpeg4 -r 30 -pix_fmt yuv420p -b:v 5000k output.m4v
where the parameters present next to the following parameters
-s:v represents input resolution
-i represents input file
-vcodec represents output codec type
-r represents frame rate of the output video
-pix_fmt represents input video YUV chroma subsampling format
-b:v represents bitrate of the output video
Image Processing with FFMPEG
The following command decompresses the JPEG image file and stores it in YUV format
ffmpeg -i image.jpg -pix_fmt yuv420p image.yuv
The following command can be used to resize the JPEG image
ffmpeg -i image.jpg -vf scale=width:height output.jpg
(or)
ffmpeg -i image.jpg -vf scale=1280:720 output.jpg
The following command can be used to convert JPG image to BMP image format
ffmpeg -i image.jpg image.bmp
To make individual still images from the compressed video
ffmpeg -i inputfile %03d.jpg
To make individual still images from the YUV file
ffmpeg -s:v 1280x720 -pix_fmt yuv420p -i inputyuvfile %03d.jpg
To make individual still images from the YUV file with good quality
ffmpeg -s:v 1280x720 -pix_fmt yuv420p -i inputyuvfile -q 1 %03d.jpg
To make individual still images from the YUV file from YUV420SP NV12
ffmpeg -s:v 1280x720 -pix_fmt nv12 -i inputyuvfile -q 1 %03d.jpg
Audio Processing with FFMPEG
FFMPEG can also be used to convert/transcode audio files compressed with MP3 codec to AAC using the following command
ffmpeg -i input.mp3 -c:a libvo_aacenc -b:a 128k output.m4a
(or)
ffmpeg -i input.mp3 -acodec aac -ab 128k -strict experimental output.m4a
where the parameters present next to the following parameters
-c:a or -acodec represents output codec type
-i represents input file
-b:a or -ab represents bitrate of the output audio
There are lot of color spaces available like RGB, CMYK, HSV, YUV, CIELAB etc., The one that is widely used for video processing is YUV color space. YUV was invented when engineers wanted color television in a black and white infrastructure. They needed a signal transmission method that was compatible with black-and-white TV being able to add color. The luma component already existed as the black-and-white signal, they added the UV signal to this as a solution. More details here.
Inputs to the Image and Video Processing will be generally YUV files. Input video will be usually in YUV 4:2:0 chroma subsampled format. More details here.
Sample YUV sequences can be downloaded from here.
Video Processing with FFMPEG
The below command resizes the input YUV video of resolution 1920x1080 in YUV 4:2:0 format to 1280x720 YUV video
ffmpeg -s:v 1920x1080 -i input.yuv -vf scale=1280:720 -c:v rawvideo -pix_fmt yuv420p output.yuv
The below command decodes the video file in YUV 4:2:2 (YUYV) format
ffmpeg -i input.mp4 -pix_fmt yuyv422 output.yuv
The below command decodes the video file in YUV 4:2:2 (YUYV) format and scales to 1280x720
ffmpeg -i input.mp4 -pix_fmt yuyv422 -vf scale=1280:720 output.yuv
The below command decodes the video file in YUV 4:2:0 format
ffmpeg -i input.mp4 -pix_fmt yuv420p output.yuv
The below command decodes the video file in YUV 4:2:0 format and scales to 1280x720
ffmpeg -i input.mp4 -pix_fmt yuv420p -vf scale=1280:720 output.yuv
If you want to resize to some other resolution change the width and height assigned to the parameter scale.
To compress the YUV file of resolution 1280x720, frame rate 30 fps in H.264 video format at 5 Mbps
ffmpeg -s:v 1280x720 -i input.yuv -vcodec h264 -r 30 -pix_fmt yuv420p -b:v 5000k output.h264
To compress the above video in MPEG4 video format
ffmpeg -s:v 1280x720 -i input.yuv -vcodec mpeg4 -r 30 -pix_fmt yuv420p -b:v 5000k output.m4v
where the parameters present next to the following parameters
-s:v represents input resolution
-i represents input file
-vcodec represents output codec type
-r represents frame rate of the output video
-pix_fmt represents input video YUV chroma subsampling format
-b:v represents bitrate of the output video
Image Processing with FFMPEG
The following command decompresses the JPEG image file and stores it in YUV format
ffmpeg -i image.jpg -pix_fmt yuv420p image.yuv
The following command can be used to resize the JPEG image
ffmpeg -i image.jpg -vf scale=width:height output.jpg
(or)
ffmpeg -i image.jpg -vf scale=1280:720 output.jpg
The following command can be used to convert JPG image to BMP image format
ffmpeg -i image.jpg image.bmp
To make individual still images from the compressed video
ffmpeg -i inputfile %03d.jpg
To make individual still images from the YUV file
ffmpeg -s:v 1280x720 -pix_fmt yuv420p -i inputyuvfile %03d.jpg
To make individual still images from the YUV file with good quality
ffmpeg -s:v 1280x720 -pix_fmt yuv420p -i inputyuvfile -q 1 %03d.jpg
To make individual still images from the YUV file from YUV420SP NV12
ffmpeg -s:v 1280x720 -pix_fmt nv12 -i inputyuvfile -q 1 %03d.jpg
The parameter -q van vary from 1 to 100. Lower the value higher the quality.
Cropping image file
ffmpeg -i inputyuvfile -filter:v "crop=out_w:out_h:left:top" outputfile
Placing 2 images side by side
ffmpeg -i inputfile1 -i inputfile2 -filter_complex hstack outputfile
Cropping image file
ffmpeg -i inputyuvfile -filter:v "crop=out_w:out_h:left:top" outputfile
Placing 2 images side by side
ffmpeg -i inputfile1 -i inputfile2 -filter_complex hstack outputfile
FFMPEG can also be used to convert/transcode audio files compressed with MP3 codec to AAC using the following command
ffmpeg -i input.mp3 -c:a libvo_aacenc -b:a 128k output.m4a
(or)
ffmpeg -i input.mp3 -acodec aac -ab 128k -strict experimental output.m4a
where the parameters present next to the following parameters
-c:a or -acodec represents output codec type
-i represents input file
-b:a or -ab represents bitrate of the output audio
To decompress the audio file and store it as PCM samples use the following command
ffmpeg -i input.mp3 output.wav
To compress the uncompressed raw PCM audio samples in wav file to compressed MP3 & AAC format use the below commands
ffmpeg -i input.wav -c:a mp3 -b:a 128k output.mp3
ffmpeg -i input.wav -c:a libvo_aacenc -b:a 128k output.m4a
(or)
ffmpeg -i input.wav -acodec aac -ab 128k -strict experimental output.m4a
Combining Audio and Video files
Suppose if we have video and audio in elementary stream format and we can use the following command to mix them
ffmpeg -i videofile -i audiofile -c:v copy -c:a copy -strict experimental output.mp4
The above command does not perform any processing on the audio and video samples when we use -c:a copy and -c:v copy. It simply copies the contents and packs them in the MP4 container.
Listing all the supported pixel formats
This command lists all the supported pixel formats of FFMPEG
ffmpeg -pix_fmts
Converting RAW (Grayscale) frames to JPEG
Let's say we have a monochrome camera sensor attached to the SoC and the MIPI interface gives us a dump of the camera sensor frames and we want to save the dumped frame as JPEG file, use the following command
ffmpeg -s:v 2592x1944 -pix_fmt gray -i output.raw output.jpg
TV not playing audio for certain files
Often we would have seen certain TV's while playing videos fail to play audio. Use the following command to fix this issue. Almost all of the TV support AAC audio format and the following command converts the audio to AAC format, stores both the video and AAC audio in MP4 container format.
ffmpeg -i inputfile -vcodec copy -acodec aac -ab 128k -strict experimental outfile.mp4
Capture uncompressed videos from webcam with FFMPEG
ffmpeg -f video4linux2 -r 30 -s 640x480 -i /dev/video0 output.avi
If the above command is executed on Laptop /dev/video0 by default selects the Integrated webcam. To capture from external webcam on Laptop change it to /dev/video1.
Conclusion
This article just provides an overview of FFMPEG usage. It can be used at most of the places where we deal with multimedia data. FFMPEG is swiss army knife of multimedia processing. I will provide more insights in the next blogs.
ffmpeg -i input.mp3 output.wav
To compress the uncompressed raw PCM audio samples in wav file to compressed MP3 & AAC format use the below commands
ffmpeg -i input.wav -c:a mp3 -b:a 128k output.mp3
ffmpeg -i input.wav -c:a libvo_aacenc -b:a 128k output.m4a
(or)
ffmpeg -i input.wav -acodec aac -ab 128k -strict experimental output.m4a
Combining Audio and Video files
Suppose if we have video and audio in elementary stream format and we can use the following command to mix them
ffmpeg -i videofile -i audiofile -c:v copy -c:a copy -strict experimental output.mp4
The above command does not perform any processing on the audio and video samples when we use -c:a copy and -c:v copy. It simply copies the contents and packs them in the MP4 container.
Listing all the supported pixel formats
This command lists all the supported pixel formats of FFMPEG
ffmpeg -pix_fmts
Converting RAW (Grayscale) frames to JPEG
Let's say we have a monochrome camera sensor attached to the SoC and the MIPI interface gives us a dump of the camera sensor frames and we want to save the dumped frame as JPEG file, use the following command
ffmpeg -s:v 2592x1944 -pix_fmt gray -i output.raw output.jpg
TV not playing audio for certain files
Often we would have seen certain TV's while playing videos fail to play audio. Use the following command to fix this issue. Almost all of the TV support AAC audio format and the following command converts the audio to AAC format, stores both the video and AAC audio in MP4 container format.
ffmpeg -i inputfile -vcodec copy -acodec aac -ab 128k -strict experimental outfile.mp4
Capture uncompressed videos from webcam with FFMPEG
ffmpeg -f video4linux2 -r 30 -s 640x480 -i /dev/video0 output.avi
If the above command is executed on Laptop /dev/video0 by default selects the Integrated webcam. To capture from external webcam on Laptop change it to /dev/video1.
Conclusion
This article just provides an overview of FFMPEG usage. It can be used at most of the places where we deal with multimedia data. FFMPEG is swiss army knife of multimedia processing. I will provide more insights in the next blogs.
Tuesday, October 21, 2014
UVC Descriptors for Enumeration - USB 2.0
/* Define this flag to add 720p10 support to USB 2.0 */
#define NEW_USB2_MODE
/* Standard High Speed Configuration Descriptor - USB 2.0 */
const uint8_t esUSBHSConfigDscr[] =
{
/* Configuration descriptor */
0x09, /* Descriptor size */
CY_U3P_USB_CONFIG_DESCR, /* Configuration descriptor type */
#ifdef NEW_USB2_MODE
0xFA,0x00, /* Length of this descriptor and all sub descriptors */
#else
0xDC,0x00, /* Length of this descriptor and all sub descriptors */
#endif
0x02, /* Number of interfaces */
0x01, /* Configuration number */
0x00, /* COnfiguration string index */
0x80, /* Config characteristics - bus powered */
0xFA, /* Max power consumption of device (in 2mA unit) : 500mA */
/* Interface association descriptor */
0x08, /* Descriptor size */
ES_INTF_ASSN_DSCR_TYPE, /* Interface association descr type */
0x00, /* I/f number of first video control i/f */
0x02, /* Number of video streaming i/f */
0x0E, /* CC_VIDEO : Video i/f class code */
0x03, /* SC_VIDEO_INTERFACE_COLLECTION : subclass code */
0x00, /* Protocol : not used */
0x00, /* String desc index for interface */
/* Standard video control interface descriptor */
0x09, /* Descriptor size */
CY_U3P_USB_INTRFC_DESCR, /* Interface descriptor type */
0x00, /* Interface number */
0x00, /* Alternate setting number */
0x01, /* Number of end points */
0x0E, /* CC_VIDEO : Interface class */
0x01, /* CC_VIDEOCONTROL : Interface sub class */
0x00, /* Interface protocol code */
0x00, /* Interface descriptor string index */
/* Class specific VC interface header descriptor */
0x0D, /* Descriptor size */
0x24, /* Class Specific I/f header descriptor type */
0x01, /* Descriptor sub type : VC_HEADER */
0x00,0x01, /* Revision of class spec : 1.0 */
0x50,0x00, /* Total size of class specific descriptors (till output terminal) */
0x00,0x6C,0xDC,0x02, /* Clock frequency : 48MHz */
0x01, /* Number of streaming interfaces */
0x01, /* Video streaming I/f 1 belongs to VC i/f */
/* Input (camera) terminal descriptor */
0x12, /* Descriptor size */
0x24, /* Class specific interface desc type */
0x02, /* Input Terminal Descriptor type */
0x01, /* ID of this terminal */
0x01,0x02, /* Camera terminal type */
0x00, /* No association terminal */
0x00, /* String desc index : not used */
0x00,0x00, /* No optical zoom supported */
0x00,0x00, /* No optical zoom supported */
0x00,0x00, /* No optical zoom supported */
0x03, /* Size of controls field for this terminal : 3 bytes */
0x2A,0x00,0x02, /* No controls supported */
/* Processing unit descriptor */
0x0C, /* Descriptor size */
0x24, /* Class specific interface desc type */
0x05, /* Processing unit descriptor type */
0x02, /* ID of this terminal */
0x01, /* Source ID : 1 : conencted to input terminal */
0x00,0x00, /* Digital multiplier */
0x03, /* Size of controls field for this terminal : 3 bytes */
0x5F,0x11,0x00, /* No controls supported */
0x00, /* String desc index : not used */
/* Extension unit descriptor */
0x1C, /* Descriptor size */
0x24, /* Class specific interface desc type */
0x06, /* Extension unit descriptor type */
0x03, /* ID of this terminal */
#if 1
0x4A,0x00,0xA6,0x29,
0x02,0xEB,0xAA,0x4D,
0x82,0xDB,0x35,0x56,
0x35,0x62,0xDE,0x9D,
#endif
#if 0
0xFF,0xFF,0xFF,0xFF, /* 16 byte GUID */
0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,
#endif
0x01, /* Number of controls in this terminal */
0x01, /* Number of input pins in this terminal */
0x02, /* Source ID : 2 : Connected to Proc Unit */
0x03, /* Size of controls field for this terminal : 3 bytes */
0x00,0x00,0x00, /* No controls supported */
0x00, /* String desc index : not used */
/* Output terminal descriptor */
0x09, /* Descriptor size */
0x24, /* Class specific interface desc type */
0x03, /* Output terminal descriptor type */
0x04, /* ID of this terminal */
0x01,0x01, /* USB Streaming terminal type */
0x00, /* No association terminal */
0x03, /* Source ID : 3 : connected to extn unit */
0x00, /* String desc index : not used */
/* Video control status interrupt endpoint descriptor */
0x07, /* Descriptor size */
CY_U3P_USB_ENDPNT_DESCR, /* Endpoint descriptor type */
ES_EP_CONTROL_STATUS, /* Endpoint address and description */
CY_U3P_USB_EP_INTR, /* Interrupt end point type */
0x40,0x00, /* Max packet size = 64 bytes */
0x08, /* Servicing interval : 8ms */
/* Class specific interrupt endpoint descriptor */
0x05, /* Descriptor size */
0x25, /* Class specific endpoint descriptor type */
CY_U3P_USB_EP_INTR, /* End point sub type */
0x40,0x00, /* Max packet size = 64 bytes */
/* Standard video streaming interface descriptor (alternate setting 0) */
0x09, /* Descriptor size */
CY_U3P_USB_INTRFC_DESCR, /* Interface descriptor type */
0x01, /* Interface number */
0x00, /* Alternate setting number */
0x00, /* Number of end points : zero bandwidth */
0x0E, /* Interface class : CC_VIDEO */
0x02, /* Interface sub class : CC_VIDEOSTREAMING */
0x00, /* Interface protocol code : undefined */
0x00, /* Interface descriptor string index */
/* Class-specific video streaming input header descriptor */
0x0E, /* Descriptor size */
0x24, /* Class-specific VS i/f type */
0x01, /* Descriptotor subtype : input header */
0x01, /* 1 format desciptor follows */
#ifdef NEW_USB2_MODE
0x6B,0x00, /* Total size of class specific VS descr */
#else
0x4D,0x00, /* Total size of class specific VS descr */
#endif
ES_EP_UVC_VIDEO, /* EP address for ISO video data */
0x01, /* No dynamic format change supported */
0x04, /* Output terminal ID : 4 */
0x02, /* Still image capture method 1 supported */
0x01, /* Hardware trigger supported for still image */
0x01, /* Hardware to initiate still image capture */
0x01, /* Size of controls field : 1 byte */
0x00, /* D2 : Compression quality supported */
/* Class specific VS format descriptor */
0x1B, /* Descriptor size */
0x24, /* Class-specific VS i/f type */
0x04, /* Descriptotor subtype : VS_FORMAT_MJPEG */
0x01, /* Format desciptor index */
#ifdef NEW_USB2_MODE
0x02, /* Number of frame descriptors */
#else
0x01, /* 1 Frame desciptor follows */
#endif
0x59, 0x55, 0x59, 0x32, /* guid */
0x00, 0x00,
0x10, 0x00,
0x80, 0x00,
0x00, 0xAA, 0x00, 0x38, 0x9B, 0x71,
0x10, /* bBitsPerPixel*/
0x01, /* Default frame index is 1 */
0x00, /* bAspectRatioX */
0x00, /* bAspectRatioY */
0x00, /* bmInterlaceFlags */
0x00, /* bCopyProtect */
/* Class specific Uncompressed VS frame descriptor */
/* VGA 30 FPS */
0x1E, /* Descriptor size */
0x24, /* Descriptor type*/
0x05, /* Subtype: uncompressed frame I/F */
0x01, /* Frame Descriptor Index */
0x00, /* Still image capture method 1 supported, fixed frame rate */
0x80,0x02, /* Width in pixel */
0xE0,0x01, /* Height in pixel */
0x00,0x00,0x08,0xCA, /* Min bit rate bits/s */
0x00,0x00,0x08,0xCA, /* Min bit rate bits/s */
0x00,0x60,0x09,0x00, /* Maximum video or still frame size in bytes(Deprecated)*/
0x15,0x16,0x05,0x00, /* Default frame interval */
0x01, /* Frame interval type : No of discrete intervals */
0x15,0x16,0x05,0x00, /* Frame interval 3 */
#ifdef NEW_USB2_MODE // KK
// 720p10 USB Device descriptor for USB 2.0
0x1E, /* Descriptor size */
0x24, /* Descriptor type*/
0x05, /* Subtype: uncompressed frame I/F */
0x02, /* Frame Descriptor Index */
0x00, /* Still image capture method 1 supported, fixed frame rate */
0x00,0x05, /* Width in pixel */
0xD0,0x02, /* Height in pixel */
0x00,0x00,0x08,0xCA, /* Min bit rate bits/s */
0x00,0x00,0x08,0xCA, /* Min bit rate bits/s */
0x00,0x20,0x1C,0x00, /* Maximum video or still frame size in bytes(Deprecated)*/
0x40,0x42,0x0F,0x00, /* Default frame interval */
0x01, /* Frame interval type : No of discrete intervals */
0x40,0x42,0x0F,0x00, /* Frame interval 3 */
#endif
/* Color matching descriptor */
0x06,
0x24,
0x0D,
0x00,
0x00,
0x00,
/* Standard video streaming interface descriptor (Alternate Setting 1) */
0x09, /* Descriptor size */
CY_U3P_USB_INTRFC_DESCR, /* Interface descriptor type */
0x01, /* Interface number */
0x01, /* Alternate setting number */
0x01, /* Number of end points : 1 ISO EP */
0x0E, /* Interface class : CC_VIDEO */
0x02, /* Interface sub class : CC_VIDEOSTREAMING */
0x00, /* Interface protocol code : Undefined */
0x00, /* Interface descriptor string index */
/* Endpoint descriptor for ISO streaming video data */
0x07, /* Descriptor size */
CY_U3P_USB_ENDPNT_DESCR, /* Endpoint descriptor type */
ES_EP_UVC_VIDEO, /* Endpoint address and description */
0x05, /* ISO End point : Async */
ES_EP_ISO_VIDEO_PKT_SIZE_L, /* 1 transaction per microframe */
ES_EP_ISO_VIDEO_PKT_SIZE_H, /* ES_EP_ISO_VIDEO_PKT_SIZE max bytes */
0x01, /* Servicing interval for data transfers */
};
#define NEW_USB2_MODE
/* Standard High Speed Configuration Descriptor - USB 2.0 */
const uint8_t esUSBHSConfigDscr[] =
{
/* Configuration descriptor */
0x09, /* Descriptor size */
CY_U3P_USB_CONFIG_DESCR, /* Configuration descriptor type */
#ifdef NEW_USB2_MODE
0xFA,0x00, /* Length of this descriptor and all sub descriptors */
#else
0xDC,0x00, /* Length of this descriptor and all sub descriptors */
#endif
0x02, /* Number of interfaces */
0x01, /* Configuration number */
0x00, /* COnfiguration string index */
0x80, /* Config characteristics - bus powered */
0xFA, /* Max power consumption of device (in 2mA unit) : 500mA */
/* Interface association descriptor */
0x08, /* Descriptor size */
ES_INTF_ASSN_DSCR_TYPE, /* Interface association descr type */
0x00, /* I/f number of first video control i/f */
0x02, /* Number of video streaming i/f */
0x0E, /* CC_VIDEO : Video i/f class code */
0x03, /* SC_VIDEO_INTERFACE_COLLECTION : subclass code */
0x00, /* Protocol : not used */
0x00, /* String desc index for interface */
/* Standard video control interface descriptor */
0x09, /* Descriptor size */
CY_U3P_USB_INTRFC_DESCR, /* Interface descriptor type */
0x00, /* Interface number */
0x00, /* Alternate setting number */
0x01, /* Number of end points */
0x0E, /* CC_VIDEO : Interface class */
0x01, /* CC_VIDEOCONTROL : Interface sub class */
0x00, /* Interface protocol code */
0x00, /* Interface descriptor string index */
/* Class specific VC interface header descriptor */
0x0D, /* Descriptor size */
0x24, /* Class Specific I/f header descriptor type */
0x01, /* Descriptor sub type : VC_HEADER */
0x00,0x01, /* Revision of class spec : 1.0 */
0x50,0x00, /* Total size of class specific descriptors (till output terminal) */
0x00,0x6C,0xDC,0x02, /* Clock frequency : 48MHz */
0x01, /* Number of streaming interfaces */
0x01, /* Video streaming I/f 1 belongs to VC i/f */
/* Input (camera) terminal descriptor */
0x12, /* Descriptor size */
0x24, /* Class specific interface desc type */
0x02, /* Input Terminal Descriptor type */
0x01, /* ID of this terminal */
0x01,0x02, /* Camera terminal type */
0x00, /* No association terminal */
0x00, /* String desc index : not used */
0x00,0x00, /* No optical zoom supported */
0x00,0x00, /* No optical zoom supported */
0x00,0x00, /* No optical zoom supported */
0x03, /* Size of controls field for this terminal : 3 bytes */
0x2A,0x00,0x02, /* No controls supported */
/* Processing unit descriptor */
0x0C, /* Descriptor size */
0x24, /* Class specific interface desc type */
0x05, /* Processing unit descriptor type */
0x02, /* ID of this terminal */
0x01, /* Source ID : 1 : conencted to input terminal */
0x00,0x00, /* Digital multiplier */
0x03, /* Size of controls field for this terminal : 3 bytes */
0x5F,0x11,0x00, /* No controls supported */
0x00, /* String desc index : not used */
/* Extension unit descriptor */
0x1C, /* Descriptor size */
0x24, /* Class specific interface desc type */
0x06, /* Extension unit descriptor type */
0x03, /* ID of this terminal */
#if 1
0x4A,0x00,0xA6,0x29,
0x02,0xEB,0xAA,0x4D,
0x82,0xDB,0x35,0x56,
0x35,0x62,0xDE,0x9D,
#endif
#if 0
0xFF,0xFF,0xFF,0xFF, /* 16 byte GUID */
0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,
#endif
0x01, /* Number of controls in this terminal */
0x01, /* Number of input pins in this terminal */
0x02, /* Source ID : 2 : Connected to Proc Unit */
0x03, /* Size of controls field for this terminal : 3 bytes */
0x00,0x00,0x00, /* No controls supported */
0x00, /* String desc index : not used */
/* Output terminal descriptor */
0x09, /* Descriptor size */
0x24, /* Class specific interface desc type */
0x03, /* Output terminal descriptor type */
0x04, /* ID of this terminal */
0x01,0x01, /* USB Streaming terminal type */
0x00, /* No association terminal */
0x03, /* Source ID : 3 : connected to extn unit */
0x00, /* String desc index : not used */
/* Video control status interrupt endpoint descriptor */
0x07, /* Descriptor size */
CY_U3P_USB_ENDPNT_DESCR, /* Endpoint descriptor type */
ES_EP_CONTROL_STATUS, /* Endpoint address and description */
CY_U3P_USB_EP_INTR, /* Interrupt end point type */
0x40,0x00, /* Max packet size = 64 bytes */
0x08, /* Servicing interval : 8ms */
/* Class specific interrupt endpoint descriptor */
0x05, /* Descriptor size */
0x25, /* Class specific endpoint descriptor type */
CY_U3P_USB_EP_INTR, /* End point sub type */
0x40,0x00, /* Max packet size = 64 bytes */
/* Standard video streaming interface descriptor (alternate setting 0) */
0x09, /* Descriptor size */
CY_U3P_USB_INTRFC_DESCR, /* Interface descriptor type */
0x01, /* Interface number */
0x00, /* Alternate setting number */
0x00, /* Number of end points : zero bandwidth */
0x0E, /* Interface class : CC_VIDEO */
0x02, /* Interface sub class : CC_VIDEOSTREAMING */
0x00, /* Interface protocol code : undefined */
0x00, /* Interface descriptor string index */
/* Class-specific video streaming input header descriptor */
0x0E, /* Descriptor size */
0x24, /* Class-specific VS i/f type */
0x01, /* Descriptotor subtype : input header */
0x01, /* 1 format desciptor follows */
#ifdef NEW_USB2_MODE
0x6B,0x00, /* Total size of class specific VS descr */
#else
0x4D,0x00, /* Total size of class specific VS descr */
#endif
ES_EP_UVC_VIDEO, /* EP address for ISO video data */
0x01, /* No dynamic format change supported */
0x04, /* Output terminal ID : 4 */
0x02, /* Still image capture method 1 supported */
0x01, /* Hardware trigger supported for still image */
0x01, /* Hardware to initiate still image capture */
0x01, /* Size of controls field : 1 byte */
0x00, /* D2 : Compression quality supported */
/* Class specific VS format descriptor */
0x1B, /* Descriptor size */
0x24, /* Class-specific VS i/f type */
0x04, /* Descriptotor subtype : VS_FORMAT_MJPEG */
0x01, /* Format desciptor index */
#ifdef NEW_USB2_MODE
0x02, /* Number of frame descriptors */
#else
0x01, /* 1 Frame desciptor follows */
#endif
0x59, 0x55, 0x59, 0x32, /* guid */
0x00, 0x00,
0x10, 0x00,
0x80, 0x00,
0x00, 0xAA, 0x00, 0x38, 0x9B, 0x71,
0x10, /* bBitsPerPixel*/
0x01, /* Default frame index is 1 */
0x00, /* bAspectRatioX */
0x00, /* bAspectRatioY */
0x00, /* bmInterlaceFlags */
0x00, /* bCopyProtect */
/* Class specific Uncompressed VS frame descriptor */
/* VGA 30 FPS */
0x1E, /* Descriptor size */
0x24, /* Descriptor type*/
0x05, /* Subtype: uncompressed frame I/F */
0x01, /* Frame Descriptor Index */
0x00, /* Still image capture method 1 supported, fixed frame rate */
0x80,0x02, /* Width in pixel */
0xE0,0x01, /* Height in pixel */
0x00,0x00,0x08,0xCA, /* Min bit rate bits/s */
0x00,0x00,0x08,0xCA, /* Min bit rate bits/s */
0x00,0x60,0x09,0x00, /* Maximum video or still frame size in bytes(Deprecated)*/
0x15,0x16,0x05,0x00, /* Default frame interval */
0x01, /* Frame interval type : No of discrete intervals */
0x15,0x16,0x05,0x00, /* Frame interval 3 */
#ifdef NEW_USB2_MODE // KK
// 720p10 USB Device descriptor for USB 2.0
0x1E, /* Descriptor size */
0x24, /* Descriptor type*/
0x05, /* Subtype: uncompressed frame I/F */
0x02, /* Frame Descriptor Index */
0x00, /* Still image capture method 1 supported, fixed frame rate */
0x00,0x05, /* Width in pixel */
0xD0,0x02, /* Height in pixel */
0x00,0x00,0x08,0xCA, /* Min bit rate bits/s */
0x00,0x00,0x08,0xCA, /* Min bit rate bits/s */
0x00,0x20,0x1C,0x00, /* Maximum video or still frame size in bytes(Deprecated)*/
0x40,0x42,0x0F,0x00, /* Default frame interval */
0x01, /* Frame interval type : No of discrete intervals */
0x40,0x42,0x0F,0x00, /* Frame interval 3 */
#endif
/* Color matching descriptor */
0x06,
0x24,
0x0D,
0x00,
0x00,
0x00,
/* Standard video streaming interface descriptor (Alternate Setting 1) */
0x09, /* Descriptor size */
CY_U3P_USB_INTRFC_DESCR, /* Interface descriptor type */
0x01, /* Interface number */
0x01, /* Alternate setting number */
0x01, /* Number of end points : 1 ISO EP */
0x0E, /* Interface class : CC_VIDEO */
0x02, /* Interface sub class : CC_VIDEOSTREAMING */
0x00, /* Interface protocol code : Undefined */
0x00, /* Interface descriptor string index */
/* Endpoint descriptor for ISO streaming video data */
0x07, /* Descriptor size */
CY_U3P_USB_ENDPNT_DESCR, /* Endpoint descriptor type */
ES_EP_UVC_VIDEO, /* Endpoint address and description */
0x05, /* ISO End point : Async */
ES_EP_ISO_VIDEO_PKT_SIZE_L, /* 1 transaction per microframe */
ES_EP_ISO_VIDEO_PKT_SIZE_H, /* ES_EP_ISO_VIDEO_PKT_SIZE max bytes */
0x01, /* Servicing interval for data transfers */
};
Wednesday, July 30, 2014
Capturing video from camera device under Linux
Uses the video4linux2 (or simply v4l2) input device to capture live input such as from a webcam.
To list the supported, connected capture devices you can use the v4l-ctl tool. This example shows two connected webcams: /dev/video0 and /dev/video1.
$ v4l2-ctl --list-devices
Acer Crystal Eye webcam (usb-0000:00:1a.7-1):
/dev/video0
PATHPARTNER 5MP-OV-1 CAMERA (usb-0000:00:1d.7-1):
/dev/video1
Then adjust the value:
v4l2-ctl -c
asvkarthick@asvkarthick:~$ v4l2-ctl --list-formats
ioctl: VIDIOC_ENUM_FMT
Index : 0
Type : Video Capture
Pixel Format: 'YUYV'
Name : YUV 4:2:2 (YUYV)
asvkarthick@asvkarthick:~$ cat /dev/video
video0 video1
asvkarthick@asvkarthick:~$ v4l2-ctl --all
Driver Info (not using libv4l2):
Driver name : uvcvideo
Card type : Acer Crystal Eye webcam
Bus info : usb-0000:00:1a.7-1
Driver version: 3.2.55
Capabilities : 0x04000001
Video Capture
Streaming
Format Video Capture:
Width/Height : 640/480
Pixel Format : 'YUYV'
Field : None
Bytes per Line: 1280
Size Image : 614400
Colorspace : SRGB
Crop Capability Video Capture:
Bounds : Left 0, Top 0, Width 640, Height 480
Default : Left 0, Top 0, Width 640, Height 480
Pixel Aspect: 1/1
Video input : 0 (Camera 1: ok)
Streaming Parameters Video Capture:
Capabilities : timeperframe
Frames per second: 25.000 (25/1)
Read buffers : 0
avconv -f video4linux2 -i /dev/video0 video0.avi
Records the captured video frame into the file
To list the supported, connected capture devices you can use the v4l-ctl tool. This example shows two connected webcams: /dev/video0 and /dev/video1.
$ v4l2-ctl --list-devices
Acer Crystal Eye webcam (usb-0000:00:1a.7-1):
/dev/video0
PATHPARTNER 5MP-OV-1 CAMERA (usb-0000:00:1d.7-1):
/dev/video1
Adjusting camera functions
Brightness, zoom, focus, etc, can be adjusted with v4l2-ctl. Display all controls and their menus:$ v4l2-ctl -L brightness (int) : min=-64 max=64 step=1 default=-20 value=20 contrast (int) : min=0 max=95 step=1 default=0 value=0 saturation (int) : min=0 max=128 step=1 default=60 value=60 hue (int) : min=-40 max=40 step=1 default=-5 value=-5 white_balance_component_auto (bool) : default=1 value=1 white_balance_red_component (int) : min=1 max=500 step=1 default=100 value=100 white_balance_blue_component (int) : min=1 max=500 step=1 default=100 value=100 gamma (int) : min=72 max=500 step=1 default=110 value=110 power_line_frequency (menu) : min=0 max=2 default=2 value=2 0: Disabled 1: 50 Hz 2: 60 Hz sharpness (int) : min=0 max=7 step=1 default=2 value=2 backlight_compensation (int) : min=0 max=1 step=1 default=0 value=0
Then adjust the value:
v4l2-ctl -c
asvkarthick@asvkarthick:~$ v4l2-ctl --list-formats
ioctl: VIDIOC_ENUM_FMT
Index : 0
Type : Video Capture
Pixel Format: 'YUYV'
Name : YUV 4:2:2 (YUYV)
asvkarthick@asvkarthick:~$ cat /dev/video
video0 video1
asvkarthick@asvkarthick:~$ v4l2-ctl --all
Driver Info (not using libv4l2):
Driver name : uvcvideo
Card type : Acer Crystal Eye webcam
Bus info : usb-0000:00:1a.7-1
Driver version: 3.2.55
Capabilities : 0x04000001
Video Capture
Streaming
Format Video Capture:
Width/Height : 640/480
Pixel Format : 'YUYV'
Field : None
Bytes per Line: 1280
Size Image : 614400
Colorspace : SRGB
Crop Capability Video Capture:
Bounds : Left 0, Top 0, Width 640, Height 480
Default : Left 0, Top 0, Width 640, Height 480
Pixel Aspect: 1/1
Video input : 0 (Camera 1: ok)
Streaming Parameters Video Capture:
Capabilities : timeperframe
Frames per second: 25.000 (25/1)
Read buffers : 0
Records the captured video frame into the file
Saturday, August 3, 2013
MATLAB Code to convert the Image to Bayer Format(BGGR)
Img = imread('Input.jpg');
ImgBayer = Img;
ImgBayer(:, 2 : 2 : end, 3) = 0;
ImgBayer(2 : 2 : end, :, 3) = 0;
ImgBayer(1 : 2 : end, :, 1) = 0;
ImgBayer(:, 1 : 2 : end, 1) = 0;
ImgBayer(1 : 2 : end, 1 : 2 : end, 2) = 0;
ImgBayer(2 : 2 : end, 2 : 2 : end, 2) = 0;
imshow(ImgBayer)
imwrite(ImgBayer, 'IMG_Bayer.jpg');
ImgBayer = Img;
ImgBayer(:, 2 : 2 : end, 3) = 0;
ImgBayer(2 : 2 : end, :, 3) = 0;
ImgBayer(1 : 2 : end, :, 1) = 0;
ImgBayer(:, 1 : 2 : end, 1) = 0;
ImgBayer(1 : 2 : end, 1 : 2 : end, 2) = 0;
ImgBayer(2 : 2 : end, 2 : 2 : end, 2) = 0;
imshow(ImgBayer)
imwrite(ImgBayer, 'IMG_Bayer.jpg');
Tuesday, April 17, 2012
MATLAB Code to scale down the image height and scale up
% Read the image
Img = imread('plato.jpg');
% Downscale it
ihalf = Img(1 : 2 : end, :, :);
% Display the image
imshow(ihalf);
% Get the height and width of the original image
[height width dim] = size(Img);
ifull = zeros(height, width, dim);
% Upscale the image
ifull(1 : 2 : end, :, :) = ihalf;
ifull(2 : 2 : end, :, :) = ihalf;
ifull = uint8(ifull);
figure;
imshow(ifull);
Hope this works. Happy coding!!!
Img = imread('plato.jpg');
% Downscale it
ihalf = Img(1 : 2 : end, :, :);
% Display the image
imshow(ihalf);
% Get the height and width of the original image
[height width dim] = size(Img);
ifull = zeros(height, width, dim);
% Upscale the image
ifull(1 : 2 : end, :, :) = ihalf;
ifull(2 : 2 : end, :, :) = ihalf;
ifull = uint8(ifull);
figure;
imshow(ifull);
Hope this works. Happy coding!!!
Tuesday, May 24, 2011
Transrate - Converting audio files from one bitrate to other using BATCH file
Follow the below steps to transrate all the audio files with extension "mp3" in a given directory.
Download the FFMPEG software from the following link:
http://www.videohelp.com/download/ffmpeg-0.5.7z
Extract the software and copy the FFMPEG.exe and create a file with any name without space and extension "bat" and copy the below contents into it.
REM START OF BATCH FILE
mkdir Transcoded
for /f "delims=" %%a IN ('dir /b/n *.mp3') do (
ffmpeg -i "%%a" -ar 44100 -ac 2 -ab 128 -f mp3 ".\Transcoded\%%a"
)
cd Transcoded
for /f "delims=" %%a IN ('dir /b/n *.mp3') do (
move /Y "%%a" "..\%%a"
)
cd ..
del /Q Transcoded
rmdir /Q Transcoded
REM END OF BATCH FILE
Copy these 2 files into the directory which has the MP3 files that you want to transrate.
Double click the batch file for transrate. This batch file converts the audio bitrate to 128kbps. If one wants a different bitrate, change the number near to -ab option to the desired value.
Download the FFMPEG software from the following link:
http://www.videohelp.com/download/ffmpeg-0.5.7z
Extract the software and copy the FFMPEG.exe and create a file with any name without space and extension "bat" and copy the below contents into it.
REM START OF BATCH FILE
mkdir Transcoded
for /f "delims=" %%a IN ('dir /b/n *.mp3') do (
ffmpeg -i "%%a" -ar 44100 -ac 2 -ab 128 -f mp3 ".\Transcoded\%%a"
)
cd Transcoded
for /f "delims=" %%a IN ('dir /b/n *.mp3') do (
move /Y "%%a" "..\%%a"
)
cd ..
del /Q Transcoded
rmdir /Q Transcoded
REM END OF BATCH FILE
Copy these 2 files into the directory which has the MP3 files that you want to transrate.
Double click the batch file for transrate. This batch file converts the audio bitrate to 128kbps. If one wants a different bitrate, change the number near to -ab option to the desired value.
Tuesday, January 11, 2011
SCILAB - An Open Source alternative to MATLAB
Scilab is an open source, cross-platform numerical computational package and a high level, numerically oriented programming language. It can be used for signal processing, statistical analysis, image enhancement, fluid dynamics simulations, numerical optimization, and modeling and simulation of explicit and implicit dynamical systems. MATLAB code, which is similar in syntax, can be converted to Scilab. Scilab is one of several open source alternatives to MATLAB.
Scilab Downloads:
Linux version download
Windows version download
Scilab Downloads:
Linux version download
Windows version download
Subscribe to:
Posts (Atom)