dylanplummer commited on
Commit
3908691
·
verified ·
1 Parent(s): dbab62b

Update hls_download.py

Browse files
Files changed (1) hide show
  1. hls_download.py +39 -38
hls_download.py CHANGED
@@ -1,39 +1,40 @@
1
- import subprocess
2
- import os
3
-
4
- def download_clips(stream_url, out_dir, start_time, end_time, resize=True, use_60fps=False):
5
- # remove all .mp4 files in out_dir to avoid confusion
6
- if len(os.listdir(out_dir)) > 5:
7
- for f in os.listdir(out_dir):
8
- if f.endswith('.mp4'):
9
- os.remove(os.path.join(out_dir, f))
10
- output_file = os.path.join(out_dir, f"train_{len(os.listdir(out_dir))}.mp4")
11
- if resize: # resize and convert to 30 fps
12
- ffmpeg_cmd = [
13
- 'ffmpeg',
14
- #'-hwaccel', 'cuda',
15
- '-i', stream_url,
16
- '-c:v', 'libx264',
17
- '-crf', '23',
18
- '-r', '30' if not use_60fps else '60',
19
- '-maxrate', '2M',
20
- '-bufsize', '4M',
21
- '-vf', f"scale=-2:300",
22
- '-ss', start_time] + (['-to', end_time] if end_time != '' else []) + [
23
- '-c:a', 'aac',
24
- '-b:a', '128k',
25
- '-y',
26
- output_file
27
- ]
28
- print(' '.join(ffmpeg_cmd))
29
- try:
30
- subprocess.run(ffmpeg_cmd, check=True, capture_output=True, text=True)
31
- except subprocess.CalledProcessError as e:
32
- print(f"Error occurred: {e}")
33
- print(f"ffmpeg output: {e.output}")
34
- return output_file
35
- # else:
36
- # os.rename(tmp_file, output_file)
37
- print(f"Converted {output_file}")
38
-
 
39
  return output_file
 
1
+ import subprocess
2
+ import os
3
+
4
+ def download_clips(stream_url, out_dir, start_time, end_time, resize=True, use_60fps=False):
5
+ # remove all .mp4 files in out_dir to avoid confusion
6
+ if len(os.listdir(out_dir)) > 5:
7
+ for f in os.listdir(out_dir):
8
+ if f.endswith('.mp4'):
9
+ os.remove(os.path.join(out_dir, f))
10
+ output_file = os.path.join(out_dir, f"train_{len(os.listdir(out_dir))}.mp4")
11
+ if resize: # resize and convert to 30 fps
12
+ ffmpeg_cmd = [
13
+ 'ffmpeg',
14
+ #'-hwaccel', 'cuda',
15
+ '-allowed_extensions', 'ALL',
16
+ '-i', stream_url,
17
+ '-c:v', 'libx264',
18
+ '-crf', '23',
19
+ '-r', '30' if not use_60fps else '60',
20
+ '-maxrate', '2M',
21
+ '-bufsize', '4M',
22
+ '-vf', f"scale=-2:300",
23
+ '-ss', start_time] + (['-to', end_time] if end_time != '' else []) + [
24
+ '-c:a', 'aac',
25
+ '-b:a', '128k',
26
+ '-y',
27
+ output_file
28
+ ]
29
+ print(' '.join(ffmpeg_cmd))
30
+ try:
31
+ subprocess.run(ffmpeg_cmd, check=True, capture_output=True, text=True)
32
+ except subprocess.CalledProcessError as e:
33
+ print(f"Error occurred: {e}")
34
+ print(f"ffmpeg output: {e.output}")
35
+ return output_file
36
+ # else:
37
+ # os.rename(tmp_file, output_file)
38
+ print(f"Converted {output_file}")
39
+
40
  return output_file