Metadict in ffmpeg does not have rotate information - opencv

My aim is to extract frames out of a video but many times the frames are inverted. This is happening because "VideoCapture" in cv2 does read the rotate flag data present in the video metadata. I am running it on mac and installed "ffmpeg" package (5.0.1) using brew package manager. This is my code to check rotation present in a video using ffmpeg.
import ffmpeg
import cv2
import pprint
pp = pprint.PrettyPrinter(depth=4)
def check_rotation(path_video_file):
# this returns meta-data of the video file in form of a dictionary
meta_dict = ffmpeg.probe(path_video_file)
pp.pprint(meta_dict)
# from the dictionary, meta_dict['streams'][0]['tags']['rotate'] is the key
# we are looking for
rotateCode = None
if int(meta_dict['streams'][0]['tags']['rotate']) == 90:
rotateCode = cv2.ROTATE_90_CLOCKWISE
elif int(meta_dict['streams'][0]['tags']['rotate']) == 180:
rotateCode = cv2.ROTATE_180
elif int(meta_dict['streams'][0]['tags']['rotate']) == 270:
rotateCode = cv2.ROTATE_90_COUNTERCLOCKWISE
return rotateCode
Here the meta_dict is supposed to have information about the rotation but it is not there.
printing out meta_dict gives:
{'format': {'bit_rate': '18498544',
'duration': '3.584000',
'filename': 'video.mp4',
'format_long_name': 'QuickTime / MOV',
'format_name': 'mov,mp4,m4a,3gp,3g2,mj2',
'nb_programs': 0,
'nb_streams': 2,
'probe_score': 100,
'size': '8287348',
'start_time': '0.000000',
'tags': {'com.android.version': '11',
'compatible_brands': 'isommp42',
'creation_time': '2021-12-08T10:56:57.000000Z',
'major_brand': 'mp42',
'minor_version': '0'}},
'streams': [{'avg_frame_rate': '990000/34997',
'bit_rate': '18804651',
'bits_per_raw_sample': '8',
'chroma_location': 'left',
'closed_captions': 0,
'codec_long_name': 'H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10',
'codec_name': 'h264',
'codec_tag': '0x31637661',
'codec_tag_string': 'avc1',
'codec_type': 'video',
'coded_height': 1080,
'coded_width': 1920,
'color_primaries': 'bt470bg',
'color_range': 'pc',
'color_space': 'bt470bg',
'color_transfer': 'smpte170m',
'display_aspect_ratio': '16:9',
'disposition': {'attached_pic': 0,
'captions': 0,
'clean_effects': 0,
'comment': 0,
'default': 1,
'dependent': 0,
'descriptions': 0,
'dub': 0,
'forced': 0,
'hearing_impaired': 0,
'karaoke': 0,
'lyrics': 0,
'metadata': 0,
'original': 0,
'still_image': 0,
'timed_thumbnails': 0,
'visual_impaired': 0},
'duration': '3.499700',
'duration_ts': 314973,
'extradata_size': 35,
'field_order': 'progressive',
'film_grain': 0,
'has_b_frames': 0,
'height': 1080,
'id': '0x1',
'index': 0,
'is_avc': 'true',
'level': 40,
'nal_length_size': '4',
'nb_frames': '99',
'pix_fmt': 'yuvj420p',
'profile': 'High',
'r_frame_rate': '120/1',
'refs': 1,
'sample_aspect_ratio': '1:1',
'side_data_list': [{...}],
'start_pts': 3168,
'start_time': '0.035200',
'tags': {'creation_time': '2021-12-08T10:56:57.000000Z',
'handler_name': 'VideoHandle',
'language': 'eng',
'vendor_id': '[0][0][0][0]'},
'time_base': '1/90000',
'width': 1920},
{'avg_frame_rate': '0/0',
'bit_rate': '128986',
'bits_per_sample': 0,
'channel_layout': 'stereo',
'channels': 2,
'codec_long_name': 'AAC (Advanced Audio Coding)',
'codec_name': 'aac',
'codec_tag': '0x6134706d',
'codec_tag_string': 'mp4a',
'codec_type': 'audio',
'disposition': {'attached_pic': 0,
'captions': 0,
'clean_effects': 0,
'comment': 0,
'default': 1,
'dependent': 0,
'descriptions': 0,
'dub': 0,
'forced': 0,
'hearing_impaired': 0,
'karaoke': 0,
'lyrics': 0,
'metadata': 0,
'original': 0,
'still_image': 0,
'timed_thumbnails': 0,
'visual_impaired': 0},
'duration': '3.584000',
'duration_ts': 172032,
'extradata_size': 2,
'id': '0x2',
'index': 1,
'nb_frames': '168',
'profile': 'LC',
'r_frame_rate': '0/0',
'sample_fmt': 'fltp',
'sample_rate': '48000',
'start_pts': 0,
'start_time': '0.000000',
'tags': {'creation_time': '2021-12-08T10:56:57.000000Z',
'handler_name': 'SoundHandle',
'language': 'eng',
'vendor_id': '[0][0][0][0]'},
'time_base': '1/48000'}]}
Can someone please help me to find if rotation is present in a video?

