Update test_facebook test case

This commit is contained in:
Linus 2019-07-21 09:14:06 +12:00
parent ca31154cef
commit ba00ff8b68

View File

@ -1,20 +1,22 @@
from __future__ import unicode_literals
from builtins import bytes
from builtins import range
from builtins import str
import ffmpeg
import os
import pytest
import random
import re
import subprocess
from builtins import bytes, range, str
import ffmpeg
import pytest
from ffmpeg import nodes
try:
import mock # python 2
except ImportError:
from unittest import mock # python 3
def pip_to_facebook(stream_key: str):
def pip_to_rtmp(url: str):
""" Capture Facetime camera and screen in macOS and stream it to facebook
"""
facetime_camera_input = (
@ -24,6 +26,7 @@ except ImportError:
audio = facetime_camera_input.audio
# ffmpeg in MacOS AVFoundation MUST increase the thread_queue_size in order to handle PIP
video = (
ffmpeg
.header(thread_queue_size='512', vsync='2')
@ -34,12 +37,18 @@ except ImportError:
)
output = (
ffmpeg
.output(video, audio, 'rtmps://live-api-s.facebook.com:443/rtmp/{}'.format(stream_key), vsync='2', s='1280x720', pix_fmt='yuv420p', video_bitrate='1500000', f='flv',
vcodec='libx264', preset='superfast', x264opts='keyint=15', g='30', ac='2', ar='48000', acodec="aac", audio_bitrate="128000")
.output(video, audio, url, vsync='2', s='1280x720', pix_fmt='yuv420p', video_bitrate='1500000', f='flv',
vcodec='libx264', preset='fast', x264opts='keyint=15', g='30', ac='2', ar='48000', acodec="aac", audio_bitrate="128000")
)
output.overwrite_output().run()
return output.overwrite_output().compile()
def test_fluent_equality():
pip_to_facebook('351682605501180?s_bl=1&s_ps=1&s_sml=1&s_sw=0&s_vt=api-s&a=AbzMoYVOuxBYwxs7')
def test_rtmp():
expected_result = ['ffmpeg', '-thread_queue_size', '512', '-vsync', '2', '-f', 'avfoundation', '-framerate', '30', '-pix_fmt', 'uyvy422', '-probesize', '200M', '-i', '1:1', '-f', 'avfoundation', '-framerate', '30', '-pix_fmt', 'uyvy422', '-probesize', '200M', '-s', '320x240', '-i', 'FaceTime:1', '-filter_complex', '[0][1]overlay=eof_action=repeat[s0]',
'-map', '[s0]', '-map', '1:a', '-f', 'flv', '-b:v', '1500000', '-b:a', '128000', '-ac', '2', '-acodec', 'aac', '-ar', '48000', '-g', '30', '-pix_fmt', 'yuv420p', '-preset', 'fast', '-s', '1280x720', '-vcodec', 'libx264', '-vsync', '2', '-x264opts', 'keyint=15', 'rtmps://live-api-s.facebook.com:443/rtmp/input_your_facebook_stream_key_here', '-y']
# Your facebook key should look like: 123456789012345?s_bl=1&s_ps=1&s_sml=1&s_sw=0&s_vt=api-s&a=AbCdEfGhiJK12345
your_facebook_key = 'input_your_facebook_stream_key_here'
facebook_stream_url = 'rtmps://live-api-s.facebook.com:443/rtmp/{}'.format(your_facebook_key)
result = pip_to_rtmp(facebook_stream_url)
assert result == expected_result