首先轉換為webm,導致分段故障的幀移到1308幀,而不是1301。
我的代碼:
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <opencv2/opencv.hpp>/span>
#include <opencv2/core.hpp>/span>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui.hpp>/span>
using namespace std;
using namespace cv;
void conv_vid_png( string input_path, string output_path){
VideoCapture cap(input_path)。
int count = 0;
if(!cap.isOpened()){
cout << "打開視頻流或檔案錯誤" << endl;
}
while(1) {
Mat frame;
//Why the fuck does this use the stream insertion operator?
// >> 似乎既要增量又要存盤。
cap >> 幀。
//Break the loop when there are no more frames to capture
if (frame.empty()
break;
imwrite(output_path "frame" to_string(count) " .png", frame)。
cout << "frame" to_string(count) " processed" << endl;
count ;
}
}
int main()
{
string in_path = "./movie_type_files/vert_beach_short.mp4"/span>。
string out_path = "./tmp_png/";
conv_vid_png(in_path, out_path); //First, convert the video file to png sequence[/span
return 0;
}
它使用OpenCV VideoCapture物件將視頻的每一幀寫入PNG中。在OpenCV for python中,我沒有遇到這個同樣的函式問題。盡管該幀表面上沒有任何例外,但分割故障還是發生在同一幀(1301)。
對解決方案有什么想法? 我目前正在使用 ffmpeg 將 .mp4 轉換為 webm,以觀察該問題是否持續存在。這是我的第一個C 程式,所以我正在努力自我診斷我的問題。我遵循一個關于診斷分段故障的指南,并將我收集的結果寫在下面。
uj5u.com熱心網友回復:
分段故障實際上發生在下面的一個函式中。 我以為我在這次渲染中正好有1340幀,但事實證明,有些幀在我做的一些處理中丟失了,所以原問題中的代碼是100%正確的。 分段故障是由讀取檔案失敗引起的,(我忘了在幀的索引前加零)。 由于該框架是空的,當我使用指標訪問不存在的資料時,我得到了一個分段故障。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/328644.html
標籤:
上一篇:img資料型別=17不被支持