Related

Logitech Lua help needed

software = Logitech G hub
UPDATE
Okay! Thanks to some help this is where I'm at, Everything's working very nicely and as it should but now I face a new task and that is adding variations of each table for the slight changes to recoil when using scopes.
I could simple add more gun modes and make the changes required but I'd really like to make a way of using a key to toggle whether they are used or not, An idea I have floating around my head is for F9 and F10 to toggle between the scopes and when the toggle is off it will work with the code I already have. however I'm not sure this is possible, to my understanding I could use the lock keys (capslock, scrolllock, numlock) to make this work. initially I had the idea to have a toggle key that modifies the timing of the recoil sequence but unfortunately this is not an accurate solution.
What I'd like to do now is create 2/3 toggles that allow gun modes to switch between variable tables without having to add more guns
any help is greatly appreciated and that goes for any help I've received so far too
thanks
---GUN MODES---
local GUN1_Mouse = 8
local GUN1_Keyboard = nil
local GUN2_Mouse = 7
local GUN2_Keyboard = nil
local GUN3_Mouse = 9
local GUN3_Keyboard = nil
local GUN4_Mouse = nil
local GUN4_Keyboard = nil
local GUN5_Mouse = 5
local GUN5_Keyboard = nil
local GUN6_Mouse = nil
local CUSTOM_Keyboard = nil
local GUN7_Mouse = 4
local GUN7_Keyboard = nil
---RECOIL TABLES---
local recoil_table = {}
-------------------------------------
recoil_table["GUN1"] = {
0, 6, 133,
-1, 6, 133,
-1, 6, 133,
-4, 6, 133,
-3, 6, 133,
-3, 6, 133,
-3, 6, 133,
-4, 6, 133,
-4, 6, 133,
-4, 6, 133,
-4, 6, 133,
-4, 6, 133,
-4, 6, 133,
-4, 6, 133,
-4, 6, 133,
-4, 6, 133,
-4, 6, 133,
-4, 6, 133,
-4, 6, 133,
-4, 6, 133,
-4, 6, 133,
-4, 6, 133,
-4, 6, 133,
-4, 6, 133,
-4, 6, 133,
-4, 6, 133,
-4, 6, 133,
-4, 6, 133,
-4, 6, 133,
-4, 6, 133,
}
recoil_table["GUN1_crouch"] = {
0, 3, 133,
-1, 3, 133,
-1, 3, 133,
-1, 3, 133,
-1, 3, 133,
-2, 3, 133,
-2, 3, 133,
-2, 3, 133,
-2, 3, 133,
-2, 3, 133,
-3, 3, 133,
-3, 3, 133,
-2, 3, 133,
-2, 3, 133,
-2, 3, 133,
-2, 3, 133,
-2, 3, 133,
-2, 3, 133,
-2, 3, 133,
-2, 3, 133,
-2, 3, 133,
-2, 3, 133,
-2, 3, 133,
-2, 3, 133,
-2, 3, 133,
-2, 3, 133,
-2, 3, 133,
-2, 3, 133,
-2, 3, 133,
-2, 3, 133,
}
-------------------------------------
recoil_table["GUN2"] = {
0, 5.5, 120,
0, 5.5, 120,
0, 5.5, 120,
0, 5.5, 120,
0, 5.5, 120,
0, 5.5, 120,
0, 5.5, 120,
0, 5.5, 120,
0, 5.5, 120,
0, 5.5, 120,
0, 5.5, 120,
0, 5.5, 120,
0, 5.5, 120,
0, 5.5, 120,
0, 5.5, 120,
0, 5.5, 120,
0, 5.5, 120,
0, 5.5, 120,
0, 5.5, 120,
0, 5.5, 120,
0, 5.5, 120,
0, 5.5, 120,
0, 5.5, 120,
0, 5.5, 120,
0, 5.5, 120,
0, 5.5, 120,
0, 5.5, 120,
0, 5.5, 120,
0, 5.5, 120,
0, 5.5, 120,
}
recoil_table["GUN2_crouch"] = {
0, 2.8, 120,
-0, 2.8, 120,
-0, 2.8, 120,
-0, 2.8, 120,
-0, 2.8, 120,
-0, 2.8, 120,
-0, 2.8, 120,
-0, 2.8, 120,
-0, 2.8, 120,
-0, 2.8, 120,
-0, 2.8, 120,
-0, 2.8, 120,
-0, 2.8, 120,
-0, 2.8, 120,
-0, 2.8, 120,
-0, 2.8, 120,
-0, 2.8, 120,
-0, 2.8, 120,
-0, 2.8, 120,
-0, 2.8, 120,
-0, 2.8, 120,
-0, 2.8, 120,
-0, 2.8, 120,
-0, 2.8, 120,
-0, 2.8, 120,
-0, 2.8, 120,
-0, 2.8, 120,
-0, 2.8, 120,
-0, 2.8, 120,
-0, 2.8, 120,
}
-------------------------------------
recoil_table["GUN3"] = {
0, 3, 133,
-1, 3, 133,
-1, 3, 133,
-1, 3, 133,
-1, 3, 133,
-2, 3, 133,
-2, 3, 133,
-2, 3, 133,
-2, 3, 133,
-2, 3, 133,
-3, 3, 133,
-3, 3, 133,
-2, 3, 133,
-2, 3, 133,
-2, 3, 133,
-2, 3, 133,
-2, 3, 133,
-2, 3, 133,
-2, 3, 133,
-2, 3, 133,
-2, 3, 133,
-2, 3, 133,
-2, 3, 133,
-2, 3, 133,
-2, 3, 133,
-2, 3, 133,
-2, 3, 133,
-2, 3, 133,
-2, 3, 133,
-2, 3, 133,
}
recoil_table["GUN3_crouch"] = {
0, 2.5, 125,
0, 2.5, 125,
1, 2.5, 125,
1, 2.5, 125,
0.7, 2.5, 125,
0.7, 2.5, 125,
0.7, 2.5, 125,
0.8, 2.5, 125,
0.9, 2.5, 125,
1, 2.5, 125,
0.7, 2.5, 125,
0.7, 2.5, 125,
0.7, 2.5, 125,
0.8, 2.5, 125,
0.9, 2.5, 125,
1, 2.5, 125,
1, 2.5, 125,
1, 2.5, 125,
1, 2.5, 125,
1, 2.5, 125,
1, 2.5, 125,
1, 2.5, 125,
1, 2.5, 125,
1, 2.5, 125,
1, 2.5, 125,
1, 2.5, 125,
1, 2.5, 125,
1, 2.5, 125,
1, 2.5, 125,
1, 2.5, 125,
}
-------------------------------------
recoil_table["GUN4"] = {
0, 3.4, 100,
0, 3.4, 100,
0, 3.4, 100,
0, 3.4, 100,
0, 3.4, 100,
0, 3.4, 100,
0, 3.4, 100,
0, 3.4, 100,
0, 3.4, 100,
0, 3.4, 100,
0, 3.4, 100,
0, 3.4, 100,
0, 3.4, 100,
0, 3.4, 100,
0, 3.4, 100,
0, 3.4, 100,
0, 3.4, 100,
0, 3.4, 100,
0, 3.4, 100,
0, 3.4, 100,
0, 3.4, 100,
0, 3.4, 100,
0, 3.4, 100,
0, 3.4, 100,
0, 3.4, 100,
0, 3.4, 100,
0, 3.4, 100,
0, 3.4, 100,
0, 3.4, 100,
0, 3.4, 100,
}
recoil_table["GUN4_crouch"] = {
0, 1.7, 100,
0, 1.7, 100,
0, 1.7, 100,
0, 1.7, 100,
0, 1.7, 100,
0, 1.7, 100,
0, 1.7, 100,
0, 1.7, 100,
0, 1.7, 100,
0, 1.7, 100,
0, 1.7, 100,
0, 1.7, 100,
0, 1.7, 100,
0, 1.7, 100,
0, 1.7, 100,
0, 1.7, 100,
0, 1.7, 100,
0, 1.7, 100,
0, 1.7, 100,
0, 1.7, 100,
0, 1.7, 100,
0, 1.7, 100,
0, 1.7, 100,
0, 1.7, 100,
0, 1.7, 100,
0, 1.7, 100,
0, 1.7, 100,
0, 1.7, 100,
0, 1.7, 100,
0, 1.7, 100,
}
-------------------------------------
recoil_table["GUN5"] = {
0, 2.4, 129,
0, 2.4, 129,
0, 2.4, 129,
0, 2.4, 129,
0, 2.4, 129,
0, 2.4, 129,
0, 2.4, 129,
0, 2.4, 129,
0, 2.4, 129,
0, 2.4, 129,
0, 2.4, 129,
0, 2.4, 129,
0, 2.4, 129,
0, 2.4, 129,
0, 2.4, 129,
0, 2.4, 129,
0, 2.4, 129,
0, 2.4, 129,
0, 2.4, 129,
0, 2.4, 129,
0, 2.4, 129,
0, 2.4, 129,
0, 2.4, 129,
0, 2.4, 129,
0, 2.4, 129,
0, 2.4, 129,
0, 2.4, 129,
0, 2.4, 129,
0, 2.4, 129,
0, 2.4, 129,
}
recoil_table["GUN5_crouch"] = {
0, 1.2, 129,
0, 1.2, 129,
0, 1.2, 129,
0, 1.2, 129,
0, 1.2, 129,
0, 1.2, 129,
0, 1.2, 129,
0, 1.2, 129,
0, 1.2, 129,
0, 1.2, 129,
0, 1.2, 129,
0, 1.2, 129,
0, 1.2, 129,
0, 1.2, 129,
0, 1.2, 129,
0, 1.2, 129,
0, 1.2, 129,
0, 1.2, 129,
0, 1.2, 129,
0, 1.2, 129,
0, 1.2, 129,
0, 1.2, 129,
0, 1.2, 129,
0, 1.2, 129,
0, 1.2, 129,
}
-------------------------------------
recoil_table["GUN6"] = {
0, 3, 100,
0, 3, 100,
0, 3, 100,
0, 3, 100,
0, 3, 100,
0, 3, 100,
0, 3, 100,
0, 3, 100,
0, 3, 100,
0, 3, 100,
0, 3, 100,
0, 3, 100,
0, 3, 100,
0, 3, 100,
0, 3, 100,
0, 3, 100,
0, 3, 100,
0, 3, 100,
0, 3, 100,
0, 3, 100,
0, 3, 100,
0, 3, 100,
0, 3, 100,
0, 3, 100,
0, 3, 100,
0, 3, 100,
0, 3, 100,
0, 3, 100,
0, 3, 100,
0, 3, 100,
}
recoil_table["GUN6_crouch"] = {
0, 1.5, 100,
0, 1.5, 100,
0, 1.5, 100,
0, 1.5, 100,
0, 1.5, 100,
0, 1.5, 100,
0, 1.5, 100,
0, 1.5, 100,
0, 1.5, 100,
0, 1.5, 100,
0, 1.5, 100,
0, 1.5, 100,
0, 1.5, 100,
0, 1.5, 100,
0, 1.5, 100,
0, 1.5, 100,
0, 1.5, 100,
0, 1.5, 100,
0, 1.5, 100,
0, 1.5, 100,
0, 1.5, 100,
0, 1.5, 100,
0, 1.5, 100,
0, 1.5, 100,
0, 1.5, 100,
0, 1.5, 100,
0, 1.5, 100,
0, 1.5, 100,
0, 1.5, 100,
0, 1.5, 100,
}
-------------------------------------
recoil_table["GUN7"] = {
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
0, 4.4, 120,
}
-------------------------------------
recoil_table["GUN7_crouch"] = {
0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
-0, 2.2, 120,
}
---------------------------------------------------
local weapon
function OnEvent(event, arg)
if event == "PROFILE_ACTIVATED" then
EnablePrimaryMouseButtonEvents(true)
elseif (event == "MOUSE_BUTTON_PRESSED" and arg == GUN1_Mouse) or (event == "G_PRESSED" and arg == GUN1_Keyboard) then
weapon = weapon ~= "GUN1" and "GUN1"
if not weapon then
OutputLogMessage("OFF-GUN1\n")
if IsKeyLockOn("numlock") then
PressAndReleaseKey("numlock")
end
else
OutputLogMessage("ON-GUN1\n")
if not IsKeyLockOn("numlock") then
PressAndReleaseKey("numlock")
end
end
------------- for adding another weapon -----------
elseif (event == "MOUSE_BUTTON_PRESSED" and arg == GUN2_Mouse) or (event == "G_PRESSED" and arg == GUN2_Keyboard) then
weapon = weapon ~= "GUN2" and "GUN2"
if not weapon then
OutputLogMessage("OFF-GUN2\n")
if IsKeyLockOn("numlock") then
PressAndReleaseKey("numlock")
end
else
OutputLogMessage("ON-GUN2\n")
if not IsKeyLockOn("numlock") then
PressAndReleaseKey("numlock")
end
end
------------- for adding another weapon -----------
elseif (event == "MOUSE_BUTTON_PRESSED" and arg == GUN3_Mouse) or (event == "G_PRESSED" and arg == GUN3_Keyboard) then
weapon = weapon ~= "GUN3" and "GUN3"
if not weapon then
OutputLogMessage("OFF-GUN3\n")
if IsKeyLockOn("numlock") then
PressAndReleaseKey("numlock")
end
else
OutputLogMessage("ON-GUN3\n")
if not IsKeyLockOn("numlock") then
PressAndReleaseKey("numlock")
end
end
------------- for adding another weapon -----------
elseif (event == "MOUSE_BUTTON_PRESSED" and arg == GUN4_Mouse) or (event == "G_PRESSED" and arg == GUN4_Keyboard) then
weapon = weapon ~= "GUN4" and "GUN4"
if not weapon then
OutputLogMessage("OFF-GUN4\n")
if IsKeyLockOn("numlock") then
PressAndReleaseKey("numlock")
end
else
OutputLogMessage("ON-GUN4\n")
if not IsKeyLockOn("numlock") then
PressAndReleaseKey("numlock")
end
end
------------- for adding another weapon -----------
elseif (event == "MOUSE_BUTTON_PRESSED" and arg == GUN5_Mouse) or (event == "G_PRESSED" and arg == GUN5_Keyboard) then
weapon = weapon ~= "GUN5" and "GUN5"
if not weapon then
OutputLogMessage("OFF-GUN5\n")
if IsKeyLockOn("numlock") then
PressAndReleaseKey("numlock")
end
else
OutputLogMessage("ON-GUN5\n")
if not IsKeyLockOn("numlock") then
PressAndReleaseKey("numlock")
end
end
------------- for adding another weapon -----------
elseif (event == "MOUSE_BUTTON_PRESSED" and arg == GUN6_Mouse) or (event == "G_PRESSED" and arg == GUN6_Keyboard) then
weapon = weapon ~= "GUN6" and "GUN6"
if not weapon then
OutputLogMessage("OFF-GUN6\n")
if IsKeyLockOn("numlock") then
PressAndReleaseKey("numlock")
end
else
OutputLogMessage("ON-GUN6\n")
if not IsKeyLockOn("numlock") then
PressAndReleaseKey("numlock")
end
end
------------- for adding another weapon -----------
elseif (event == "MOUSE_BUTTON_PRESSED" and arg == GUN7_Mouse) or (event == "G_PRESSED" and arg == GUN7_Keyboard) then
weapon = weapon ~= "GUN7" and "GUN7"
if not weapon then
OutputLogMessage("OFF-GUN7\n")
if IsKeyLockOn("numlock") then
PressAndReleaseKey("numlock")
end
else
OutputLogMessage("ON-GUN7\n")
if not IsKeyLockOn("numlock") then
PressAndReleaseKey("numlock")
end
end
---------------------------------------------------
elseif event == "MOUSE_BUTTON_PRESSED" and arg == 1 and weapon and IsMouseButtonPressed(3) then
local recoil_sequence = recoil_table[weapon..(IsModifierPressed("lctrl") and "_crouch" or "")] or {}
local x, y, tm = 0, 0, GetRunningTime()
for j = 3, #recoil_sequence, 3 do
local dx_10ms = recoil_sequence[j-2]
local dy_10ms = recoil_sequence[j-1]
local duration = recoil_sequence[j]
repeat
Sleep(10)
if not IsMouseButtonPressed(1) then break end
local dt = math.min(GetRunningTime() - tm, duration)
duration, tm = duration - dt, tm + dt
x, y = x + dt/10 * dx_10ms, y + dt/10 * dy_10ms
local int_x, int_y = math.floor(x), math.floor(y)
x, y = x - int_x, y - int_y
MoveMouseRelative(int_x, int_y)
until duration == 0
if not IsMouseButtonPressed(1) then break end
end
end
end
You should use function GetRunningTime() to check if it is time to change recoil direction.
---GUN MODES---
local AK47_Mouse = 8
local AK47_Keyboard = nil
------------- for adding another weapon -----------
local AnotherWeapon_Mouse = 7
local AnotherWeapon_Keyboard = nil
---------------------------------------------------
local SpeedX2Modifier_Mouse = nil
local SpeedX2Modifier_Keyboard = 1 -- key G1
local SpeedX2 = false
---RECOIL TABLES---
local recoil_table = {}
recoil_table["AK47"] = {
-- down for 1 second
0, 0.5, 1000, -- delta_x_per_10ms, delta_y_per_10ms, duration_in_ms
-- diagonal for 1 second
-2, 4, 1000,
-- it stops moving after 2 seconds (even if LMB is still pressed)
}
recoil_table["AK47_crouch"] = {
-- down forever (until LMB is released)
0, 2, math.huge, -- math.huge means "very big number of ms"
}
recoil_table["AK47_reddot"] = {
-- down forever (until LMB is released)
0, 2, math.huge, -- math.huge means "very big number of ms"
}
------------- for adding another weapon -----------
recoil_table["AnotherWeapon"] = {
-- down for 1 second
0, 0.5, 1000, -- delta_x_per_10ms, delta_y_per_10ms, duration_in_ms
-- diagonal for 1 second
-2, 4, 1000,
-- it stops moving after 2 seconds (even if LMB is still pressed)
}
recoil_table["AnotherWeapon_crouch"] = {
-- down forever (until LMB is released)
0, 2, math.huge, -- math.huge means "very big number of ms"
}
recoil_table["AnotherWeapon_reddot"] = {
-- down forever (until LMB is released)
0, 2, math.huge, -- math.huge means "very big number of ms"
}
---------------------------------------------------
local weapon
function OnEvent(event, arg)
if event == "PROFILE_ACTIVATED" then
EnablePrimaryMouseButtonEvents(true)
elseif (event == "MOUSE_BUTTON_PRESSED" and arg == AK47_Mouse) or (event == "G_PRESSED" and arg == AK47_Keyboard) then
weapon = weapon ~= "AK47" and "AK47"
if not weapon then
OutputLogMessage("OFF-Macro-AK47\n")
if IsKeyLockOn("numlock") then
PressAndReleaseKey("numlock")
end
else
OutputLogMessage("ON-NoRecoil-AK47\n")
if not IsKeyLockOn("numlock") then
PressAndReleaseKey("numlock")
end
end
------------- for adding another weapon -----------
elseif (event == "MOUSE_BUTTON_PRESSED" and arg == AnotherWeapon_Mouse) or (event == "G_PRESSED" and arg == AnotherWeapon_Keyboard) then
weapon = weapon ~= "AnotherWeapon" and "AnotherWeapon"
if not weapon then
OutputLogMessage("OFF-Macro-AnotherWeapon\n")
if IsKeyLockOn("numlock") then
PressAndReleaseKey("numlock")
end
else
OutputLogMessage("ON-NoRecoil-AnotherWeapon\n")
if not IsKeyLockOn("numlock") then
PressAndReleaseKey("numlock")
end
end
---------------------------------------------------
elseif (event == "MOUSE_BUTTON_PRESSED" and arg == SpeedX2Modifier_Mouse) or (event == "G_PRESSED" and arg == SpeedX2Modifier_Keyboard) then
SpeedX2 = not SpeedX2
if not SpeedX2 then
OutputLogMessage("OFF-SpeedX2\n")
else
OutputLogMessage("ON-SpeedX2\n")
end
elseif event == "MOUSE_BUTTON_PRESSED" and arg == 1 and weapon and IsMouseButtonPressed(3) then
local recoil_sequence = recoil_table[weapon..(
IsKeyLockOn("capslock") and "_crouch" or
IsKeyLockOn("scrolllock") and "_reddot" or "")] or {}
local x, y, tm = 0, 0, GetRunningTime()
for j = 3, #recoil_sequence, 3 do
local dx_10ms = recoil_sequence[j-2]
local dy_10ms = recoil_sequence[j-1]
if SpeedX2 then
dx_10ms = dx_10ms * 2
dy_10ms = dy_10ms * 2
end
local duration = recoil_sequence[j]
repeat
Sleep(10)
if not IsMouseButtonPressed(1) then break end
local dt = math.min(GetRunningTime() - tm, duration)
duration, tm = duration - dt, tm + dt
x, y = x + dt/10 * dx_10ms, y + dt/10 * dy_10ms
local int_x, int_y = math.floor(x), math.floor(y)
x, y = x - int_x, y - int_y
MoveMouseRelative(int_x, int_y)
until duration == 0
if not IsMouseButtonPressed(1) then break end
end
end
end

