I think your finding here is key:
FFMPEG backend with MP4 container natively uses other values as fourcc code: see ObjectType, so you may receive a warning message from OpenCV about fourcc code conversion.
The mp4 tag values implemented for ffmpeg
confirm this, and are in the ff_mp4_obj_type[]
, in isom.c
. The code in OpenCV's cap_ffmpeg_impl.hpp
likely needs to be updated to support this. I poked around for an hour or two, realized it was non-trivial, and bailed.
One work-around is to output to an .avi
file. There are numerous examples of people having trouble with OpenCV and mp4, and being told to use .mov
or .avi
. (Here's one.)
@Greg Kramida: setting isColor = false
did not help for me: the message remained, and my output file became only ~48 bytes. According to the documentation it is a Windows flag -- whatever it is doing for me on Linux, it isn't good.
Did you confirm that you could generate x264 with ffmpeg, by itself?
After confirming that libx264 has value 0x21 when I invoke this on the command line:
ffmpeg -i x264-input.mp4 -vcodec libx264 -f mp4 x264-output.mp4
I decided to use 0x21
directly into VideoWriter.open()
. That generates a valid and interpretable video file.
For reference, my software is ffmpeg 3.0:
ffmpeg -version
ffmpeg version 3.0 Copyright (c) 2000-2016 the FFmpeg developers
built with gcc 4.9.2 (Debian 4.9.2-10)
configuration: --enable-libx264 --enable-gpl --prefix=/usr/local --enable-shared --cc=`gcc -fPIC` --enable-libfdk-aac --enable-libx265 --enable-nonfree --enable-libmp3lame
libavutil 55. 17.103 / 55. 17.103
libavcodec 57. 24.102 / 57. 24.102
libavformat 57. 25.100 / 57. 25.100
libavdevice 57. 0.101 / 57. 0.101
libavfilter 6. 31.100 / 6. 31.100
libswscale 4. 0.100 / 4. 0.100
libswresample 2. 0.101 / 2. 0.101
libpostproc 54. 0.100 / 54. 0.100
And OpenCV 3.1.0 configured with:
cmake
-D WITH_IPP=ON
-D INSTALL_CREATE_DISTRIB=ON
-D CMAKE_BUILD_TYPE=Release
-D CMAKE_INSTALL_PREFIX=/usr/local ..
x264 is the libx264-142:amd64
release for Debian Jessie.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…