日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

解决Python OpenCV 读取视频并抽帧出现error while decoding的问题

發(fā)布時(shí)間:2023/11/27 生活经验 72 豆豆
生活随笔 收集整理的這篇文章主要介紹了 解决Python OpenCV 读取视频并抽帧出现error while decoding的问题 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

解決Python OpenCV 讀取視頻抽幀出現(xiàn)error while decoding的問題

    • 1. 問題
    • 2. 解決
    • 3. 源代碼
    • 參考

1. 問題

讀取H264視頻,抽幀視頻并保存,報(bào)錯(cuò)如下;

[aac @ 00000220b9a07fc0] Input buffer exhausted before END element found
[h264 @ 00000220b9cd0500] error while decoding MB 20 45, bytestream -14

2. 解決

溯本求源:https://stackoverflow.com/questions/49233433/opencv-read-errorh264-0x8f915e0-error-while-decoding-mb-53-20-bytestream

發(fā)現(xiàn)問題原因是:它與時(shí)間有關(guān),當(dāng)在連續(xù)的capture.read()之間執(zhí)行比較耗時(shí)的操作時(shí)會(huì)出現(xiàn)該錯(cuò)誤。

解決:增加一個(gè)線程處理捕獲到的視頻幀就好~~~

3. 源代碼

import os
import queue
import threadingimport cv2q = queue.Queue()
save_path = ''def get_frame_from_video(video_name, interval):"""Args:video_name:輸入視頻名字interval: 保存圖片的幀率間隔Returns:"""# 開始讀視頻video_capture = cv2.VideoCapture(video_name)i = 0while True:success, frame = video_capture.read()# 檢測(cè)是否到了視頻尾部if not success or frame is None:print('video is all read')breaki += 1if i % interval == 0:q.put(frame)def Display(arr):print("Start Displaying")j = int(arr)while True:if q.empty() != True:frame = q.get()# 保存圖片j += 1save_name = save_path + str(j) + '.jpg'cv2.imwrite(save_name, frame)print('image of %s is saved' % save_name)# cv2.imshow(save_name, frame)if cv2.waitKey(1) & 0xFF == ord('q'):breakif __name__ == '__main__':video_name = 'F:\\v01.H264'j = 0save_path = video_name.split('.H264')[0] + "\\"print(save_path)interval = 125# 保存圖片的路徑is_exists = os.path.exists(save_path)if not is_exists:os.makedirs(save_path)print('path of %s is build' % save_path)p2 = threading.Thread(target=Display,args=[j])p2.start()get_frame_from_video(video_name, interval)

參考

  • https://stackoverflow.com/questions/49233433/opencv-read-errorh264-0x8f915e0-error-while-decoding-mb-53-20-bytestream
  • https://blog.csdn.net/darkeyers/article/details/84865363

總結(jié)

以上是生活随笔為你收集整理的解决Python OpenCV 读取视频并抽帧出现error while decoding的问题的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。