Commit 3387d829 authored by Diego Giovane Pasqualin's avatar Diego Giovane Pasqualin
Browse files

le-vlc-captura: le-vlc-captura.sh rewritten in python


Signed-off-by: default avatarDiego Giovane Pasqualin <dpasqualin@c3sl.ufpr.br>
parent 552d189e
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright (C) 2004-2013 Centro de Computacao Cientifica e Software Livre
# Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR
#
# This file is part of le-vlc-captura
#
# le-vlc-captura is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
# USA.
import sys
import glob
import subprocess
import re
#
# Zenity commands
#
# Main zenity window
zenity_cmd = "zenity --height=220 --width=450 --list --text='Escolha a opção de Edição de Vídeo' --radiolist --column 'Opções' --column 'Dispositivo'"
# Zenity window shown when no device is found
zenity_cmd_error = "zenity --error --text='Nenhum dispositivo de captura encontrado.'"
# Zenity window to ask the input standard for the user device
zenity_cmd_ask_vs = "zenity --height=300 --width=450 --list --text='Escolha o padrão de vídeo (caso não tenha certeza, use NTSC)' --radiolist --column 'Opções' --column 'Padrão'"
# Text options used to ask about the different video input devices
capture_card_opt1 = 'Dispositivo de captura de vídeo composto'
capture_card_opt2 = 'Dispositivo de captura S-Video'
webcam_opt1 = 'Captura de vídeo usando WEBCAM'
#
# Driver names for the input devices
#
capture_card_driver_name = "em28xx"
webcam_driver_name = "uvcvideo"
#
# Video standards
# The first element of the tuple is the usual name, and the second is then
# name as it's known by the VLC player
#
video_standards = (
('NTFS', 'NTFS'),
('Não Definido', '""'),
('Detalhado', 'ALL'),
('PAL', 'PAL'),
('PAL B/G', 'PAL_BG'),
('PAL D/k', 'PAL_DK'),
('SECAM', 'SECAM'),
('SECAM D/K', 'SECAM_DK'),
('525 LINHAS / 60Hz', '525_60'),
('525 LINHAS / 50Hz', '525_50'),
('ATSC', 'ATSC'),
('PAL/NTSC M/N', 'MN'),
('PAL/SECAM B', 'B'),
('PAL/SECAM G/H', 'GH'),
('PAL/SECAM D/K', 'DK'),
('PAL B', 'PAL_B'),
('PAL B1', 'PAL_B1'),
('PAL G', 'PAL_G'),
('PAL H', 'PAL_H'),
('PAL I', 'PAL_I'),
('PAL D', 'PAL_D'),
('PAL D1', 'PAL_D1'),
('PAL K', 'PAL_K'),
('PAL M', 'PAL_M'),
('PAL N', 'PAL_N'),
('PAL N Argentina', 'PAL_Nc'),
('PAL 60', 'PAL_60'),
('NTFS M', 'NTFS_M'),
('NTFS M do Japão', 'NTFS_M_JP'),
('NTFS 442', 'NTFS_443'),
('NTFS M da Coréia do Sul', 'NTFS_M_KR'),
('SECAM B', 'SECAM_B'),
('SECAM D', 'SECAM_D'),
('SECAM G', 'SECAM_G'),
('SECAM H', 'SECAM_H'),
('SECAM K', 'SECAM_K'),
('SECAM K1', 'SECAM_K1'),
('SECAM L', 'SECAM_L'),
('SECAM L/C', 'SECAM_LC'),
('ATSC 8-VSB', 'ATSC_8_VSC'),
('ATSC 16-VSB', 'ATSC_16_VSC')
)
#
# Functions
#
# Return true if the <driver> was detected on the <device>
def detect_driver(device, driver):
output = get_cmd_output(['v4l-info', device])
return True
return re.search(driver, output) and True or False
# Add an entry <opt> to the options on the <zenity_cmd>
# Returns <zenity_cmd> with the new option added
def add_entry_to_zenity(zenity_cmd, opt):
zenity_cmd += " FALSE '" + opt + "'"
return zenity_cmd
# Runs external command <cmd>, returning its output, without the newline
# character
def get_cmd_output(cmd):
try:
output = subprocess.check_output(cmd, shell=True)
except:
#print cmd, e
sys.exit(1)
return output.strip("\n")
# Fill and <zenity_cmd> with all video standard options available
def add_v_s_opts(zenity_cmd, options):
for opt in options:
zenity_cmd = add_entry_to_zenity(zenity_cmd, opt[0])
zenity_cmd = zenity_cmd.replace('FALSE', 'TRUE', 1)
return zenity_cmd
# Return a video standard based on the option <opt> given as argument
def get_opt_value(opt, options):
for key, value in options:
if key == opt:
return value
return None
#
# Main Program
#
capture_card = False
webcam = False
for device in glob.iglob("/dev/video*"):
if detect_driver(device, capture_card_driver_name):
zenity_cmd = add_entry_to_zenity(zenity_cmd, capture_card_opt1)
zenity_cmd = add_entry_to_zenity(zenity_cmd, capture_card_opt2)
capture_card = device
elif detect_driver(device, webcam_driver_name):
zenity_cmd = add_entry_to_zenity(zenity_cmd, webcam_opt1)
webcam = device
# If no device was detected, show an error and exit the program
if not (capture_card or webcam):
sys.exit(subprocess.call([zenity_cmd_error], shell=True))
# Mark first option as default
zenity_cmd = zenity_cmd.replace('FALSE', 'TRUE', 1)
# Interact with user
output = get_cmd_output([zenity_cmd])
# Check what the user chose
ask_for_vs = False
if output == webcam_opt1:
vlc_cmd = "vlc v4l2://" + webcam + " :input-slave=alsa://hw:0,0"
elif output == capture_card_opt1:
ask_for_vs = True
vlc_cmd = "vlc v4l2://" + capture_card + " :v4l2-standard=VS_OPT :input-slave=alsa://hw:1,0 :v4l2-input=1 :v4l2-width=640 :v4l2-height=480"
elif output == capture_card_opt2:
ask_for_vs = True
vlc_cmd = "vlc v4l2://" + capture_card + " :v4l2-standard=VS_OPT :input-slave=alsa://hw:1,0 :v4l2-input=0 :v4l2-width=640 :v4l2-height=480"
# Webcam doesn't need to specify the video input standard, but capture
# devices does.
if capture_card and ask_for_vs:
zenity_cmd_ask_vs = add_v_s_opts(zenity_cmd_ask_vs, video_standards)
output = get_cmd_output([zenity_cmd_ask_vs])
opt = get_opt_value(output, video_standards)
vlc_cmd = vlc_cmd.replace("VS_OPT", opt, 1)
# Call vlc and exit
sys.exit(subprocess.call([vlc_cmd], shell=True))
#!/bin/bash
#
# Copyright (C) 2004-2013 Centro de Computacao Cientifica e Software Livre
# Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR
#
# This file is part of le-interface
#
# le-interface is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
# USA.
ZENITYCMD="zenity --list --text='Escolha a opção de Edição de Vídeo' --radiolist --column 'Opções' --column 'Dispositivo'"
CAPTURA=""
WEBCAM=""
for dev in $(ls /dev/video*); do
if v4l-info $dev | grep -q "em28xx"; then
CAPTURA="$dev"
ZENITYCMD="$ZENITYCMD FALSE 'Dispositivo de captura de vídeo composto'"
ZENITYCMD="$ZENITYCMD FALSE 'Dispositivo de captura S-Video'"
elif v4l-info "$dev" | grep -q "uvcvideo"; then
WEBCAM="$dev"
ZENITYCMD="$ZENITYCMD FALSE 'Captura de vídeo usando WEBCAM'"
fi
done
ZENITYCMD=$(echo $ZENITYCMD | sed s/FALSE/TRUE/)
if test -z "$CAPTURA" && test -z "$WEBCAM"; then
ZENITYCMD="zenity --error --text='Nenhum dispositivo de captura encontrado.'"
else
ZENITYCMD="$ZENITYCMD --height=220 --width=450"
fi
RESP=$(eval $ZENITYCMD)
if [ "$RESP" = "Captura de vídeo usando WEBCAM" ]; then
vlc v4l2://$WEBCAM :input-slave=alsa://hw:0,0
fi
if [ "$RESP" = "Dispositivo de captura de vídeo composto" ]; then
vlc v4l2://$CAPTURA :v4l2-standard=NTSC :input-slave=alsa://hw:1,0 :v4l2-input=1 :v4l2-width=640 :v4l2-height=480
fi
if [ "$RESP" = "Dispositivo de captura S-Video" ]; then
vlc v4l2://$CAPTURA :v4l2-standard=NTSC :input-slave=alsa://hw:1,0 :v4l2-input=0 :v4l2-width=640 :v4l2-height=480
fi
...@@ -16,7 +16,7 @@ Name[lt]=VLC grotuvas ...@@ -16,7 +16,7 @@ Name[lt]=VLC grotuvas
Comment[lt]=Groti, įrašyti, siųsti daugialypės terpės kūrinius Comment[lt]=Groti, įrašyti, siųsti daugialypės terpės kūrinius
Name[ja]=VLCメディアプレイヤー Name[ja]=VLCメディアプレイヤー
Comment[ja]=マルチメディアストリームの読み込み、キャプチャー、ブロードキャスト Comment[ja]=マルチメディアストリームの読み込み、キャプチャー、ブロードキャスト
Exec=le-vlc-captura.sh Exec=le-vlc-captura.py
Icon=vlc Icon=vlc
Terminal=false Terminal=false
Type=Application Type=Application
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment