Git Bash for Windows AttributeError: ‘NoneType’ object has no attribute ‘groups’ using Python re to parse string

  attributeerror, git, python, re, windows

I am trying to use a pretrained CNN model for a project and some of the included code is having issues on my machine. Windows 10, git version 2.28.0.windows.1, Python 3.9.0

This code hails from https://github.com/zhoubolei/moments_models/tree/v2

output = subprocess.Popen(['ffmpeg', '-i', video_file], stderr=subprocess.PIPE, shell=True).communicate()
# Search and parse 'Duration: 00:05:24.13,' from ffmpeg stderr.
re_duration = re.compile(r'Duration: (.*?).')
duration = re_duration.search(str(output[1])).groups()[0]

I get the following traceback:

Traceback (most recent call last):
  File "C:UsersgradxPycharmProjectsfinalmoments_modelstest_video.py", line 62, in <module>
    frames = extract_frames(args.video_file, args.num_segments)
  File "C:UsersgradxPycharmProjectsfinalmoments_modelsutils.py", line 21, in extract_frames
    duration = re_duration.search(str(output[1])).groups()[0]
AttributeError: 'NoneType' object has no attribute 'groups'

Essentially the goal is to collect the run time of the input video file from some string Popen and re.complile() produce. This is not my code so I can’t say why this method is used, but also can’t suggest a different one. I’ve tried modifying the regular expression passed to re.compile() because I realize that could return None if nothing is found, but this hasn’t helped.

Any support is appreciated.

Source: Windows Questions

LEAVE A COMMENT