PW Akshay

Generation

generate functionTue, 17 Jan 2023

create a python program to stream video from m3u8 url to youtube using moviepy module you can also modify this code to do so: from moviepy.editor import VideoFileClip # Replace with the actual M3U8 URL url = "https://xxxxxxx.m3u8" # Open the video file clip = VideoFileClip(url) # Set the codecs and other options clip = clip.set_fps(30).set_audio_fps(44100).set_audio_bitrate(128) # Write the video to file clip.write_videofile("output.flv", codec='libx264', audio_codec='aac')

import subprocess import re import os import time import requests # parse the m3u8 url to get the urls of all the ts segments def parse_m3u8_url(url): r = requests.get(url) m3u8_urls = re.findall(r'\n(http[s]?://.+\.ts)', r.text) ffmpeg_cmd = 'ffmpeg -i "concat:' for url in m3u8_urls: ffmpeg_cmd = ffmpeg_cmd + url + '|' return ffmpeg_cmd[:-1] + '" -acodec copy -vcodec copy -absf aac_adtstoasc output.mp4' def download(cmd): # process the command in linux terminal and return the output process = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE) output = process.communicate() return output def run(url):

Questions about programming?Chat with your personal AI assistant