Add local M3U8 file support with validation
This commit is contained in:
@@ -40,11 +40,16 @@ python stream_m3u_to_rtmp.py \
|
|||||||
"https://example.com/live/stream.m3u8" \
|
"https://example.com/live/stream.m3u8" \
|
||||||
"rtmp://live.twitch.tv/app/your_stream_key"
|
"rtmp://live.twitch.tv/app/your_stream_key"
|
||||||
|
|
||||||
# Stream from local M3U8 file
|
# Stream from local M3U8 file (relative or absolute path)
|
||||||
python stream_m3u_to_rtmp.py \
|
python stream_m3u_to_rtmp.py \
|
||||||
"playlist.m3u8" \
|
"playlist.m3u8" \
|
||||||
"rtmp://server.com/live/stream_key"
|
"rtmp://server.com/live/stream_key"
|
||||||
|
|
||||||
|
# Stream from local M3U8 file with absolute path
|
||||||
|
python stream_m3u_to_rtmp.py \
|
||||||
|
"C:/path/to/playlist.m3u8" \
|
||||||
|
"rtmp://server.com/live/stream_key"
|
||||||
|
|
||||||
# Specify custom ffmpeg path
|
# Specify custom ffmpeg path
|
||||||
python stream_m3u_to_rtmp.py \
|
python stream_m3u_to_rtmp.py \
|
||||||
"https://example.com/stream.m3u8" \
|
"https://example.com/stream.m3u8" \
|
||||||
|
|||||||
+17
-3
@@ -14,11 +14,25 @@ def stream_m3u_to_rtmp(m3u_url, rtmp_url, ffmpeg_path='ffmpeg'):
|
|||||||
Stream M3U8 playlist to RTMP server without re-encoding.
|
Stream M3U8 playlist to RTMP server without re-encoding.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
m3u_url: URL or path to M3U8 playlist file
|
m3u_url: URL or path to M3U8 playlist file (supports both local files and URLs)
|
||||||
rtmp_url: RTMP server URL (e.g., rtmp://server/live/stream_key)
|
rtmp_url: RTMP server URL (e.g., rtmp://server/live/stream_key)
|
||||||
ffmpeg_path: Path to ffmpeg executable (default: 'ffmpeg')
|
ffmpeg_path: Path to ffmpeg executable (default: 'ffmpeg')
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# Check if it's a local file
|
||||||
|
is_local_file = not (m3u_url.startswith('http://') or m3u_url.startswith('https://') or m3u_url.startswith('rtmp://'))
|
||||||
|
|
||||||
|
if is_local_file:
|
||||||
|
# Convert to absolute path
|
||||||
|
m3u_path = os.path.abspath(m3u_url)
|
||||||
|
if not os.path.exists(m3u_path):
|
||||||
|
print(f"Error: Local M3U8 file not found: {m3u_path}")
|
||||||
|
return False
|
||||||
|
print(f"Using local M3U8 file: {m3u_path}")
|
||||||
|
m3u_input = m3u_path
|
||||||
|
else:
|
||||||
|
m3u_input = m3u_url
|
||||||
|
|
||||||
# FFmpeg command for direct stream (no re-encoding)
|
# FFmpeg command for direct stream (no re-encoding)
|
||||||
# -i: input M3U8 URL
|
# -i: input M3U8 URL
|
||||||
# -c copy: copy codecs without re-encoding
|
# -c copy: copy codecs without re-encoding
|
||||||
@@ -29,7 +43,7 @@ def stream_m3u_to_rtmp(m3u_url, rtmp_url, ffmpeg_path='ffmpeg'):
|
|||||||
|
|
||||||
ffmpeg_cmd = [
|
ffmpeg_cmd = [
|
||||||
ffmpeg_path,
|
ffmpeg_path,
|
||||||
'-i', m3u_url,
|
'-i', m3u_input,
|
||||||
'-c', 'copy', # Copy all streams without re-encoding
|
'-c', 'copy', # Copy all streams without re-encoding
|
||||||
'-f', 'flv', # RTMP requires FLV format
|
'-f', 'flv', # RTMP requires FLV format
|
||||||
'-flvflags', 'no_duration_filesize',
|
'-flvflags', 'no_duration_filesize',
|
||||||
@@ -102,7 +116,7 @@ def main():
|
|||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'm3u_url',
|
'm3u_url',
|
||||||
help='URL or path to M3U8 playlist file'
|
help='URL or path to M3U8 playlist file (supports both local files and HTTP/HTTPS URLs)'
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'rtmp_url',
|
'rtmp_url',
|
||||||
|
|||||||
Reference in New Issue
Block a user