[Common, ffmpeg]Exp: Add a ffmpeg downloader and player for any URL

This commit is contained in:
David Zhuang 2016-06-29 15:56:39 -04:00
parent 7c2ea4f641
commit 5966a090f4
3 changed files with 79 additions and 0 deletions

View File

@ -898,6 +898,23 @@ def download_rtmp_url(url,title, ext,params={}, total_size=0, output_dir='.', re
assert has_rtmpdump_installed(), "RTMPDump not installed."
download_rtmpdump_stream(url, title, ext,params, output_dir)
def download_url_ffmpeg(url,title, ext,params={}, total_size=0, output_dir='.', refer=None, merge=True, faker=False):
assert url
if dry_run:
print('Real URL:\n%s\n' % [url])
if params.get("-y",False): #None or unset ->False
print('Real Playpath:\n%s\n' % [params.get("-y")])
return
if player:
from .processor.ffmpeg import ffmpeg_play_stream
ffmpeg_play_stream(player, url, params)
return
from .processor.ffmpeg import has_ffmpeg_installed, ffmpeg_download_streaming
assert has_ffmpeg_installed(), "FFmpeg not installed."
ffmpeg_download_stream(url, title, ext, params, output_dir)
def playlist_not_supported(name):
def f(*args, **kwargs):
raise NotImplementedError('Playlist is not supported for ' + name)

View File

@ -199,3 +199,64 @@ def ffmpeg_concat_mp4_to_mp4(files, output='output.mp4'):
for file in files:
os.remove(file + '.ts')
return True
def ffmpeg_download_stream(files, title, ext, params={}, output_dir='.'):
"""str, str->True
WARNING: NOT THE SAME PARMS AS OTHER FUNCTIONS!!!!!!
You can basicly download anything with this function
but better leave it alone with
"""
output = title + '.' + ext
if not (output_dir == '.'):
output = output_dir + output
ffmpeg_params = []
#should these exist...
if len(params) > 0:
for k, v in params:
ffmpeg_params.append(k)
ffmpeg_params.append(v)
print('Downloading streaming content with FFmpeg, press Ctrl+C to stop recording...')
ffmpeg_params = [FFMPEG] + LOGLEVEL + ['-y', '-i']
ffmpeg_params.append(files) #not the same here!!!!
if FFMPEG == 'avconv': #who cares?
ffmpeg_params += ['-c', 'copy', output]
else:
ffmpeg_params += ['-c', 'copy', '-bsf:a', 'aac_adtstoasc', '-bsf:v', 'h264_mp4toannexb', output]
ffmpeg_params.append(output)
subprocess.call(ffmpeg_params)
return True
#
#To be refactor
#Direct copy of rtmpdump.py
#
def ffmpeg_play_stream(player, url, params={}):
ffmpeg_params = []
#should these exist...
if len(params) > 0:
for k, v in params:
ffmpeg_params.append(k)
ffmpeg_params.append(v)
print('Playing streaming content with FFmpeg, press Ctrl+C to stop recording...')
ffmpeg_params = [FFMPEG] + LOGLEVEL + ['-y', '-i']
ffmpeg_params.append(url) #not the same here!!!!
if FFMPEG == 'avconv': #who cares?
ffmpeg_params += ['-c', 'copy', '|']
else:
ffmpeg_params += ['-c', 'copy', '-bsf:a', 'aac_adtstoasc', '-bsf:v', 'h264_mp4toannexb', '|']
ffmpeg_params += [player, '-']
print(' '.join(ffmpeg_params))
subprocess.call(ffmpeg_params)
return

View File

@ -43,6 +43,7 @@ def download_rtmpdump_stream(url, title, ext,params={},output_dir='.'):
#
#To be refactor
#To the future myself: Remember to refactor the same function in ffmpeg.py
#
def play_rtmpdump_stream(player, url, params={}):
cmdline="rtmpdump -r '%s' "%url