ChandimaPrabath commited on
Commit
0e4a709
·
1 Parent(s): 1893784
Files changed (1) hide show
  1. video.py +6 -1
video.py CHANGED
@@ -2,6 +2,7 @@ import os
2
  import logging
3
  import uuid
4
  from ffmpy import FFmpeg
 
5
 
6
  # Set up logging
7
  logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s')
@@ -18,14 +19,18 @@ def ffmpeg_stream(file_url, token, output_dir="tmp/cache/stream"):
18
  output_path = os.path.join(stream_dir, 'output.m3u8')
19
  segment_filename = os.path.join(stream_dir, 'segment_%03d.ts')
20
 
 
 
 
21
  # Construct the FFmpeg command using ffmpy
 
22
  ff = FFmpeg(
23
  inputs={file_url: None},
24
  outputs={
25
  output_path: f'-c:v libx264 -crf 23 -preset medium -c:a aac -b:a 192k -f hls '
26
  f'-hls_time 10 -hls_list_size 0 -hls_segment_filename {segment_filename}'
27
  },
28
- global_options=f'-headers \"Authorization: Bearer {token}\"\r\n'
29
  )
30
 
31
  try:
 
2
  import logging
3
  import uuid
4
  from ffmpy import FFmpeg
5
+ from urllib.parse import quote
6
 
7
  # Set up logging
8
  logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s')
 
19
  output_path = os.path.join(stream_dir, 'output.m3u8')
20
  segment_filename = os.path.join(stream_dir, 'segment_%03d.ts')
21
 
22
+ # URL encode the file URL
23
+ file_url = quote(file_url, safe=':/')
24
+
25
  # Construct the FFmpeg command using ffmpy
26
+ headers = f"Authorization: Bearer {token}"
27
  ff = FFmpeg(
28
  inputs={file_url: None},
29
  outputs={
30
  output_path: f'-c:v libx264 -crf 23 -preset medium -c:a aac -b:a 192k -f hls '
31
  f'-hls_time 10 -hls_list_size 0 -hls_segment_filename {segment_filename}'
32
  },
33
+ global_options=[f'-headers', headers]
34
  )
35
 
36
  try: