-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsplit_video.py
More file actions
67 lines (56 loc) · 2.42 KB
/
split_video.py
File metadata and controls
67 lines (56 loc) · 2.42 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#import ffmpeg
from subprocess import call
import datetime
#start = '00:00:00'
duration = '01:00:00'
#end = '00:00:10'
# output video dimensions
#DIMENSIONS = '1920x1080'
# output video framerate
#FRAMERATE = '30'
# controls the approximate bitrate of the encode
#BITRATE = '6M'
# encoding speed:compression ratio
#PRESET = 'veryslow'
# output file format
OUTPUT_FILE_EXTENSION = 'mp4'
# relative output directory
#RELATIVE_OUTPUT_DIRECTORY = 'encoded'
# ffmpeg path
# Guide for encoding video using FFMPEG with libx264e: https://trac.ffmpeg.org/wiki/Encode/H.264
FFMPEG_PATH = r'C:\Program Files\ffmpeg-N-104865-g571e8ca2dd-win64-gpl\ffmpeg-N-104865-g571e8ca2dd-win64-gpl\bin\ffmpeg.exe'
output_directory = r"E:\Social-interaction-Recordings\2022-07-06@12_27_44f403084\2022-07-06@12_27_44f403084_RPi_recording_splits\\"
input_file_path = r"E:\Social-interaction-Recordings\2022-07-06@12_27_44f403084\2022-07-06@12_27_44f403084_RPi_recording.h264"
input_file_name = input_file_path.split('\\')[-1]
input_file_name = input_file_name.split('.')[0] + '_split.' + input_file_name.split('.')[-1]
print(f'Input file name: {input_file_name}')
# length of the video
# ffmpeg -i recording_RP_2021_12_09--12-02-59.h264 -f null -
# video length is in this line in the variable `time`: frame=2074416 fps=2159 q=-0.0 Lsize=N/A time=23:02:56.64 bitrate=N/A speed=86.3x
# ## recording_RP_2021_12_09--12-02-59: time=23:02:56.64
# ## recording_RP_2021_12_15--14-00-27: time=28:48:55.28
# An example to extract the time
# my_string="hello python world , i'm a beginner "
# print my_string.split("world",1)[1]
for h in range(0, 24):
#start = f'{datetime.timedelta(hours = h):02d}:00:00'
start = str(datetime.timedelta(hours = h))
#end = str(datetime.timedelta(hours = h + 1)) # we do not need this if we work with `duration` (set `duration` to 01:00:00 and just update `start`)
output_file_path = output_directory + str(h) + '_' + input_file_name
print(f'Output file path: {output_file_path}')
call([
FFMPEG_PATH,
'-i', input_file_path,
'-vcodec', 'copy',
'-ss', start,
#'-to', end,
'-t', duration,
'-f', OUTPUT_FILE_EXTENSION,
#'-s', DIMENSIONS,
#'-b:v', BITRATE,
#'-r', FRAMERATE,
#'-preset', PRESET,
'-threads', '0',
#'-strict', 'experimental',
output_file_path
])