# How do you identify the codec of a .mp4 video file in Xcode?

**URL:** <https://forum.opencv.org/t/how-do-you-identify-the-codec-of-a-mp4-video-file-in-xcode/4453>\
**Category:** C++\
**Tags:** xcode, ffmpeg, videoio, apple\
**Created:** [July 25, 2021, 1:59am UTC](https://forum.opencv.org/t/how-do-you-identify-the-codec-of-a-mp4-video-file-in-xcode/4453 "2021-07-25T01:59:44Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![sjsu\_alumna](https://avatars.discourse-cdn.com/v4/letter/s/6de8d8/32.png) [@sjsu\_alumna](https://forum.opencv.org/u/sjsu_alumna)\
**Post date:** [July 25, 2021, 1:59am UTC](https://forum.opencv.org/t/how-do-you-identify-the-codec-of-a-mp4-video-file-in-xcode/4453/1 "2021-07-25T01:59:44Z")

</div>

I tried

```auto
cv::VideoCapture cap( argv[1] );
unsigned f = (unsigned)cap.get( cv::CAP_PROP_FOURCC );
cout << "f: " << f << endl;

```

but output of f was 0. The codec of the video file is H.264.

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [July 25, 2021, 4:24pm UTC](https://forum.opencv.org/t/how-do-you-identify-the-codec-of-a-mp4-video-file-in-xcode/4453/2 "2021-07-25T16:24:57Z")

</div>

related

> <https://stackoverflow.com/questions/68515229/how-do-you-identify-the-codec-of-a-mp4-video-file-using-opencv-3-4-14-in-xcode>

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [July 25, 2021, 4:45pm UTC](https://forum.opencv.org/t/how-do-you-identify-the-codec-of-a-mp4-video-file-in-xcode/4453/3 "2021-07-25T16:45:27Z")

</div>

you should at least query, if your capture opened at all:

```auto
cv::VideoCapture cap(argv[1] );
if (! cap.isOpened()) ....

```

---

<div class="post-metadata">

**Author:** ![sjsu\_alumna](https://avatars.discourse-cdn.com/v4/letter/s/6de8d8/32.png) [@sjsu\_alumna](https://forum.opencv.org/u/sjsu_alumna)\
**Post date:** [July 25, 2021, 10:30pm UTC](https://forum.opencv.org/t/how-do-you-identify-the-codec-of-a-mp4-video-file-in-xcode/4453/4 "2021-07-25T22:30:00Z")

</div>

I was able to play the video using OpenCV. I’m wondering if the problem is related to ffmpeg, as suggested by the 1st answer in [https://stackoverflow.com/questions/47858206/c-opencv-3-4-ffmpeg-3-4-1-videowriter-and-mp4-output-file-format/54138523](https://stackoverflow.com/questions/47858206/c-opencv-3-4-ffmpeg-3-4-1-videowriter-and-mp4-output-file-format/54138523)

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [July 26, 2021, 5:21am UTC](https://forum.opencv.org/t/how-do-you-identify-the-codec-of-a-mp4-video-file-in-xcode/4453/5 "2021-07-26T05:21:43Z")

</div>

no, it is not related. you’re not using a Videowriter, and while _writing_ h264 has a liceense problem, reading is free.

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [July 27, 2021, 7:55am UTC](https://forum.opencv.org/t/how-do-you-identify-the-codec-of-a-mp4-video-file-in-xcode/4453/6 "2021-07-27T07:55:08Z")

</div>

since you say this is osx, the video backend might be AVFoundation, not ffmpeg.

do `cap.get(cv::CAP_PROP_BACKEND)`

---

<div class="post-metadata">

**Author:** ![sjsu\_alumna](https://avatars.discourse-cdn.com/v4/letter/s/6de8d8/32.png) [@sjsu\_alumna](https://forum.opencv.org/u/sjsu_alumna)\
**Post date:** [July 28, 2021, 4:51am UTC](https://forum.opencv.org/t/how-do-you-identify-the-codec-of-a-mp4-video-file-in-xcode/4453/7 "2021-07-28T04:51:30Z")

</div>

I tried CAP\_PROP\_BACKEND and now the output of f is 1200. The next lines of code are:

```auto
char fourcc[] = { (char) f, (char)(f >> 8), 
                  (char)(f >> 16), (char)(f >> 24),
                  '\0' };
cout << "fourcc: " << fourcc << endl;

```

Output of fourcc is \260, but it should be avc1, so I don’t think CAP\_PROP\_BACKEND gives the fourcc codec.

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [July 28, 2021, 5:35am UTC](https://forum.opencv.org/t/how-do-you-identify-the-codec-of-a-mp4-video-file-in-xcode/4453/8 "2021-07-28T05:35:53Z")

</div>

it doesn’t. `CAP_PROP_BACKEND` tells you the _backend_.

1200 is `CAP_AVFOUNDATION`

all your troubles stem from that.

open a VideoCapture with explicit `apiPreference`… with `CAP_FFMPEG`

---

<div class="post-metadata">

**Author:** ![sjsu\_alumna](https://avatars.discourse-cdn.com/v4/letter/s/6de8d8/32.png) [@sjsu\_alumna](https://forum.opencv.org/u/sjsu_alumna)\
**Post date:** [July 28, 2021, 7:14am UTC](https://forum.opencv.org/t/how-do-you-identify-the-codec-of-a-mp4-video-file-in-xcode/4453/9 "2021-07-28T07:14:31Z")

</div>

I tried:

```auto
  cv::VideoCapture cap;
  cap.open( string(argv[1]), cv::CAP_FFMPEG );
  if( !cap.isOpened() ) {
      cout << "Couldn't open capture." << endl;
      return -1;
  }

```

and the output was “Couldn’t open capture.”

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [July 28, 2021, 3:42pm UTC](https://forum.opencv.org/t/how-do-you-identify-the-codec-of-a-mp4-video-file-in-xcode/4453/10 "2021-07-28T15:42:20Z")

</div>

```cpp
std::cout << cv::getBuildInformation();

```

---

<div class="post-metadata">

**Author:** ![sjsu\_alumna](https://avatars.discourse-cdn.com/v4/letter/s/6de8d8/32.png) [@sjsu\_alumna](https://forum.opencv.org/u/sjsu_alumna)\
**Post date:** [August 1, 2021, 1:16am UTC](https://forum.opencv.org/t/how-do-you-identify-the-codec-of-a-mp4-video-file-in-xcode/4453/11 "2021-08-01T01:16:33Z")

</div>

I tried:

```auto
cout << cv::getBuildInformation() << endl;

```

and the output was:

> General configuration for OpenCV 3.4.14-dev =====================================  
> Version control: 3.4.14-17-g6f70b0524a
> 
> Extra modules:  
> Location (extra): /Users/myname/opencv\_contrib/modules  
> Version control (extra): 3.4.14-7-g31c657e0
> 
> Platform:  
> Timestamp: 2021-04-13T01:15:18Z  
> Host: Darwin 19.6.0 x86\_64  
> CMake: 3.20.1  
> CMake generator: Unix Makefiles  
> CMake build tool: /usr/bin/make  
> Configuration: RELEASE
> 
> CPU/HW features:  
> Baseline: SSE SSE2 SSE3 SSSE3 SSE4\_1  
> requested: DETECT  
> Dispatched code generation: SSE4\_2 FP16 AVX AVX2 AVX512\_SKX  
> requested: SSE4\_1 SSE4\_2 AVX FP16 AVX2 AVX512\_SKX  
> SSE4\_2 (2 files): + POPCNT SSE4\_2  
> FP16 (1 files): + POPCNT SSE4\_2 FP16 AVX  
> AVX (6 files): + POPCNT SSE4\_2 AVX  
> AVX2 (30 files): + POPCNT SSE4\_2 FP16 FMA3 AVX AVX2  
> AVX512\_SKX (7 files): + POPCNT SSE4\_2 FP16 FMA3 AVX AVX2 AVX\_512F AVX512\_COMMON AVX512\_SKX
> 
> C/C++:  
> Built as dynamic libs?: YES  
> C++ Compiler: /Library/Developer/CommandLineTools/usr/bin/c++ (ver 12.0.0.12000032)  
> C++ flags (Release): -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -fdiagnostics-show-option -Wno-long-long -Qunused-arguments -Wno-semicolon-before-method-body -ffunction-sections -fdata-sections -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG -DNDEBUG  
> C++ flags (Debug): -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -fdiagnostics-show-option -Wno-long-long -Qunused-arguments -Wno-semicolon-before-method-body -ffunction-sections -fdata-sections -fvisibility=hidden -fvisibility-inlines-hidden -g -O0 -DDEBUG -D\_DEBUG  
> C Compiler: /Library/Developer/CommandLineTools/usr/bin/cc  
> C flags (Release): -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -fdiagnostics-show-option -Wno-long-long -Qunused-arguments -Wno-semicolon-before-method-body -ffunction-sections -fdata-sections -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG -DNDEBUG  
> C flags (Debug): -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -fdiagnostics-show-option -Wno-long-long -Qunused-arguments -Wno-semicolon-before-method-body -ffunction-sections -fdata-sections -fvisibility=hidden -fvisibility-inlines-hidden -g -O0 -DDEBUG -D\_DEBUG  
> Linker flags (Release): -Wl,-dead\_strip  
> Linker flags (Debug): -Wl,-dead\_strip  
> ccache: NO  
> Precompiled headers: NO  
> Extra dependencies: /Library/Developer/CommandLineTools/SDKs/MacOSX11.1.sdk/System/Library/Frameworks/OpenGL.framework  
> 3rdparty dependencies:
> 
> OpenCV modules:  
> To be built: aruco bgsegm bioinspired calib3d ccalib core datasets dnn dnn\_objdetect dpm face features2d flann fuzzy hfs highgui img\_hash imgcodecs imgproc line\_descriptor ml objdetect optflow phase\_unwrapping photo plot python2 python3 reg rgbd saliency shape stereo stitching structured\_light superres surface\_matching text tracking ts video videoio videostab xfeatures2d ximgproc xobjdetect xphoto  
> Disabled: world  
> Disabled by dependency: -  
> Unavailable: cnn\_3dobj cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev cvv freetype hdf java matlab ovis sfm viz  
> Applications: tests perf\_tests examples apps  
> Documentation: NO  
> Non-free algorithms: NO
> 
> GUI:  
> QT: YES (ver 5.15.2)  
> QT OpenGL support: YES (Qt5::OpenGL 5.15.2)  
> Cocoa: YES  
> OpenGL support: YES (/Library/Developer/CommandLineTools/SDKs/MacOSX11.1.sdk/System/Library/Frameworks/OpenGL.framework /Library/Developer/CommandLineTools/SDKs/MacOSX11.1.sdk/System/Library/Frameworks/OpenGL.framework)  
> VTK support: NO
> 
> Media I/O:  
> ZLib: build (ver 1.2.11)  
> JPEG: build-libjpeg-turbo (ver 2.0.6-62)  
> WEBP: build (ver encoder: 0x020f)  
> PNG: build (ver 1.6.37)  
> TIFF: build (ver 42 - 4.2.0)  
> JPEG 2000: build (ver 1.900.1)  
> OpenEXR: build (ver 2.3.0)  
> HDR: YES  
> SUNRASTER: YES  
> PXM: YES
> 
> Video I/O:  
> DC1394: NO  
> FFMPEG: NO  
> avcodec: NO  
> avformat: NO  
> avutil: NO  
> swscale: NO  
> avresample: NO  
> GStreamer: NO  
> AVFoundation: YES  
> libv4l/libv4l2: NO  
> v4l/v4l2: NO
> 
> Parallel framework: GCD
> 
> Trace: YES (with Intel ITT)
> 
> Other third-party libraries:  
> Intel IPP: 2020.0.0 Gold [2020.0.0]  
> at: /Users/myname/opencv/build/3rdparty/ippicv/ippicv\_mac/icv  
> Intel IPP IW: sources (2020.0.0)  
> at: /Users/myname/opencv/build/3rdparty/ippicv/ippicv\_mac/iw  
> Lapack: YES (/Library/Developer/CommandLineTools/SDKs/MacOSX11.1.sdk/System/Library/Frameworks/Accelerate.framework -lm -ldl)  
> Eigen: NO  
> Custom HAL: NO  
> Protobuf: build (3.5.1)
> 
> OpenCL: YES (no extra features)  
> Include path: NO  
> Link libraries: -framework OpenCL
> 
> Python 2:  
> Interpreter: /usr/bin/python2.7 (ver 2.7.16)  
> Libraries: /usr/lib/libpython2.7.dylib (ver 2.7.16)  
> numpy: /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy/core/include (ver 1.8.0rc1)  
> install path: lib/python2.7/site-packages
> 
> Python 3:  
> Interpreter: /usr/local/bin/python3 (ver 3.9.4)  
> Libraries: /usr/local/Frameworks/Python.framework/Versions/3.9/lib/libpython3.9.dylib (ver 3.9.4)  
> numpy: /usr/local/lib/python3.9/site-packages/numpy/core/include (ver 1.20.2)  
> install path: ~/.virtualenvs/OpenCV-3.4.14-py3/lib/python3.9/site-packages
> 
> Python (for build): /usr/bin/python2.7
> 
> Java:  
> ant: NO  
> JNI: NO  
> Java wrappers: NO  
> Java tests: NO
> 
> Install to: /Users/myname/installation/OpenCV-3.4.14

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [August 1, 2021, 6:38am UTC](https://forum.opencv.org/t/how-do-you-identify-the-codec-of-a-mp4-video-file-in-xcode/4453/12 "2021-08-01T06:38:17Z")

</div>

so, AVFoundation is the only usable video backend on your box, [and it’s quite limited](https://github.com/opencv/opencv/blob/master/modules/videoio/src/cap_avfoundation.mm#L520-L529)

tl;dr:

sorry, but you cannot query the video codec like that.

---

<div class="post-metadata">

**Author:** ![sjsu\_alumna](https://avatars.discourse-cdn.com/v4/letter/s/6de8d8/32.png) [@sjsu\_alumna](https://forum.opencv.org/u/sjsu_alumna)\
**Post date:** [August 1, 2021, 9:36pm UTC](https://forum.opencv.org/t/how-do-you-identify-the-codec-of-a-mp4-video-file-in-xcode/4453/13 "2021-08-01T21:36:38Z")

</div>

So in order to be able to use cv::CAP\_PROP\_FOURCC, I would need FFMPEG built, correct? And the way to do that is by adding the line  
`-D WITH_FFMPEG=ON \`  
when using CMake to build OpenCV, as shown in step 2 of [Install OpenCV 3.4.4 on macOS | LearnOpenCV](https://learnopencv.com/install-opencv-3-4-4-on-macos/), correct?

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [August 1, 2021, 10:47pm UTC](https://forum.opencv.org/t/how-do-you-identify-the-codec-of-a-mp4-video-file-in-xcode/4453/14 "2021-08-01T22:47:26Z")

</div>

just use ffmpeg directly. look at documentation for ffprobe. it can show you all information on the container and on every contained audio/video/… stream.

if _all_ you need is to find out the codecs in a video file, OpenCV is the _wrong library_ for that.

“the fourcc” doesn’t exist for a video. it exists per stream, because a fourcc represents a choice of codec/bitstream. most videos have a video stream and an audio stream, which means you have two different types of bytestream.
