Subscribe to Updates
Get the latest creative news from FooBar about art, design and business.
Author: Ranveer Kumar
Python 3 PYQT5 FFMPEG Script to Build Live Audio Streaming Server Using RTMP Protocol in Command Line from fbs_runtime.application_context.PyQt5 import ApplicationContextfrom PyQt5.QtWidgets import QWidget, QPushButton, QVBoxLayout, QLabel, \ QSlider, QHBoxLayout, QComboBox, QLineEditfrom PyQt5.QtCore import Qt import sysimport subprocessfrom threading import Timer class FFMPEG: def __init__(self): self.device_cmd = [‘ffmpeg’, ‘-list_devices’, ‘true’, ‘-f’, ‘dshow’, ‘-i’, ‘dummy’] self.stream_cmd_base = [ ‘ffmpeg’, ‘-re’, ‘-f’, ‘lavfi’, ‘-i’, ‘color=size=640×480:rate=6:color=black’ ] self.stream_audio_option = [ ‘-ac’, ‘2’, ‘-c:a’, ‘aac’, ‘-ar’, ‘44100’, ‘-b:a’, ‘160k’ ] self.amix_cmd = [ ‘-filter_complex’, ‘amix=inputs=2:duration=longest’ ] self.dshow_cmd = [ ‘-f’, ‘dshow’, ‘-i’ ] self.rtmp_addr = ‘rtmp://global-live.mux.com:5222/app/’ self.current_stream = None def get_input_devices(self): proc = subprocess.run(self.device_cmd,…
The mobile phone has become an essential part of everyone’s life. With their smartphones at hand, people can make calls and send messages whenever and wherever they want, have access to all kinds of information, get driving directions, take photos and videos, surf the Internet, watch videos on YouTube, listen to music, play games, and so much more! However, there is one problem with these devices that bother their owners – short battery life! Over the years we have seen a lot of improvements in smartphones batteries – they’re getting bigger and bigger in capacity. Today, mobile devices have become…
Python 3 OpenCV Script to Extract Frames of MP4 Video & Save It as PNG/JPEG Images # Importing all necessary librariesimport cv2import os # Read the video from specified pathcam = cv2.VideoCapture(“video.mp4”) try:# creating a folder named dataif not os.path.exists(‘data’):os.makedirs(‘data’) # if not created then raise errorexcept OSError:print (‘Error: Creating directory of data’) # framecurrentframe = 0 while(True):# reading from frameret,frame = cam.read() if ret:# if video is still left continue creating imagesname = ‘./data/frame’ + str(currentframe) + ‘.jpg’print (‘Creating…’ + name) # writing the extracted imagescv2.imwrite(name, frame) # increasing counter so that it will# show how many frames are…
Python 3 FFMPEG Script to Build & Extract Facial Recognition From RTMP Live Streaming Video in Browser import syssys.path.append(‘/home/raiy/.local/lib/python3.7/site-packages’) # Path for import following libs import cv2import face_recognitionimport numpy as npfrom datetime import datetimeimport time def extractFaces(media_path, filename, output_path): cap = cv2.VideoCapture(media_path + filename) extracted, face_areas = [], [] process_this_frame = True num_of_captured = 0 while True: try: ret, frame = cap.read() #cv2.imshow(frame) small_frame = cv2.resize(frame, (0, 0), fx=0.25, fy=0.25) except: break rgb_small_frame = small_frame[:, :, ::-1] if process_this_frame: locations = face_recognition.face_locations(rgb_small_frame, number_of_times_to_upsample=3) # Only works when number_of_times_to_upsample = 3 captured = face_recognition.face_encodings(rgb_small_frame, locations) for i, face in enumerate(captured): top,…
Python 3 FFMPEG Script to Convert BLOB Data to RTMP Live Video Streaming in Browser Using HTML5 #! /usr/bin/env python3.6 import argparseimport loggingfrom asyncio import get_event_loop import asyncioimport socketio from aiohttp import webfrom subprocess import Popen, PIPE, DEVNULL sio = socketio.AsyncServer()logger = logging.getLogger(‘transfer-logger’)server = None class FFMPEGProcess: DEFAULT_LIFE = 6 LIFE_STEP = 3 ffmpeg = None rtmp_url = None options = None key = None def __init__(self, key: str, rtmp_url: str): self.life = self.DEFAULT_LIFE self.key = key self.rtmp_url = rtmp_url self.options = [ ‘ffmpeg’, ‘-vcodec’, ‘libvpx’, ‘-i’, ‘-‘, ‘-c:v’, ‘libx264’, ‘-preset’, ‘veryfast’, ‘-tune’, ‘zerolatency’, ‘-an’, ‘-bufsize’, ‘1000’, ‘-f’, ‘flv’, rtmp_url…
Python 3 Script to Extract All Images From PDF Document in Command Line import sys pdf = open(sys.argv[1], “rb”).read()minimum_seek = 20startfix = 0endfix = 2i = 0 formats = { “jpeg”: { “start”: b’\xff\xd8′, “end”: b’\xff\xd9′ }} filenumber = 0while True: istream = pdf.find(b’stream’, i) if istream < 0: break print(istream) iend = pdf.find(b’endstream’, istream) if iend < 0: raise Exception(“Didn’t find end of stream!”) istart = pdf.find(formats[“jpeg”][“start”], istream, istream + minimum_seek) if istart < 0: iend = pdf.find(b’endstream’, istart) data = pdf[istream:iend] datafile = open(“data%d” % filenumber, “wb”) datafile.write(data) datafile.close() i = istream + minimum_seek filenumber += 1 continue…
Python 3 Selenium Script to Convert Website URL (HTML) To PDF Document in Headless Chrome Browser from pyhtml2pdf import converter converter.convert(‘https://pypi.org’, ‘sample.pdf’)
Python 3 Steganography Script to Hide Text, Images & EXE Files Inside Another Images in Command Line
Python 3 Steganography Script to Hide Text, Images & EXE Files Inside Another Images in Command Line from treasure_image import PIRATE #if want to hide a string in example.jpg(host image)PIRATE.hide_str_treasure(image=”profile.jpg”, treasure=”JOHN WILLIAMSON ASTLE”) from treasure_image import EXPLORER #if want to extract a string from example.jpg(host image)text = EXPLORER.seek_str_treasure(image=”profile.jpg”)print(text) from treasure_image import PIRATE PIRATE.hide_img_treasure(image=”profile.jpg”, treasure=”1.png”) PIRATE.hide_file_treasure(image=”profile.jpg”, treasure=”file.exe”) from treasure_image import EXPLORER EXPLORER.seek_str_treasure(image=”profile.jpg”) EXPLORER.seek_img_treasure(image=”profile.jpg”) EXPLORER.seek_exe_treasure(image=”profile.jpg”)
Python 3 Tkinter Script to Access Live IP Camera RTSP Video Stream Using FFMPEG & OpenCV Library GUI Desktop App capture = cv2.VideoCapture(<span class=”hljs-string”>’rtsp://192.168.1.64/1′</span>) capture = cv2.VideoCapture(<span class=”hljs-string”>’rtsp://username:password@192.168.1.64/1′</span>) import cv2 #print(“Before URL”)cap = cv2.VideoCapture(‘rtsp://admin:123456@192.168.1.216/H264?ch=1&subtype=0’)#print(“After URL”) while True: #print(‘About to start the Read command’) ret, frame = cap.read() #print(‘About to show frame of Video.’) cv2.imshow(“Capturing”,frame) #print(‘Running..’) if cv2.waitKey(1) & 0xFF == ord(‘q’): break cap.release()cv2.destroyAllWindows() <span class=”hljs-keyword”>import</span> cv2 <span class=”hljs-comment”>#print(“Before URL”)</span>cap = cv2.VideoCapture(<span class=”hljs-string”>’rtsp://admin:123456@192.168.1.216/H264?ch=1&subtype=0′</span>)<span class=”hljs-comment”>#print(“After URL”)</span> <span class=”hljs-keyword”>while</span> <span class=”hljs-literal”>True</span>: <span class=”hljs-comment”>#print(‘About to start the Read command’)</span> ret, frame = cap.read() <span class=”hljs-comment”>#print(‘About to show frame of Video.’)</span> cv2.imshow(<span class=”hljs-string”>”Capturing”</span>,frame) <span class=”hljs-comment”>#print(‘Running..’)</span>…
Python 3 OpenCV Tkinter Script to Render Flickering Video in Window Using FFMPEG Library GUI Desktop App from tkinter import *from PIL import Image, ImageTkimport cv2import threading cap = cv2.VideoCapture(0) root = Tk()def videoLoop(): global root global cap vidLabel = Label(root, anchor=NW) vidLabel.pack(expand=YES, fill=BOTH) while True: ret, frame = cap.read() frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) frame = Image.fromarray(frame) frame = ImageTk.PhotoImage(frame) vidLabel.configure(image=frame) vidLabel.image = frame videoThread = threading.Thread(target=videoLoop, args=())videoThread.start()root.mainloop() from tkinter import *from PIL import Image, ImageTkimport cv2import threading cap = cv2.VideoCapture(0) root = Tk()def videoLoop(): global root global cap vidLabel = Label(root, anchor=NW) vidLabel.pack(expand=YES, fill=BOTH) while True: ret, frame =…