简体   繁体   English

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

[英]Can't write .mp4 files - Could not open codec 'libx264': Unspecified error

Days ago I installed the latest 2.4 branch withou ffmpeg. 几天前,我用ffmpeg安装了最新的2.4分支。 I'm using Ubuntu 14.04 and I don't have at all ffmpeg in my Virtual Machine. 我正在使用Ubuntu 14.04,但我的虚拟机中根本没有ffmpeg。

I want to write .mp4 video files and the input files are also .mp4. 我想写.mp4视频文件,输入文件也是.mp4。 The input codec is avc1. 输入编解码器为avc1。

I can't obtain any results, the errors can be seen below. 我无法获得任何结果,错误可以在下面看到。

Error 错误

[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

Simplified Code 简码

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;
                }

My cmake was this: 我的命令是这样的:

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 ..

Can anyone help solving my problem? 谁能帮助解决我的问题?

Thanks in advance. 提前致谢。

Use ffmpeg to convert your input file into mp4 properly and retry your program. 使用ffmpeg将输入文件正确转换为mp4,然后重试程序。 The commandline I used to converted my file is: 我用来转换文件的命令行是:

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

FYI: You can find in this link the instructions to install ffmpeg with several options if you have not do so. 仅供参考:您可以在此链接中找到有关安装ffmpeg的说明(如果尚未安装的话)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM