Ask Your Question
1

Cannot read a 10-bit, 3-channel encoded video file as 10-bit

asked 2014-02-03 17:23:55 -0500

Nate gravatar image

updated 2014-02-04 10:07:02 -0500

Hello all,

I'm running into a problem reading a 10-bit, 3-channel encoded video that was saved from a high definition camera we have. I checked the file using GSpot, and it is encoded using the "Optibase VideoPump 10-bit 4:2:2 Component Y'CbCr" codec (v210).

I can read in frames using OpenCV's VideoCapture class from the file. I can even display the frames just fine using OpenCV's imshow function. Unfortunately, the cv::Mat object that the frames are saved into is of an 8-bit type (CV_8UC3).

Here is the code that I am using to read the video file:

   std::cout<< "Attempting to open file:  "<< filename<< std::endl;
   cv::VideoCapture videoIn;
   videoIn.open( filename);
   if( !videoIn.isOpened())
      throw "Error when reading stream!";

   if( !videoIn.read( frame))
      return 0;

   int type= frame.type();  // Returns 16 (CV_8UC3)

Like I said earlier, frames are being read and displayed, but when I check frame.type(), it returns 16 (CV_8UC3). Since I am trying to get the extra precision by using 10-bits, this is suboptimal.

Does anyone know how to actually read the frames at 10-bit?

Thanks!

-Nate

edit retag flag offensive close merge delete

Comments

What about using:

CV_16UC3

It is 16 bits big or 6 bit bigger than 10, and it is 3 channels.

keghn gravatar imagekeghn ( 2014-02-04 15:34:40 -0500 )edit

Thanks for the feedback keghn! I would love for it to read in as CV_16UC3. At 10 bit, that's actually what I would expect. Unfortunately, there does not seem to be a way to instruct the VideoCapture object to do that. At least not that I have found.

Nate gravatar imageNate ( 2014-02-04 23:41:24 -0500 )edit

You would like to have an option like the CV_RETRIEVE_ANY_DEPTH option in the imread fuction... Doesn't the source code of the VideoCapture interface uses the imread function on a certain moment? You might be able to change it there and rebuilt it yourself.

StevenPuttemans gravatar imageStevenPuttemans ( 2014-02-05 03:54:55 -0500 )edit
1

Thanks for the suggestion StevenPuttemans! I've not dug into the inner workings of OpenCV before. I'll have to download the source code and have a look at the internals of VideoCapture later today.

Nate gravatar imageNate ( 2014-02-05 10:04:45 -0500 )edit
1

Well, I downloaded the OpenCV source code and tried to figure out if there was some internal setting for VideoCapture that I could set to get it to read 10-bit video files. I couldn't find any reference to a "CV_RETRIEVE_ANY_DEPTH" setting, but the OpenCV source does have CV_LOAD_IMAGE_ANYDEPTH and IMREAD_ANYDEPTH preprocessor directives. Unfortunately, I could not track down where, if at all, these preprocessor directives might be used in VideoCapture. VideoCapture seems like it is a wrapper on top of IPL calls. Quite frankly, without a detailed system architecture diagram and writeup for OpenCV's video processing system, figuring this out is quite beyond me. At this point, I have to conclude OpenCV is not the right tool for reading and processing high-bitrate video files.

Nate gravatar imageNate ( 2014-02-06 10:53:13 -0500 )edit
1

Of course, if anyone has any alternative tools to OpenCV that might be viable, please post and let me know!

Nate gravatar imageNate ( 2014-02-06 11:08:33 -0500 )edit
1

Yeah digging into this is indead quite hard. You could however add a feature request on the development forum of openCV. It might encourage someone who has an idea to implement this feature.

StevenPuttemans gravatar imageStevenPuttemans ( 2014-02-07 01:50:30 -0500 )edit

2 answers

Sort by ยป oldest newest most voted
1

answered 2014-02-28 09:53:06 -0500

Nate gravatar image

Alright, so I didn't get direct 10-bit video reading in OpenCV working per se, but I did get a complicated, "hacky" solution that worked well enough to test whether the extra bit depth going from 8-bit video to 10-bit video was helpful.

So here is what I did:

  1. Used FFMPEG to convert the (10-bit) video from a v210-encoded AVI file into a series of (16-bit) PNG image files, one image file for each frame of the video. Obviously, this takes a tremendous amount of hard drive space. The 10-bits in the original seems to have been stretched to the 16-bit (I assume by adding 6 zero bits of padding to the end).
  2. Read the 16-bit PNG files in sequentially and process them as if they were frames in a video. They actually get read in a CV_16UC3 images!

And that's how I did it. This solution is ugly, hacky, and slow, but it worked.

-Nate

edit flag offensive delete link more

Comments

Hmmm this is indeed a 'hacky' way. Someone should add this to the videoWriter directive. Care to create a bug report at the dev forum?

StevenPuttemans gravatar imageStevenPuttemans ( 2014-03-10 07:27:14 -0500 )edit
1

answered 2015-01-07 14:46:07 -0500

Hi Nate!

I had the same problem, and I created a solution using OpenCV's functions. Do you want know the solution, or this problem is no longer important? In my case, I received raw data (uncompress video, and the data was in an array of char) from multiples camera feeds (this scenario involved channels Y, U and V separated, different values of chroma subsampling and different values of bit rate). When the Bit Depth was equal to 10-bit I had problems with OpenCV. Using cv::Mat( int height, int width, CV_16UC, (unsigned char*) feed_channel_Y) i didn't had a successful results. In my opinion i think if you use the function cv::VideoCapture, you won't get good results.

To get a solution for this problem, I made some conversions on video data. But remember I worked with uncompressed video data, the video didn't have any codec.

Cheers, Victor

edit flag offensive delete link more

Comments

Thanks for the information Victor!

This problem is no longer important to me--I was simply trying to check out if 10-bit video would provide useful extra information for a specific problem. After running my hacky solution, it turned out it wasn't worth pursuing further.

Glad you were able to find something that worked though! This was an annoying problem. :o)

-Nate

Nate gravatar imageNate ( 2015-01-29 12:50:41 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2014-02-03 17:23:55 -0500

Seen: 3,625 times

Last updated: Jan 07 '15