로그인

  • 목록
  • 아래로
  • 위로
  • 쓰기
  • 검색

정보&강의 Live pro 커스텀 API 파이썬 소스코드

첨부 46


2년전, 라이브 프로의 통신 소켓을 분석해 네트워크 소켓 통신을 통해 커스텀 api를 제작하였다.

상당히 많은 분들이 관심을 가지고 공부하는 용도로 생각하시는 것 같은데, 파일 생성을 통해 단일 파일로 만든 소스를 원하시는 분이 계셔서 공개하기로 했다.

 

시간이 지나서 오랜만에 찾아봤는데, 이런건 만들 때는 힘든데 시간이 지나면 컴퓨터의 어느 구석진 폴더에서 사장되어버리는 경우가 있다.

 

지금 라이브 프로에도 적용되는지는 모르겠으나, 공부하실 분들에게 참고가 되면 좋겠다.

 

#! /usr/bin/python
# -*- coding: utf-8 -*-

import socket
from datetime import datetime
import sys, re

# 실행 인자값
HOST = sys.argv[1]
PORT = 1000
BUFSIZE = 1024
ADDR = (HOST,PORT)
argv_command = sys.argv[2]
active_cam = ""


# Socket command value
input_1ch = b"<T000575020000007c>"
input_2ch = b"<T008b750200010003>"
input_3ch = b"<T009d750200020016>"
input_4ch = b"<T00ad750200030027>"

output_hdmi_1ch = b""
output_hdmi_2ch = b""
output_hdmi_3ch = b""
output_hdmi_4ch = b""
output_hdmi_pvw = b"<T00317622010000ca>"
output_hdmi_pgm = b"<T00e076220101007a>"

output_usb_pvw = b"<T008b762200000023>"
output_usb_pgm = b"<T00d9762200010072>"

input_sound_afv = b"<T002a810c000000b7>"
input_sound_line = b"<T005d810c000100eb>"
input_sound_1ch = b"<T00a4810c00020033>"
input_sound_2ch = b"<T00ed810c0003007d>"
input_sound_3ch = b"<T0006810c00040097>"
input_sound_4ch = b"<T0017810c000500a9>"

test_pattern_hdmi_color_bar = b"<T00ae7d000101002d>"
test_pattern_hdmi_solid_color = b"<T00887d0200010008>"


# 인자값을 명령어로 변환

if (argv_command == "input_1ch"):
    target = input_1ch
    active_cam = "1"
elif (argv_command == "input_2ch"):
    target = input_2ch
    active_cam = "2"
elif (argv_command == "input_3ch"):
    target = input_3ch
    active_cam = "3"
elif (argv_command == "input_4ch"):
    target = input_4ch
    active_cam = "4"
elif (argv_command == "output_hdmi_pvw"):
    target = output_hdmi_pvw
elif (argv_command == "output_hdmi_pgm"):
    target = output_hdmi_pgm
elif (argv_command == "output_usb_pvw"):
    target = output_usb_pvw
elif (argv_command == "output_usb_pgm"):
    target = output_usb_pgm
elif (argv_command == "input_sound_afv"):
    target = input_sound_afv
elif (argv_command == "input_sound_line_in"):
    target = input_sound_line
elif (argv_command == "input_sound_1ch"):
    target = input_sound_1ch
elif (argv_command == "input_sound_2ch"):
    target = input_sound_2ch
elif (argv_command == "input_sound_3ch"):
    target = input_sound_3ch
elif (argv_command == "input_sound_4ch"):
    target = input_sound_4ch
elif (argv_command == "test_pattern_hdmi_color_bar"):
    target = test_pattern_hdmi_color_bar
elif (argv_command == "test_pattern_hdmi_solid_color"):
    target = test_pattern_hdmi_solid_color
else :
    target = ""

def sentTolivepro(command):
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)# 서버에 접속하기 위한 소켓을 생성한다.
    try:
        s.sendto(command, (HOST,PORT))
    except  Exception as e:
        print(f'error : {ADDR} {e}')

sentTolivepro(target)



if active_cam and sys.argv[3]:
    # tally 시스템 - 구현방식
    # html 파일의 javascript activeCam 변수를 액티브 카메라 값을 수정한다.

    text_file_path = f'{sys.argv[3]}'
    new_text_content = ''

    target_word = 'var\sactiveCam\s=\s\"\d\"'

    new_word = f'var activeCam = "{active_cam}";'

    with open(text_file_path,'r', encoding='UTF-8') as f:
        lines = f.readlines()
        
        for i, l in enumerate(lines):
            new_string = re.sub(target_word, new_word, l)

            if new_string:
                new_text_content += new_string
            else:
                new_text_content += l
                    
    with open(text_file_path,'w', encoding='UTF-8') as f:
        f.write(new_text_content)



# pyinstaller -F --noconsole -w --icon=icon.ico --clean .\livepro_api.py

 

해당 소스에는 Live pro L1의 패킷 명령어가 포함되어 있고, 정리되어 있다.

또, tally 시스템을 구현하고자 별도 자바스크립트와 연동되는 작업도 했었는데 이건 그냥 참고만 하시기 바란다.

 


이런 글도 찾아보세요!

공유

facebooktwitterpinterestbandkakao story
퍼머링크

댓글 0

권한이 없습니다. 로그인

신고

"님의 댓글"

이 댓글을 신고 하시겠습니까?

삭제

"님의 댓글"

이 댓글을 삭제하시겠습니까?