无法写入.mp4文件 - 无法打开编解码器' libx264':未指定的错误

时间:2015-02-09 12:35:15

标签: opencv video mp4 ubuntu-14.04 libx264

几天前我用ffmpeg安装了最新的2.4分支。我正在使用Ubuntu 14.04而我的虚拟机中根本没有ffmpeg。

我想写.mp4视频文件,输入文件也是.mp4。输入编解码器是avc1。

我无法获得任何结果,错误可以在下面看到。

错误

[libx264 @ 0x9357bc0] broken ffmpeg default settings detected
[libx264 @ 0x9357bc0] use an encoding preset (e.g. -vpre medium)
[libx264 @ 0x9357bc0] preset usage: -vpre <speed> -vpre <profile>
[libx264 @ 0x9357bc0] speed presets are listed in x264 --help
[libx264 @ 0x9357bc0] profile is optional; x264 defaults to high
Could not open codec 'libx264': Unspecified error
Could not open the output video for write: /home/margarida/exams_2014/Output.mp4

简化代码

int main(int argc, char *argv[]) {
            VideoWriter outputVideo;

            // Get Codec Type
            int ex = static_cast<int>(cap.get(CV_CAP_PROP_FOURCC));

            // Transform from int to char via Bitwise operators
            char EXT[] = { (char) (ex & 0XFF), (char) ((ex & 0XFF00) >> 8),
                            (char) ((ex & 0XFF0000) >> 16), (char) ((ex & 0XFF000000)
                                    >> 24), 0 };

            // Acquire input size
            Size S = Size((int) cap.get(CV_CAP_PROP_FRAME_WIDTH),
                            (int) cap.get(CV_CAP_PROP_FRAME_HEIGHT));

            cout << "Input codec type: " << EXT << endl;

            // Open the output
            outputVideo.open(newname, ex, cap.get(CV_CAP_PROP_FPS), S, true);

            if (!outputVideo.isOpened()) {
                cout << "Could not open the output video for write " << endl;
                        return -1;
                    }

                    while (true) {
                        cap >> frame;
                        if (frame.empty()) {
                            cerr << "nao apanhou frame" << endl;
                            break;
                        }

                        cinzento = acinzentar(frame);
                        imshow("Cinzento", cinzento);

                        outputVideo.write(cinzento);

                        switch(waitKey(10)){

                        case 27:
                            //'esc' has been pressed (ASCII value for 'esc' is 27)
                            //exit program.
                            return 0;

                        }
                    }
                   return 0;
                }

我的cmake是这样的:

cmake -D WITH_TBB=ON -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON -D WITH_QT=ON -D WITH_OPENGL=ON -D WITH_VTK=ON -D WITH_FFMPEG=OFF -D WITH_IPP=OFF ..

任何人都可以帮忙解决我的问题吗?

提前致谢。

1 个答案:

答案 0 :(得分:-1)

使用ffmpeg将您的输入文件正确转换为mp4并重试您的程序。 我用来转换文件的命令行是:

ffmpeg -i test.mp4 -acodec libfdk_aac -b:a 128k -vcodec mpeg4 -b:v 1200k -flags +aic+mv4 output.mp4

仅供参考:如果您没有这样做,可以找到in this link安装ffmpeg的说明。