Frame extraction processing of something-somethingV2 data set

Regarding the problems I encountered when processing the ssv2 data set, it’s really terrible. Although it’s not a big problem, it can mess with people’s mentality.

1. Brief introduction to the problem

Because the ssv2 data set is all videos, unlike ssv1 which has ready-made jpg images, the video needs to be extracted and processed here. There are roughly two mainstream processing methods on the Internet:

The first one is provided by Seaweed Eyebrow, the up host on csdn:

http://t.csdnimg.cn/FoLsO

The second is a data set processing provided by the TSM author on github, which not only includes frame extraction for ssv2, but also subsequent division processing, as well as the processing of k400 and ssv1 data sets. Very detailed, here is a link:

https://github.com/mit-han-lab/temporal-shift-module/blob/master/tools/vid2img_sthv2.py

Both methods are implemented using ffmpeg, and the codes are similar. I used the first code from the csdn boss, and changed one place – added a frame rate fps: frames per second. quantity.

The original code is:

except:
print(dst_directory_path)
continue
cmd = 'ffmpeg -i "{}" -vf scale=-1:240 "{}/ d.jpg"'.format(video_file_path, dst_directory_path)
print(cmd)
subprocess.call(cmd, shell=True)
print('\
')

Mine is:

except:
print(dst_directory_path)
continue
cmd = 'ffmpeg -i "{}" -r 24 -vf scale=-1:240 "{}/ d.jpg"'.format(video_file_path, dst_directory_path)
print(cmd)
subprocess.call(cmd, shell=True)
print('\
')

Added -r 24: means to extract 24 frames every second

-i: The file path of the video to be processed

The first {} is the ssv2 video in webm format to be processed, which does not need to be converted to mp4, which is the value corresponding to video_file_path. The second {} is the path to generate the jpg image, which is the value corresponding to dst_directory_path.

– vf: Specify the width of the image

scale = – 1:240: Adaptively adjust the width according to the aspect ratio of the video, the height is 240 pixels

(The final actual size is width and height: 427*240)

d.jpg: It is the picture format and name of the extracted frame. Six digits are left here for naming, starting from 000001

2. Specific operation procedures

I won’t go into details about downloading and decompressing the data set. You can refer to the old man’s approach. Here is a brief introduction to the frame extraction operation. Copy the code and save it in .py format, and then create a new jpg folder to store the frame extraction. ,As shown in the picture, my ssv2 video folder is input_dir, the folder where pictures are stored is img_ssv2, and the code name is video_to_jpg.py

Then win + r, cmd and press Enter to enter the directory where the data set is located. My data set is on the D drive. Enter D:, then enter cd D:\file\somethingV2 to enter the specified directory, and then run the code:

python code name.py dir_path dst_dir_path

python and .py files, there is a space between the input path and the output path

dir_path: is the ssv2 video storage folder in webm format to be processed

dst_dir_path: is the folder where the generated jpg images are stored.

What I am running is:

python video_to_jpg.py D:\file\somethingV2\input_dir D:\file\somethingV2\img_ssv2

Then you can see the running process: it runs very fast because there are many videos, hundreds of thousands of them.

At the same time, click on the img_ssv2 folder and you can see that the corresponding folder is generated, and there are extracted frames in the folder.

Then hang up and wait for it to finish running. It takes about half a day (it was run on a laboratory computer without a server, so it was a bit slow). I successfully produced more than 30,000 in two hours.

3. Some specific issues during the implementation process

It was not all smooth sailing during the specific operation, and I still encountered many problems, so I wanted to write a blog to record them.

1. In the comment area of the original up, some friends said that the final generated folder was empty and had no pictures. I also encountered this problem. Here is a brief explanation:

After running the code, such a bug appeared: ffmpeg е ?

This string of garbled characters is actually ‘ffmpeg’. It is not an internal or external command, nor is it an executable program. Later I found out that I did not install ffmpeg on my computer. It is not enough to install a package in pycharm. I have to go to the official website to find ffmpeg. Download this software, win64 static compressed package, then unzip it and configure environment variables

Hang a link: ffmpeg Old Versions Downloads – VideoHelp — ffmpeg Old Versions Downloads – Video Help

Be sure to download the static one, unzip it after downloading, then find the bin folder and copy the path.

Then add environment variables to it, right-click on My Computer, Properties, Advanced System Settings

After clicking on environment variables, double-click Path to create a new environment variable.

Then just paste the bin path you just copied, and then confirm.

Then win + R, press Enter, and enter ffmpeg -version. If the field as shown appears, the environment variable configuration is successful.

After handling this step, running the frame extraction code just now will be successful, and the garbled code situation will not occur again. I also encountered the same problem. I adopted the second method without configuring the ffmpeg environment variables – the frame extraction code provided by the TSM author on github. I ran this code on the laboratory server. I also encountered a problem when it showed that the bus was busy, and then the corresponding folder was generated in the img_ssv2 folder but there were no pictures in it. Now I think it may be caused by not configuring the environment variables of ffmpeg.

It is recommended that when you start trying to run the code, you can create two new folders for testing. Just put 3-5 webm videos in the input video folder, and then use this to test whether it is successful. If you use the entire video of ssv2 If you use data to test, you may end up generating a lot of empty folders, and then there will be bugs when you run the code.

The knowledge points of the article match the official knowledge files, and you can further learn relevant knowledge. Python entry skill treeArtificial intelligenceDeep learning 385019 people are learning the system