OpenCV Streaming formats - opencv

I'm trying to stream in video to my Linux machine. On the Linux side I'm using OpenCV. I tried to find a list of supported codecs but couldn't find any.
Where can I find a list of supported codecs that can be used with open CV?
Thanks,
Nahum

From here:
The mencoder video encoder is an open source video encoder which is
available on Mac OS X, Windows, and Linux. To convert existing videos
to the I420 format supported by OpenCV on all platforms, install the
mencoder binary and use:
$ mencoder in.avi -ovc raw -vf format=i420 -o out.avi
Looks like the I420 format is what you're looking for.

Related

OpenCV cannot read ffmpeg videos

I was unable to read video frames in OpenCV (python and c++) after using ffmpeg.
Specifically, I had the following problems:
1) unable to open the video file using VideoCapture.
2) able to open the video file using VideoCapture, but reading zero frames and/or receiving frames of size 0x0 pixels.
I am pasting my solution below, hoping this will help others.
These problems were encountered on Mac OS X Sierra 10.12.5, ffmpeg 3.2.4, Python 2.7.13, g++ 4.2.1
1) OpenCV cannot read as many video formats as ffmpeg. Therefore, it is often possible to play videos in VLC, but not to open them in OpenCV's VideoCapture. Hence, conversion with a tool such as ffmpeg is often required (see next point). One format that worked for me is h.264.
2) OpenCV seemed to require YUV420, whereas ffmpeg used YUV444 by default. Therefore, the following command solved my problems:
ffmpeg -i input.avi -c:v libx264 -vf format=yuv420p output.mp4

iOS Video Player FFmpeg

So I want to make an app for the iPhone that will play live mms:// video streams.
I have look around, and everywhere says that I'll need FFmpeg in order to accomplish it. So I successfully compiled the FFmpeg libraries, but now
Do I have to convert the mms:// link to a .m3u8 link? Or I can just use apples AV Foundation Framework ?
Thanks!
You need libmms as well as the ffmpeg libs ,however as think the latest versions of ffmpeg has the code built in so you may not need libmms mms is just a streaming protocol so the actual format is likely some mpeg variant, mp4, h264.
Once you have that you extract the frames , and use ffmpeg avcodec_decode_video2 to decode to an avFrame. Just like any other video.

how can I use the openCV FFMPEG video I/O rather than the DirectShow one in Windows?

So I'm trying to write a video using the openCV videoWriter as such:
writer=cv.CreateVideoWriter(path+"test_output.avi",-1,fps,(W,H),1)
So instead of supplying the FOURCC I supplied -1 in order to see what codecs I have available.
Result was Microsoft RLE, Microsoft Video 1, Intel YUV, and Uncompressed.
The reason is that when configuring openCV using CMAKE for Visual Studio 10 x64, this is what I have in the video i/o:
Video I/O: DirectShow
Is there a way to switch this to FFMPEG? I know the ffmpeg dll is present in \3dparty\ffmpeg.
I looked for Cmake FFMPEG flags but found none whatsoever. The weird thing is in the CmakeLists.txt in the opencv root under the video section:
if(UNIX AND NOT APPLE)
<FFMPEG stuff>
elseif(WIN32)
status(" Video I/O:" HAVE_VIDEOINPUT THEN DirectShow ELSE NO)
endif()
So it seems to me that opencv automatically switched to DirectShow and gives no choice of using FFMpeg.
Or rather can one upgrade Driectshow to support other formats such as Divx or h264?
Any ideas?
The answer your looking for is here and it works for the 32 bit and 64 bit configurations. I used this build of FFMPEG. http://ffmpeg.zeranoe.com/builds/win64/dev/ffmpeg-git-1aeb88b-win64-dev.7z
1) Download OpenCV 2.3
2) Open the root CMakeLists.txt and insert the line set(HAVE_FFMPEG 1)
3) Download http://ffmpeg.zeranoe.com/builds/win64/dev/ffmpeg-git-1aeb88b-win64-dev.7z (or the 32 bit build if u fancy it)
4) Edit avformat.h found in the ffmpeg include dir with #define INT64_C
5) Edit cap_ffmpeg_impl.hpp from the highgui project with #define snprintf _snprintf
6) in your highgui project properties under C/C++>Additional Include Directories add path of the include directory of FFMPEG you just downloaded
7)On the same property page under Linker>General>Additional Library Dependencies add the path of the lib directory of FFMPEG you just downloaded
8)On the same property page under Linker>Input>Additional dependencies add ALL the names of the libraries of ffmpeg found in lib (avformat.lib, avscale.lib, avcore.lib etc)
9) build the highgui project
10) Add the path of the .dll files that came with FFMPEG to the System Path environment variable.
That's it! 10 easy steps ;)
If you're still unable to compile OpenCV with FFMpeg support, the library that is linked on this blogpost provides a pretty good starting point for creating a windows-compatible FFMpeg wrapper: Making OpenCV-2.3 work with ffmpeg library and Microsoft Visual Studio 2010

