【问题标题】:Can't write .mp4 files - Could not open codec 'libx264': Unspecified error无法写入 .mp4 文件 - 无法打开编解码器“libx264”:未指定的错误
【发布时间】:2015-04-09 04:53:49
【问题描述】:

几天前,我在没有 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 ..

谁能帮助解决我的问题?

提前致谢。

【问题讨论】:

    标签: opencv video mp4 ubuntu-14.04 libx264


    【解决方案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 的说明,如果您还没有这样做的话,有几个选项。

    【讨论】:

    • 请注意,问题是关于写入文件,而不是读取。
    猜你喜欢
    • 2017-06-17
    • 2014-06-10
    • 1970-01-01
    • 2010-11-23
    • 2023-02-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多