Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

create_mini_videos.py 1.8 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
  1. import ffmpeg
  2. import pickle
  3. import os
  4. whole_vid_dir = '/media/hdd_data1/michael/deeplabcut'
  5. videos = {'15122014': 'crop_30fps2014-12-15T15_42_21.avi',
  6. '16122014': 'crop_30fps2014-12-16T15_35_28.avi',
  7. '17122014': 'crop_30fps2014-12-17T17_23_38.avi',
  8. '18122014': 'crop_30fps2014-12-18T18_09_05.avi',
  9. '19122014': 'crop_30fps2014-12-19_concatenated.avi',
  10. '20122014': 'crop_30fps2014-12-20T17_53_17.avi',
  11. '21122014': 'crop_30fps2014-12-21T15_10_39.avi',
  12. '22122014': 'crop_30fps2014-12-22T16_51_00.avi',
  13. '23122014': 'crop_30fps2014-12-23T14_08_57.avi'}
  14. video_out_dir = '/media/hdd_data1/michael/deeplabcut/subvideos'
  15. mice = ['4I', '4II', '4III', '4IV', '5I', '5II', '5III', '5IV']
  16. days = list(videos.keys())
  17. # file containing start and end times for each mice in the session video in ms
  18. metadata_file_path = '../cache/time_shifts.pickle'
  19. with open(metadata_file_path, 'rb') as f:
  20. times = pickle.load(f)
  21. # TODO: this should be substituted by a for loop for all days
  22. for day in days:
  23. video_file_path = os.path.join(whole_vid_dir, videos[day])
  24. stream = ffmpeg.input(video_file_path)
  25. for mouse in mice:
  26. t_start, t_stop = times[day][mouse] # in ms
  27. t_start /= 1000 # convert to s
  28. t_stop /= 1000 # convert to s
  29. stream = ffmpeg.input(video_file_path, ss=t_start, to=t_stop)
  30. # stream = ffmpeg.trim(stream, start=t_start, end=t_stop)
  31. video_out_dir_day = os.path.join(video_out_dir, day)
  32. if not os.path.exists(video_out_dir_day):
  33. os.makedirs(video_out_dir_day)
  34. video_out_path = os.path.join(video_out_dir_day,
  35. 'crop_30fps_%s_%s.avi' % (day, mouse))
  36. stream = ffmpeg.output(stream, video_out_path, codec='copy')
  37. ffmpeg.run(stream)
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...