OpenCV. How to identify i-frames only for a video file encoded in MPEG format

I need to extract only the i-frames from an MPEG encoded video file(it may be a .avi file or .mp4 file). Is it possible to atleast identify the i-frames.
It looks like this ffmpeg enhancement can accomplish this for you using the select filter to filter all I-Frames. You may need to build ffmpeg from source to get this capability I'm not sure. Here is an Ubuntu guide with the details, and here is where you can get the nightly Windows binary version.
EDIT: OpenCV relies on ffmpeg API's to capture video from a file. However, the functionality you want is a bit specific, so you are going to need to write your own custom filtering module with ffmpeg's libavfilter. Here is one of their how to guides on using libavfilter. In particular, as I mentioned above, you will probably want to use the select filter provided by libavfilter. This will filter all I-frames from the stream for you to process.
Hope that helps!

IplImage 'None' error on CaptureFromFile() - Python 2.7.1 and OpenCV 2.2 WinXP

I am running Python2.7.1 and OpenCV 2.2 without problems in my WinXP laptop and wrote a tracking program that is working without a glitch. But for some strange reason I cannot get the same program to run in any other computer where I tried to install OpenCV and Python (using the same binaries or appropriate 64 bit binaries). In those computers OpenCV seems to be correctly installed (although I have only tested and CaptureFromCamera() in the webcam of the laptop), but CaptureFromFile() return 'None' and give "error: Array should be CvMat or IplImage" after a QueryFrame, for example.
This simple code:
import cv /
videofile = cv.CaptureFromFile('a.avi') /
frame = cv.QueryFrame(videofile) /
print type(videofile) /
print type(frame)
returns:
type 'cv.Capture' /
type 'NoneType'
OpenCV and Python are in the windows PATH...
I have moved the OpenCV site-packages content back and forth to the Pyhton27 Lib\Site-packages folder.
I tried different avi files (just in case it was some CODEC problem). This AVI uses MJPEG encoding (and GSpot reports that ffdshow Video Decoder is used for reading).
Images work fine (I think): the simple convert code:
im = cv.LoadImageM("c:\tests\colormap3.tif")
cv.SaveImage("c:\tests\colormap3-out.png", im)
opens, converts and saves the new image...
I have tested with AVI files in different folders, using "c:\", "c:/", "c:\" and "c://".
I am lost here... Anyone has any idea of what stupid and noob mistake may be the cause of this? Thanks
It may sound stupid, but I just had the same issue with the same symptoms for the same code snippet (Python 2.7.1, Win 7, OpenCV 2.2.0). I changed file path from
capture = cv.CaptureFromFile('C:\Misc\tree.avi')
to
capture = cv.CaptureFromFile('C:/Misc/tree.avi')
and voila
<type 'cv.Capture'>
<type 'cv.iplimage'>
I was having this problem, and here is how I fixed it. I took a look at the output of OpenCV's cmake command, and it had the following line:
...
-- FFMPEG: NO
...
In order to fix this, you might be able to get away with simply installing the following libraries:
sudo apt-get install libavformat-dev libavcodec-dev libavfilter-dev libswscale-dev
Re-running cmake will hopefully now say:
...
-- FFMPEG: YES
...
Re-compile OpenCV, re-install it, and hopefully you can now read videos. If you still have problems, you can try to compile ffmpeg using the --enable-shared option, using these as guides:
http://opencv.willowgarage.com/wiki/FFMPEG
http://ubuntuforums.org/showthread.php?t=786095
Hope that helps.
This must be an issue with the default codecs. OpenCV uses brute force methods to open video files or capture from camera. It goes by trial and error through all sources/codecs/apis it can find in some reasonable order. (at least 1.1 did so).
That means that on n different systems (or days) you may get n different ways of accessing the same video. The order of multiple webcams for instance, is also non-deterministic and may depend on plugging order or butterflies.
Find out what your laptop uses, (re)install that on all the systems and retry.
Also, in the c version, you can look at the capture's properties
look for cvGetCaptureProperty and cvSetCaptureProperty where you might be able to hint to the format.
[EDIT]
Just looked i tup in the docs, these functions are also available in Python. Take a look, it should help.

Resources