Last active
November 29, 2017 04:35
-
-
Save axtstar/7d55dc5fb47c14770622c40e020b3ed1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
import cv2 | |
import argparse | |
#引数 | |
parser = argparse.ArgumentParser(description='in:input file, out: Output file.') | |
parser.add_argument('-i','--input', | |
action='store', | |
nargs='?', | |
type=str, | |
help='an input movie file') | |
parser.add_argument('-o','--output', | |
action='store', | |
nargs='?', | |
type=str, | |
help='an output movie file') | |
parser.add_argument('-c','--iscolor', | |
action='store_true') | |
args = parser.parse_args() | |
InfilePath = args.input | |
OutfilePath = args.output | |
iscolor = args.iscolor | |
print(f'iscolor {iscolor}') | |
# 元ビデオファイル読み込み | |
org = cv2.VideoCapture(InfilePath) | |
# FPS取得 | |
fps = org.get(cv2.CAP_PROP_FPS) # fps | |
print(f'fps : {fps}') | |
#1フレーム目読み込み | |
end_flag, frame = org.read() | |
#(書き込み用に)幅、高さ取得 | |
height, width, channels = frame.shape | |
print(f'width x height x channels: {width} x {height} x {channels}') | |
# 保存ビデオファイルの準備 | |
fourcc = cv2.VideoWriter_fourcc(*"X264") | |
rec = cv2.VideoWriter(OutfilePath, | |
fourcc, | |
fps, | |
(width, height), | |
iscolor | |
) | |
# 変換処理ループ | |
while end_flag == True: | |
#実際の書き込みはオリジナルのフレーム | |
#↓変換処理をここに↓ | |
conv_frame = frame | |
#↑変換処理をここに↑ | |
rec.write(conv_frame) | |
# フレーム表示 | |
cv2.imshow("conv", conv_frame) | |
# 次のフレーム読み込み | |
end_flag, frame = org.read() | |
# imshowを表示する場合はwaitが必要みたい。。。 | |
#VBの | |
# ファイルを出力するだけならコメントアウトしても問題なし | |
key = cv2.waitKey(33) & 0xff | |
# 終了処理 | |
cv2.destroyAllWindows() | |
org.release() | |
rec.release() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment