From ca31154cef511206991c8abcf472d71fbf9abdc2 Mon Sep 17 00:00:00 2001 From: Linus Date: Tue, 16 Jul 2019 22:47:39 +1200 Subject: [PATCH] Added Facebook Live Test case --- ffmpeg/_ffmpeg.py | 1 - ffmpeg/_run.py | 5 +--- ffmpeg/nodes.py | 1 - ffmpeg/tests/test_facebook.py | 45 +++++++++++++++++++++++++++++++++++ ffmpeg/tests/test_ffmpeg.py | 4 ---- 5 files changed, 46 insertions(+), 10 deletions(-) create mode 100644 ffmpeg/tests/test_facebook.py diff --git a/ffmpeg/_ffmpeg.py b/ffmpeg/_ffmpeg.py index 2cbcf86..19ac7f6 100644 --- a/ffmpeg/_ffmpeg.py +++ b/ffmpeg/_ffmpeg.py @@ -44,7 +44,6 @@ def header(*args, **kwargs): """Add extra header command-line argument(s), e.g. ``-re``. """ stream = None - print("in header: {}, {}, {}".format(repr(stream), args, kwargs)) return HeaderNode(name=header.__name__, args=args, kwargs=kwargs).stream() diff --git a/ffmpeg/_run.py b/ffmpeg/_run.py index a6f08de..8dfffc8 100644 --- a/ffmpeg/_run.py +++ b/ffmpeg/_run.py @@ -69,6 +69,7 @@ def _format_output_stream_name(stream_name_map, edge): def _get_filter_spec(node, outgoing_edge_map, stream_name_map): incoming_edges = node.incoming_edges outgoing_edges = get_outgoing_edges(node, outgoing_edge_map) + inputs = [ _format_input_stream_name(stream_name_map, edge) for edge in incoming_edges ] @@ -110,8 +111,6 @@ def _get_filter_arg(filter_nodes, outgoing_edge_maps, stream_name_map): def _get_header_args(node): kwargs = copy.copy(node.kwargs) args = [] - print(node.args) - print(node.kwargs) for arg in node.args: args += arg args += convert_kwargs_to_cmd_line_args(kwargs) @@ -131,7 +130,6 @@ def _get_output_args(node, stream_name_map): raise ValueError('Output node {} has no mapped streams'.format(node)) for edge in node.incoming_edges: - # edge = node.incoming_edges[0] stream_name = _format_input_stream_name( stream_name_map, edge, is_final_arg=True ) @@ -167,7 +165,6 @@ def get_args(stream_spec, overwrite_output=False): sorted_nodes, outgoing_edge_maps = topo_sort(nodes) header_nodes = [node for node in sorted_nodes if isinstance(node, HeaderNode)] - print('{}'.format(repr(header_nodes))) input_nodes = [node for node in sorted_nodes if isinstance(node, InputNode)] output_nodes = [node for node in sorted_nodes if isinstance(node, OutputNode)] global_nodes = [node for node in sorted_nodes if isinstance(node, GlobalNode)] diff --git a/ffmpeg/nodes.py b/ffmpeg/nodes.py index 7a23814..b7c3899 100644 --- a/ffmpeg/nodes.py +++ b/ffmpeg/nodes.py @@ -198,7 +198,6 @@ class Node(KwargReprNode): kwargs={}, ): stream_map = get_stream_map(stream_spec) - print('{}'.format(stream_map)) self.__check_input_len(stream_map, min_inputs, max_inputs) self.__check_input_types(stream_map, incoming_stream_types) incoming_edge_map = self.__get_incoming_edge_map(stream_map) diff --git a/ffmpeg/tests/test_facebook.py b/ffmpeg/tests/test_facebook.py new file mode 100644 index 0000000..83c3d17 --- /dev/null +++ b/ffmpeg/tests/test_facebook.py @@ -0,0 +1,45 @@ +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 + +try: + import mock # python 2 +except ImportError: + 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 + + video = ( + ffmpeg + .header(thread_queue_size='512', vsync='2') + .input('1:1', format='avfoundation', + pix_fmt='uyvy422', framerate=30, probesize='200M') + .overlay(facetime_camera_input) + + ) + 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.overwrite_output().run() + + +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') diff --git a/ffmpeg/tests/test_ffmpeg.py b/ffmpeg/tests/test_ffmpeg.py index 58c2dd2..90b0c3e 100644 --- a/ffmpeg/tests/test_ffmpeg.py +++ b/ffmpeg/tests/test_ffmpeg.py @@ -137,10 +137,6 @@ def test_global_args(): def test_header_args(): - # header = ffmpeg.header('-re', '-s', thread_queue_size=512) - - # print('in test: {}'.format(repr(header))) - out_file = ( ffmpeg.header(thread_queue_size='512') .input("input.mp4")