Skip to content

Create avi container for mjpeg#10145

Merged
opencv-pushbot merged 1 commit intoopencv:masterfrom
allnes:vedeoio_avi_container
Feb 15, 2018
Merged

Create avi container for mjpeg#10145
opencv-pushbot merged 1 commit intoopencv:masterfrom
allnes:vedeoio_avi_container

Conversation

@allnes
Copy link
Copy Markdown
Member

@allnes allnes commented Nov 23, 2017

No description provided.


AviMjpegStream mjpeg_video_stream;
bool is_parsed = mjpeg_video_stream.parseAvi(in_str, m_mjpeg_frames);
AVIReadContainer<MjpegInputStream> mjpeg_video_stream;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will be better to move MjpegInputStream to the same place where AVIReadContainer is located, then you will be able to avoid templates in the code.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mshabunin And unless the task was not to separate mjpeg codec and avi container, it turns out they will be together to one file again

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see a problem here: MjpegInputStream is just a convenient object for reading AVI files, it does not implement MJPEG specific behavior.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mshabunin I already remade, you can see

AviStreamHeader strm_hdr;
*in_str >> strm_hdr;

if(strm_hdr.fccType == VIDS_CC && strm_hdr.fccHandler == MJPG_CC)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably we should pass FourCC code (MJPG_CC here) as a parameter into this method.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mshabunin corrected



bool MotionJpegCapture::parseRiff(MjpegInputStream& in_str)
bool MotionJpegCapture::parseRiff()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this method can be moved to the AVIReadContainer class.

@@ -781,17 +140,17 @@ double MotionJpegCapture::getProperty(int property) const

std::vector<char> MotionJpegCapture::readFrame(frame_iterator it)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this method can be moved to the AVIReadContainer class.

void MotionJpegCapture::close()
{
m_file_stream.close();
m_avi_container.getStream()->close();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is better to avoid exposing internal stream. You can either provide AVIReadContainer::release method or, even better, to create new m_avi_container object for each opened file (store it in Ptr):

Ptr<AVIReadContainer> avi;
...
MotionJpegCapture::MotionJpegCapture(const String& filename)
{
    avi = makePtr<AVIReadContainer>(filename);
    ...
}

 bool MotionJpegCapture::open(const String& filename)
 {
    avi = makePtr<AVIReadContainer>(filename);
    ...
}

@@ -0,0 +1,479 @@
/*M///////////////////////////////////////////////////////////////////////////////////////
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use short license in all new files:

// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.

${CMAKE_CURRENT_LIST_DIR}/src/cap_images.cpp
${CMAKE_CURRENT_LIST_DIR}/src/cap_mjpeg_encoder.cpp
${CMAKE_CURRENT_LIST_DIR}/src/cap_mjpeg_decoder.cpp
${CMAKE_CURRENT_LIST_DIR}/src/cap_avi_container.cpp
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's rename cap_avi_container.cpp to container_avi.cpp.

#include "precomp.hpp"
#include <deque>
#include <stdint.h>
#include "opencv2/core/private.cap_avi_container.hpp"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's rename this header to container_avi.private.hpp and it should be moved to the videoio module.

bool m_is_indx_present;
};

static const int AVIH_STRH_SIZE = 56;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All variables and functions marked static should be moved to the .cpp file.


#include "test_precomp.hpp"
#include "opencv2/core/private.cap_avi_container.hpp"
#include "opencv2/highgui.hpp"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This include should be removed.

@mshabunin mshabunin self-assigned this Jan 25, 2018
@mshabunin
Copy link
Copy Markdown
Contributor

@allnes , we have updated test writing guidelines, please take a look: https://github.com/opencv/opencv/wiki/Coding_Style_Guide#implementing-tests

You have to wrap your test into namespace opencv_test.


using namespace cv;
using namespace std;
using namespace opencv_test;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All source code should be put into this namespace.

#include <cstdio>

using namespace cv;
using namespace std;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid using namespace std. Use std:: if necessary (common types are imported into opencv_test namespace).

class BunnyParameters
{
private:
int bunny_width, bunny_height, bunny_fps, bunny_count;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not necessary to store values in the object:

class BunnyParameters {
public:
  inline static int getWidth() { return 672; }
  inline static getCount() { return cvRound(getFps() * getTime()); }
  ...

// call BunnyParameters::getCount()

Filename generation can be provided by this class too:

inline static String getFilename(const String &ext) { 
  return cvtest::TS::ptr()->get_data_path() + "video/big_buck_bunny" + ext; 
}

@allnes
Copy link
Copy Markdown
Member Author

allnes commented Feb 9, 2018

@mshabunin I'm fixed

ext = get<0>(GetParam());
apiPref = get<1>(GetParam());

video_file = cvtest::TS::ptr()->get_data_path() + "video/big_buck_bunny." + ext;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use bunny_param.getFilename(String(".") + ext) here.

{

TEST(videoio_avi, good_MJPG) {
String filename = cvtest::TS::ptr()->get_data_path() + "video/big_buck_bunny.mjpg.avi";
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should add BunnyParameters::getFilename(".mjpg.avi"); here for consistency.

@allnes
Copy link
Copy Markdown
Member Author

allnes commented Feb 14, 2018

@mshabunin fixed

#include "opencv2/core/cvdef.h"
#include "opencv2/videoio/videoio_c.h"
#include <deque>
#include <stdint.h>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is C++11/C11 header: http://www.cplusplus.com/reference/cstdint/ like uint32_t and other types.

@allnes
Copy link
Copy Markdown
Member Author

allnes commented Feb 15, 2018

@alalek fixed types, review please

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants