OpenCV videowriter H264 codec (ffmpeg) - windows

I want to save a video with opencv with lossless compresion so I don't lose any details of the frames. Everything works with the xvid codec but offcourse this is not a lossless compression so I found that the x264 codec is suitable. However it doesn't work, I tried the following sample code but while running I get the following error: "could not find encoder for codec id 28: encoder not found."
cv::VideoWriter makeVideo;
makeVideo.open("makevideo//newVideo.mp4", CV_FOURCC('X','2','6','4'), 30, cv::Size(1600,1200), true);
cv::Mat image = imread("makevideo//frames//111.png");
for(int i = 0; i < 200; i++)
makeVideo << image;
makeVideo.release();
I found that for this to work, I need to have ffmpeg support. I'm currently using opencv2.4.6 and in this discussion (how can I use the openCV FFMPEG video I/O rather than the DirectShow one in Windows?) someone mentioned that in opencv2.4 ffmpeg is automatically included. But its not working....
Here (How to compile OpenCV 2.3 with ffmpeg support with Visual Studio 2010) I found how to compile opencv and ffmpeg yourself on windows. I followed all the steps sucessfully but still I get the same error....

I had the same problem and could not find a solution. So now I always use -1 as FOURCC and choose the x264 codec by hand.

I managed to work it out on ubuntu, write down for your reference.
In order to have x264 codec work, you need to: Build FFmpeg with x264 enabled!
Before debug about OpenCV, please make sure you could generate x264 with ffmpeg, by itself.
Try the below command to verify H264 codec:
ffmpeg -i x264-input.mp4 -vcodec libx264 -f mp4 x264-output.mp4
Follow the FFmpeg officially doc to install from source.

Related

Automatic encoder selection failed for output stream #0:0 [duplicate]

I have installed ffmpeg using yum install in my centos.Now i want to recompile it with 'libmp3lame'.Is possible a recompilation of the installed ffmpeg or i want to remove ffmpeg and reinstall.
suggestion is highly appreciable.
Unlike AAC and some other audio formats, FFmpeg does not have a native MP3 encoder, so you have to use a supported external encoding library such as libmp3lame. You have several options if your ffmpeg is not configured with --enable-libmp3lame:
Download an already compiled binary
Download ffmpeg for Linux. This is an already compiled binary. This is the easiest solution.
See the FFmpeg Download page for links to Windows and OS X builds.
Compile ffmpeg
Follow a non-invasive step-by-step guide to Compile FFmpeg on CentOS. If you can copy and paste you can compile.
Pipe to lame
ffmpeg -i input -f wav - | lame - output.mp3
I do not consider this to be a practical solution but it may be useful to some.
Use a different format
If you don't require MP3 you can use AAC or some other audio format that has native encoding support.

I want to use libx264 codec with ffmpeg. but Ffmpeg libx264's configuration failed

configure failed
I want to use libx264 codec with ffmpeg.
when i tried to convert image files to a video using the codec, a message appears said Unknown encoder "libx264". so I tried to execute configure and make again at msys folder. I typed ./configure --enable-libx264 and it failed. :(
my ffmpeg version is 3.0.1 and x264 is also the latest version so far.
It is possible that you don't have the x264 libraries for compiling on your machine.
The last time I compiled FFMpeg I downloaded and compiled x264 also along with it to ensure I had the libraries installed.
http://www.videolan.org/developers/x264.html
It may also interest you to enable OpenH264 by Cisco.
http://www.openh264.org/

How to add libmp3lame, libx264, libvo_aacenc and libvorbis codecs to existing ffmpeg install on Redhat 6.7

Adobe cq uses ffmpeg to transcode videos. There is a workflow that is triggered when a user uploads any video to the digital asset management (DAM) section. This workflow internally uses ffmpeg to transcode the uploaded video and spits out additional video renditions in formats like ogg, m4v, mp3.
The server (Red Hat Enterprise Linux Server release 6.5) on which adobe cq runs needs to have ffmpeg installed for the DAM workflow to function. ffmpeg has already installed been installed, but it is missing certain codecs: libmp3lame, libx264, libvo_aacenc and libvorbis.
How to add and enable these codecs ?
You can't just add support for arbitrary external libraries to an existing ffmpeg binary.
You'll either need to download a new ffmpeg binary, or compile ffmpeg. Downloading a build is easiest and supports the encoders you listed (except libvo_aacenc). Compiling allows for customization.
Avoid libvo_aacenc: it provides poor quality and support for libvo_aacenc has been removed from FFmpeg. Use the native FFmpeg AAC encoder instead. See FFmpeg Wiki: AAC for more info.

recompile ffmpeg with libmp3lame

I have installed ffmpeg using yum install in my centos.Now i want to recompile it with 'libmp3lame'.Is possible a recompilation of the installed ffmpeg or i want to remove ffmpeg and reinstall.
suggestion is highly appreciable.
Unlike AAC and some other audio formats, FFmpeg does not have a native MP3 encoder, so you have to use a supported external encoding library such as libmp3lame. You have several options if your ffmpeg is not configured with --enable-libmp3lame:
Download an already compiled binary
Download ffmpeg for Linux. This is an already compiled binary. This is the easiest solution.
See the FFmpeg Download page for links to Windows and OS X builds.
Compile ffmpeg
Follow a non-invasive step-by-step guide to Compile FFmpeg on CentOS. If you can copy and paste you can compile.
Pipe to lame
ffmpeg -i input -f wav - | lame - output.mp3
I do not consider this to be a practical solution but it may be useful to some.
Use a different format
If you don't require MP3 you can use AAC or some other audio format that has native encoding support.

ffmpeg imlib2.so watermarking troubles

I am trying to watermark a flash video, but it throws long list of
"Unsupported Codec".
So, is flv not supported at all ? Do I need to convert it to .avi and watermark ?
install all the externall libraries which ffmpeg support and configure it with ffmpeg when compiling from source.

Resources