dylan-plummer commited on
Commit
28fe16f
·
1 Parent(s): 0df0393

test claude suggestions

Browse files
Files changed (1) hide show
  1. hls_download.py +29 -30
hls_download.py CHANGED
@@ -1,35 +1,34 @@
1
  import subprocess
2
  import os
3
- # import m3u8
4
- # import numpy as np
5
- # import matplotlib.pyplot as plt
6
- # from tqdm import tqdm
7
- # from moviepy.editor import VideoFileClip
8
- # from scipy.signal import correlate, find_peaks
9
- # from scipy.io import wavfile
10
-
11
 
12
  def download_clips(stream_url, out_dir, start_time, end_time, resize=True):
13
  output_file = os.path.join(out_dir, f"train_{len(os.listdir(out_dir))}.mp4")
14
- # output video at 30fps
15
- if resize:
16
- subprocess.run(['ffmpeg', '-f', 'hls', '-i', stream_url,
17
- '-ss', str(start_time - 2),
18
- '-to', str(end_time + 2), # pad end time by a couple of seconds
19
- '-r', str(30),
20
- '-vcodec', 'libx264',
21
- '-crf', str(24),
22
- '-preset', 'fast',
23
- '-vf', 'scale=-2:360',
24
- '-c:a', 'copy', output_file])
25
- else:
26
- subprocess.run(['ffmpeg', '-f', 'hls', '-i', stream_url,
27
- '-ss', str(start_time - 2),
28
- '-to', str(end_time + 2), # pad end time by a couple of seconds
29
- '-r', str(30),
30
- '-vcodec', 'libx264',
31
- '-crf', str(24),
32
- '-preset', 'fast',
33
- '-vf', 'scale=-2:720',
34
- '-c:a', 'copy', output_file])
35
- 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
+
7
+ ffmpeg_cmd = [
8
+ 'ffmpeg',
9
+ '-loglevel', 'warning', # Reduce log output
10
+ '-f', 'hls',
11
+ '-i', stream_url,
12
+ '-ss', str(max(0, start_time - 2)), # Ensure start time is not negative
13
+ '-to', str(end_time + 2),
14
+ '-r', '30',
15
+ '-c:v', 'libx264',
16
+ '-preset', 'ultrafast', # Use fastest encoding preset
17
+ '-crf', '23', # Slightly lower CRF for better quality
18
+ '-maxrate', '1M', # Limit bitrate
19
+ '-bufsize', '2M',
20
+ '-vf', f"scale=-2:{360 if resize else 720}",
21
+ '-c:a', 'aac', # Re-encode audio for better compatibility
22
+ '-b:a', '128k',
23
+ '-max_muxing_queue_size', '1024', # Increase muxing queue size
24
+ '-y', # Overwrite output file if it exists
25
+ output_file
26
+ ]
27
+
28
+ try:
29
+ subprocess.run(ffmpeg_cmd, check=True, capture_output=True, text=True)
30
+ return output_file
31
+ except subprocess.CalledProcessError as e:
32
+ print(f"Error occurred: {e}")
33
+ print(f"FFmpeg output: {e.output}")
34
+ return None