dylanplummer commited on
Commit
4ca2ffd
·
1 Parent(s): 779feb1

even fewer pixels

Browse files
Files changed (1) hide show
  1. hls_download.py +50 -48
hls_download.py CHANGED
@@ -1,48 +1,50 @@
1
- import subprocess
2
- import os
3
-
4
- def download_clips(stream_url, out_dir, start_time, end_time, resize=True):
5
- output_file = os.path.join(out_dir, f"train_{len(os.listdir(out_dir))}.mp4")
6
- tmp_file = os.path.join(out_dir, f"train_{len(os.listdir(out_dir))}_tmp.mp4")
7
- yt_dlp_cmd = [
8
- 'yt-dlp',
9
- '--download-sections', f'*{start_time}-{end_time}',
10
- stream_url,
11
- '-o', tmp_file
12
- ]
13
-
14
- print(' '.join(yt_dlp_cmd))
15
-
16
- try:
17
- subprocess.run(yt_dlp_cmd, check=True, capture_output=True, text=True)
18
- except subprocess.CalledProcessError as e:
19
- print(f"Error occurred: {e}")
20
- print(f"yt-dlp output: {e.output}")
21
- return None
22
-
23
- if resize: # resize and convert to 30 fps
24
- ffmpeg_cmd = [
25
- 'ffmpeg',
26
- '-i', tmp_file,
27
- '-c:v', 'libx264',
28
- '-preset', 'veryfast',
29
- '-crf', '23',
30
- '-r', '30',
31
- '-maxrate', '2M',
32
- '-bufsize', '4M',
33
- '-vf', f"scale=-2:320",
34
- '-c:a', 'aac',
35
- '-b:a', '128k',
36
- '-y',
37
- output_file
38
- ]
39
- try:
40
- subprocess.run(ffmpeg_cmd, check=True, capture_output=True, text=True)
41
- except subprocess.CalledProcessError as e:
42
- print(f"Error occurred: {e}")
43
- print(f"ffmpeg output: {e.output}")
44
- return None
45
- else:
46
- os.rename(tmp_file, output_file)
47
-
48
- return output_file
 
 
 
1
+ import subprocess
2
+ import os
3
+
4
+ def download_clips(stream_url, out_dir, start_time, end_time, resize=True):
5
+ output_file = os.path.join(out_dir, f"train_{len(os.listdir(out_dir))}.mp4")
6
+ tmp_file = os.path.join(out_dir, f"train_{len(os.listdir(out_dir))}_tmp.mp4")
7
+ yt_dlp_cmd = [
8
+ 'yt-dlp',
9
+ '--download-sections', f'*{start_time}-{end_time}',
10
+ stream_url,
11
+ '-o', tmp_file
12
+ ]
13
+
14
+ print(' '.join(yt_dlp_cmd))
15
+
16
+ try:
17
+ subprocess.run(yt_dlp_cmd, check=True, capture_output=True, text=True)
18
+ except subprocess.CalledProcessError as e:
19
+ print(f"Error occurred: {e}")
20
+ print(f"yt-dlp output: {e.output}")
21
+ return None
22
+ print(f"Downloaded {output_file}")
23
+ if resize: # resize and convert to 30 fps
24
+ ffmpeg_cmd = [
25
+ 'ffmpeg',
26
+ '-i', tmp_file,
27
+ '-c:v', 'libx264',
28
+ '-preset', 'veryfast',
29
+ '-crf', '23',
30
+ '-r', '30',
31
+ '-maxrate', '2M',
32
+ '-bufsize', '4M',
33
+ '-vf', f"scale=-2:300",
34
+ '-c:a', 'aac',
35
+ '-b:a', '128k',
36
+ '-y',
37
+ output_file
38
+ ]
39
+ print(' '.join(ffmpeg_cmd))
40
+ try:
41
+ subprocess.run(ffmpeg_cmd, check=True, capture_output=True, text=True)
42
+ except subprocess.CalledProcessError as e:
43
+ print(f"Error occurred: {e}")
44
+ print(f"ffmpeg output: {e.output}")
45
+ return None
46
+ else:
47
+ os.rename(tmp_file, output_file)
48
+ print(f"Converted {output_file}")
49
+
50
+ return output_file