diff --git a/README.md b/README.md index ae8ad15..48581a6 100644 --- a/README.md +++ b/README.md @@ -40,11 +40,16 @@ python stream_m3u_to_rtmp.py \ "https://example.com/live/stream.m3u8" \ "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 \ "playlist.m3u8" \ "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 python stream_m3u_to_rtmp.py \ "https://example.com/stream.m3u8" \ diff --git a/stream_m3u_to_rtmp.py b/stream_m3u_to_rtmp.py index 2e9b1de..c2325d4 100644 --- a/stream_m3u_to_rtmp.py +++ b/stream_m3u_to_rtmp.py @@ -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. 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) 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) # -i: input M3U8 URL # -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_path, - '-i', m3u_url, + '-i', m3u_input, '-c', 'copy', # Copy all streams without re-encoding '-f', 'flv', # RTMP requires FLV format '-flvflags', 'no_duration_filesize', @@ -102,7 +116,7 @@ def main(): ) parser.add_argument( '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( 'rtmp_url',