mirror of
https://github.com/kkroening/ffmpeg-python.git
synced 2025-04-06 04:15:44 +08:00
Update test_facebook test case
This commit is contained in:
parent
ca31154cef
commit
ba00ff8b68
@ -1,45 +1,54 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
from builtins import bytes
|
|
||||||
from builtins import range
|
|
||||||
from builtins import str
|
|
||||||
import ffmpeg
|
|
||||||
import os
|
import os
|
||||||
import pytest
|
|
||||||
import random
|
import random
|
||||||
import re
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
|
from builtins import bytes, range, str
|
||||||
|
|
||||||
|
import ffmpeg
|
||||||
|
import pytest
|
||||||
|
from ffmpeg import nodes
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import mock # python 2
|
import mock # python 2
|
||||||
except ImportError:
|
except ImportError:
|
||||||
from unittest import mock # python 3
|
from unittest import mock # python 3
|
||||||
|
|
||||||
def pip_to_facebook(stream_key: str):
|
|
||||||
""" Capture Facetime camera and screen in macOS and stream it to facebook
|
|
||||||
"""
|
|
||||||
facetime_camera_input = (
|
|
||||||
ffmpeg
|
|
||||||
.input('FaceTime:1', format='avfoundation', pix_fmt='uyvy422', framerate=30, s='320x240', probesize='200M')
|
|
||||||
)
|
|
||||||
|
|
||||||
audio = facetime_camera_input.audio
|
def pip_to_rtmp(url: str):
|
||||||
|
""" Capture Facetime camera and screen in macOS and stream it to facebook
|
||||||
|
"""
|
||||||
|
facetime_camera_input = (
|
||||||
|
ffmpeg
|
||||||
|
.input('FaceTime:1', format='avfoundation', pix_fmt='uyvy422', framerate=30, s='320x240', probesize='200M')
|
||||||
|
)
|
||||||
|
|
||||||
video = (
|
audio = facetime_camera_input.audio
|
||||||
ffmpeg
|
|
||||||
.header(thread_queue_size='512', vsync='2')
|
|
||||||
.input('1:1', format='avfoundation',
|
|
||||||
pix_fmt='uyvy422', framerate=30, probesize='200M')
|
|
||||||
.overlay(facetime_camera_input)
|
|
||||||
|
|
||||||
)
|
# ffmpeg in MacOS AVFoundation MUST increase the thread_queue_size in order to handle PIP
|
||||||
output = (
|
video = (
|
||||||
ffmpeg
|
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',
|
.header(thread_queue_size='512', vsync='2')
|
||||||
vcodec='libx264', preset='superfast', x264opts='keyint=15', g='30', ac='2', ar='48000', acodec="aac", audio_bitrate="128000")
|
.input('1:1', format='avfoundation',
|
||||||
)
|
pix_fmt='uyvy422', framerate=30, probesize='200M')
|
||||||
|
.overlay(facetime_camera_input)
|
||||||
|
|
||||||
output.overwrite_output().run()
|
)
|
||||||
|
output = (
|
||||||
|
ffmpeg
|
||||||
|
.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")
|
||||||
|
)
|
||||||
|
|
||||||
|
return output.overwrite_output().compile()
|
||||||
|
|
||||||
|
|
||||||
def test_fluent_equality():
|
def test_rtmp():
|
||||||
pip_to_facebook('351682605501180?s_bl=1&s_ps=1&s_sml=1&s_sw=0&s_vt=api-s&a=AbzMoYVOuxBYwxs7')
|
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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user