Love2d / LUA grid locked movement NO DIAGONAL

I thought this would be a common problem but after days of research I can't find a solution. Very new to programming in general and LUA specifically. I'm building a SUPAPLEX clone as a CS50 personal project: the character moves along the grid based map and there's a code that everyone seems to suggest (attached). On release of arrow buttons the movement is continued until the end of a tile, smoothly. But if 2 movement buttons are pushed, it causes brief diagonal movement and that's the problem I'm unsuccessfully trying to solve.
Basically I'm trying to either ignore any input until the movement of the sprite is finished at the end of the grid tile or prevent updating until movement in one direction is complete. Seems like a simple thing but I'm about to give up this whole thing. Frustrating. Any input is hiiiighly appreciated and I'm sure this would be a lot of help for very many people...
function love.load()
love.keyboard.setKeyRepeat(true)
player = {
grid_x = 256,
grid_y = 256,
act_x = 256,
act_y = 256,
speed = 5,
}
map = {
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
{ 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 },
{ 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1 },
{ 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1 },
{ 1, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1 },
{ 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 },
{ 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
{ 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
{ 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
{ 1, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1 },
{ 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 },
{ 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 },
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }
}
function testMap(x, y)
if map[(player.grid_y / 32) + y][(player.grid_x / 32) + x] == 1 then
return false
end
return true
end
function love.keypressed(key)
if key == "up" then
player.grid_y = player.grid_y - 32
elseif key == "down" then
player.grid_y = player.grid_y + 32
elseif key == "left" then
player.grid_x = player.grid_x - 32
elseif key == "right" then
player.grid_x = player.grid_x + 32
end
end
end
function love.update(dt)
player.act_y = player.act_y - ((player.act_y - player.grid_y) * player.speed * dt)
player.act_x = player.act_x - ((player.act_x - player.grid_x) * player.speed * dt)
end
function love.draw()
love.graphics.rectangle("fill", player.act_x, player.act_y, 32, 32)
for y=1, #map do
for x=1, #map[y] do
if map[y][x] == 1 then
love.graphics.rectangle("line", x * 32, y * 32, 32, 32)
end
end
end
end
you're trying to get it to only walk along grid-lines?
take out love.keyboard.setKeyRepeat(true)
and don't use love.keypressed(key)
that's for one-at-a-time keypresses, and it would be hard to use that
with love.keyreleased() to see if all the other keys are released.
use isDown instead, and if one of them isDown, then none of the other dir keys allow input. (along with the couple player.act lines you already have in your update)
player = {
grid_x = 256,
grid_y = 256,
act_x = 256,
act_y = 256,
speed = 5,
dir = ''
}
function love.update(dt)
if love.keyboard.isDown("up", "down", "left", "right") then
if love.keyboard.isDown("up") and ( player.dir == 'up' or player.dir == '' ) then
player.dir = 'up' -- only go up if currently held, or no other dir key being pressed
player.grid_y = player.grid_y - 32
elseif love.keyboard.isDown("down") and ( player.dir == 'down' or player.dir == '' ) then
player.dir = 'down' -- only go down if currently held...
player.grid_y = player.grid_y + 32
elseif key == "left" and ( player.dir == 'left' or player.dir == '' ) then
player.dir = 'left'
player.grid_x = player.grid_x - 32
elseif key == "right" and ( player.dir == 'right' or player.dir == '' ) then
player.dir = 'right'
player.grid_x = player.grid_x + 32
end
else -- none of those keys are being pressed, so player is idle
player.dir = ''
end -- isDown()
player.act_y = player.act_y - ((player.act_y - player.grid_y) * player.speed * dt)
player.act_x = player.act_x - ((player.act_x - player.grid_x) * player.speed * dt)
end -- update()

GridDB Bad Connection Exception

My application runs a sampling query periodically and it was working fine without any issue for around 30 hours. Then suddenly it gave the following error.
Java client is unable to access the Database and get the following exception.
Caused by: com.toshiba.mwcloud.gs.common.GSConnectionException: [145028:JC_BAD_CONNECTION] Failed to update by notification (address=/239.0.0.1:31999, reason=Receive timed out)
at com.toshiba.mwcloud.gs.subnet.NodeResolver.updateMasterInfo(NodeResolver.java:815)
at com.toshiba.mwcloud.gs.subnet.NodeResolver.prepareConnectionAndClusterInfo(NodeResolver.java:522)
at com.toshiba.mwcloud.gs.subnet.NodeResolver.getPartitionCount(NodeResolver.java:205)
at com.toshiba.mwcloud.gs.subnet.GridStoreChannel$5.execute(GridStoreChannel.java:2106)
at com.toshiba.mwcloud.gs.subnet.GridStoreChannel.executeStatement(GridStoreChannel.java:1675)
... 38 more
Caused by: java.net.SocketTimeoutException: Receive timed out
Why is this happening? What is the cause.
This is the output of gs_stat -u admin/admin
{
"checkpoint": {
"archiveLog": 0,
"backupOperation": 0,
"duplicateLog": 0,
"endTime": 1580053987745,
"mode": "NORMAL_CHECKPOINT",
"normalCheckpointOperation": 1470,
"pendingPartition": 0,
"periodicCheckpoint": "ACTIVE",
"requestedCheckpointOperation": 0,
"startTime": 1580053987741
},
"cluster": {
"activeCount": 0,
"autoGoal": "ACTIVE",
"clusterName": "defaultCluster",
"clusterRevisionId": "4e9be62e-7911-48a4-8d93-19af09be7a15",
"clusterRevisionNo": 17651,
"clusterStatus": "SUB_CLUSTER",
"designatedCount": 1,
"loadBalancer": "ACTIVE",
"nodeList": [
{
"address": "10.128.0.2",
"port": 10040
}
],
"nodeStatus": "ABNORMAL",
"notificationMode": "MULTICAST",
"partitionStatus": "INITIAL",
"startupTime": "2020-01-25T15:20:31.377Z",
"syncCount": 0
},
"currentTime": "2020-01-26T17:20:39Z",
"performance": {
"backupCount": 0,
"batchFree": 0,
"bufferHashCollisionCount": 0,
"checkpointFileAllocateSize": 5443584,
"checkpointFileFlushCount": 0,
"checkpointFileFlushTime": 0,
"checkpointFileSize": 5439488,
"checkpointFileUsageRate": 0.927710843373494,
"checkpointMemory": 196608,
"checkpointMemoryLimit": 1073741824,
"checkpointWriteSize": 270139392,
"checkpointWriteTime": 214,
"currentCheckpointWriteBufferSize": 0,
"currentTime": 1580059239771,
"expirationDetail": {
"autoExpire": false,
"erasableExpiredTime": "1970-01-01T00:00:00.000Z",
"latestExpirationCheckTime": "1970-01-01T00:00:00.000Z"
},
"logFileFlushCount": 8832,
"logFileFlushTime": 38224,
"numBackground": 0,
"numConnection": 2,
"numNoExpireTxn": 0,
"numSession": 0,
"numTxn": 0,
"ownerCount": 128,
"peakProcessMemory": 86626304,
"processMemory": 86626304,
"recoveryReadSize": 262144,
"recoveryReadTime": 0,
"recoveryReadUncompressTime": 0,
"storeCompressionMode": "NO_BLOCK_COMPRESSION",
"storeDetail": {
"batchFreeMapData": {
"storeMemory": 0,
"storeUse": 0,
"swapRead": 0,
"swapWrite": 0
},
"batchFreeRowData": {
"storeMemory": 0,
"storeUse": 0,
"swapRead": 0,
"swapWrite": 0
},
"mapData": {
"storeMemory": 131072,
"storeUse": 131072,
"swapRead": 0,
"swapWrite": 0
},
"metaData": {
"storeMemory": 131072,
"storeUse": 131072,
"swapRead": 0,
"swapWrite": 0
},
"rowData": {
"storeMemory": 4784128,
"storeUse": 4784128,
"swapRead": 0,
"swapWrite": 0
}
},
"storeMemory": 5046272,
"storeMemoryLimit": 1073741824,
"storeTotalUse": 5046272,
"swapRead": 0,
"swapReadSize": 0,
"swapReadTime": 0,
"swapReadUncompressTime": 0,
"swapWrite": 0,
"swapWriteCompressTime": 0,
"swapWriteSize": 0,
"swapWriteTime": 0,
"syncReadSize": 0,
"syncReadTime": 0,
"syncReadUncompressTime": 0,
"totalBackupLsn": 0,
"totalLockConflictCount": 0,
"totalOtherLsn": 0,
"totalOwnerLsn": 110220,
"totalReadOperation": 4733,
"totalRowRead": 2325894,
"totalRowWrite": 55108,
"totalWriteOperation": 55108,
"txnDetail": {
"totalBackgroundOperation": 0
}
},
"recovery": {
"progressRate": 1
},
"version": "4.3.0-36424 CE"
}
It seems that it is being dealt separately at GitHub.
Please refer to this post:
https://github.com/griddb/griddb_nosql/issues/235

Getting Sum & Average from response coming from Server

I am iOS developer & I have JSON file in my project. I am getting below JSON array from a file saved as below
["fa", "pinfield", [
[0, 0, 26082730, ["pt", 213.3332769870769, 584.3332864443584, 414, 226]],
[1, 0, 26082819, ["pt", 0, 0, 414, 226]]
]],
["fa", "pinfield", [
[0, 0, 26084394, ["pt", 195.999944249791, 529.3332950671626, 414, 226]],
[1, 0, 26084475, ["pt", 0, 0, 414, 226]]
]],
["fa", "pinfield", [
[0, 0, 26082219, ["pt", 221.3332726558057, 555.9999453624226, 414, 226]],
[1, 0, 26082310, ["pt", 0, 0, 414, 226]]
]],
["fa", "pinfield", [
[0, 0, 26083275, ["pt", 200.3332853317256, 641.3332811991493, 414, 226]],
[1, 0, 26083364, ["pt", 0, 0, 414, 226]]
]],
["fa", "pinfield", [
[0, 0, 26083755, ["pt", 224.3332901000954, 705.3332707087325, 414, 226]],
[1, 0, 26083836, ["pt", 0, 0, 414, 226]]
]]
There are five objects in this array & each array have sub-arrays.
Now is there any way to calculate the average of above values & put into a signle array as below
["fa", "pinfield", [
[0, 0, xxx, ["pt", xxx.xxxxx, xxx.xxxxx, xxx.xxxxx, xxx.xxxxx]],
[1, 0, xxx, ["pt", 0, 0, xxx.xxxxx, xxx.xxxxx]]
]]
I can run for loops but it will be a time taking approach. Any help would be great.
At some level solving this problem will involve looping through your array of data, building sum and average values.
You could use the Swift reduce higher-order function to build a sum of all of the other values, and then calculate the average in a final step.
An example of using reduce to calculate the sum and average of a simpler array:
let array = [1, 7, 14, 35, 14, 12, 17]
let sum = array.reduce(0, +)
let average = Double(sum) / Double(array.count)
print("Sum = \(sum), avrage = \(average)")

gawk: change 5th element on every other line

I want to add a line break (\n) in front of the 5th element on every other line:
2, 0, 0, 0, 2
4, 0, 0, 0, 4
6, 0, 0, 0, 6
8, 0, 0, 0, 8
... in order to get:
2, 0, 0, 0, 2
4, 0, 0, 0, \n4
6, 0, 0, 0, 6
8, 0, 0, 0, \n8
What I have so far in gawk doesn't work:
gawk '{if (NR % 2) {$5=\n$5; print} else print}'
You could say:
awk '{NR%2 || $5="\\n"$5 }1' filename
Note that you'll need to escape the \ in order to get a literal \.
For your input, it'd produce:
2, 0, 0, 0, 2
4, 0, 0, 0, \n4
6, 0, 0, 0, 6
8, 0, 0, 0, \n8
Alternatively, (as pointed out by #WilliamPursell), you could say:
awk '!(NR%2) {$5="\\n"$5 }1' filename

Resources