logo Debian Debian Debian-France Debian-Facile Debian-fr.org Forum-Debian.fr Debian ? Communautés logo inclusivité

Debian-facile

Bienvenue sur Debian-Facile, site d'aide pour les nouveaux utilisateurs de Debian.

Vous n'êtes pas identifié(e).

#1 08-09-2015 10:45:20

Anonyme
Invité

Un bout de script à garder sous le coude

Cela permet par l'action sur le bouton "Annuler" de Zenity de killer le programme avconv et l'encodage en cours.
Et par la même occasion de faire un deuxième script en parallèle pour stopper le travail.

Trouvé ici :


https://bbs.archlinux.org/viewtopic.php?id=147749



#/bin/bash
LA_COMMANDE | zenity --progress --width=600 --height=50 --pulsate  --auto-kill --text="Enregistrement  en cours..."
if [ $? = 1 ]; then
    echo you pressed cancel
    killall -INT -w avconv
else
    echo you did not press cancel
fi

 





cool

Par contre je ne comprend cette ligne et surtout à quoi elle sert :


if [ $? = 1 ]; then
 

Dernière modification par Anonyme (08-09-2015 10:59:00)

#2 08-09-2015 11:35:49

Thuban
aka prx
Distrib. : OpenBSD
Noyau : current
(G)UI : cwm
Inscription : 09-01-2009
Site Web

Re : Un bout de script à garder sous le coude

En fait, quand tu cliques sur "annuler", ça envoie le code de retour 1 .
La variable $? contient le code de retour de la dernière commande.

Donc ce test est là pour vérifier si l'utilisateur a appuyé sur annuler.

Hors ligne

#3 08-09-2015 15:44:58

Anonyme
Invité

Re : Un bout de script à garder sous le coude

Ok merci Thuban

Je voudrais caser ces quelques lignes dans mon script. Tu peux voir ça :


#!/bin/bash


#patrick@debian:~$ pactl list sources | grep Name:
# Name: alsa_input.pci-0000_05_01.1.analog-stereo
# Name: alsa_output.pci-0000_05_02.0.analog-surround-51.monitor
# Name: alsa_input.pci-0000_05_02.0.analog-stereo
#patrick@debian:~$


Format=(" Monitor                           6 Channels 48000Hz 16 Bits Wav" " Monitor                           2 Channels 44100Hz 16 Bits Flac" " Monitor                           2 Channels 44100Hz 16 Bits Wav" " Line                                   2 Channels 44100Hz 16 Bits Wav" " ADCD, Mocp                  2 Channels 44100Hz 16 Bits Wav" " VHS                                   2 Channels 44100Hz 16 Bits Wav")
choice=$(zenity --list --radiolist --width=750 --height=300 \
        --title "Capture" \
        --text="Sélectionner Un Choix" \
        --column="Choix" --column="Entrée                     Format" \
                FALSE           "${Format[0]}" \
                FALSE           "${Format[1]}" \
                TRUE            "${Format[2]}" \
                FALSE           "${Format[3]}" \
                FALSE           "${Format[4]}" \
                FALSE           "${Format[5]}");    
                                           

echo "choice=$choice"
if    [ "$choice" == "${Format[0]}" ]; then avconv -ac 6 -ar 48000 -f  pulse -i alsa_output.pci-0000_05_02.0.analog-surround-51.monitor  -acodec copy ~/Musique/Monitor-$(date +%F-%H-%M-%S).wav | zenity --progress --width=600 --height=50 --pulsate  --auto-kill --text="Enregistrement  en cours..."
elif  [ "$choice" == "${Format[1]}" ]; then avconv  -ac 2 -ar 44100 -f pulse -i  alsa_output.pci-0000_05_02.0.analog-surround-51.monitor -acodec  flac  -compression_level 0   ~/Musique/Monitor-$(date +%F-%H-%M-%S).flac  | zenity --progress --width=600 --height=50 --pulsate  --auto-kill --text="Enregistrement  en cours..."
elif  [ "$choice" == "${Format[2]}" ]; then avconv -ac 2 -ar 44100 -f pulse -i alsa_output.pci-0000_05_02.0.analog-surround-51.monitor -acodec pcm_s16le ~/Musique/Monitor-$(date +%F-%H-%M-%S).wav  | zenity --progress --width=600 --height=50 --pulsate  --auto-kill --text="Enregistrement  en cours..."
elif  [ "$choice" == "${Format[3]}" ]; then avconv -f alsa -ac 2 -ar 44100 -f pulse -i alsa_input.pci-0000_05_02.0.analog-stereo -acodec pcm_s16le ~/Musique/LINE-$(date +%F-%H-%M-%S).wav  | zenity --progress --width=600 --height=50 --pulsate  --auto-kill --text="Enregistrement  en cours..."
elif  [ "$choice" == "${Format[4]}" ]; then avconv -f alsa -ac 2 -ar 44100 -f pulse -i alsa_input.pci-0000_05_02.0.analog-stereo -acodec pcm_s16le ~/Musique/MOC-$(date +%F-%H-%M-%S).wav  | zenity --progress --width=600 --height=50 --pulsate  --auto-kill --text="Enregistrement  en cours..."









elif  [ "$choice" == "${Format[5]}" ]; then

# Application Qui Se Lance et Qui Doit Se Terminer Rapidement
# PID Du Dernier Programme Détaché
# Le Temps Qu'on Veut Attendre Avant De Tuer Le Programme
# Run It in Background
# Attendre...
# ...Et tuer


tvtime &                                                                                                                                                              
PID=$!
time=1s
${prog} &
sleep $time
kill $PID


avconv -f pulse -i $(pactl list sources | sed -n '/alsa.*_05_02.0.analog-stereo/s/.*: \(.*\)$/\1/p') -f video4linux2 -channel 1 -i /dev/video0 -codec:a libmp3lame -b:a 192k -codec:v libx264 -b:v 14000k  -s hd1080 -vf crop=in_w-32:in_h-14:14:4,yadif=0  -vprofile main -preset ultrafast -tune film ~/Vidéos/VHS-$(date +%F-%H-%M-%S).mkv  | zenity --progress --width=600 --height=50 --pulsate --auto-kill --text="Enregistrement  en cours..."








else
    echo "Aucun Choix, Ou Quelque Chose S'est Mal Passé -- Arrêt"
   exit 1
fi

 

#4 09-09-2015 07:32:12

Anonyme
Invité

Re : Un bout de script à garder sous le coude

En fait, ça ne fonctionne pas.

Je suis en train d'adapter la solution proposé sur ce lien :

http://bernaerts.dyndns.org/linux/331-l … -right-way

avec une seule commande, l'action cancel coupe bien le terminal et l'encodage  stoppe bien. avconv ne continue plus en arrière plan quand le terminal est fermé :

Dernière modification par Anonyme (09-09-2015 07:33:34)

#5 09-09-2015 10:35:45

Anonyme
Invité

Re : Un bout de script à garder sous le coude

Bon on doit pouvoir alléger tout ça mais je ne sais pas faire, mais en tout cas mon bidule fonctionne bien big_smile


#!/bin/bash

#patrick@debian:~$ pactl list sources | grep Name:
# Name: alsa_input.pci-0000_05_01.1.analog-stereo
# Name: alsa_output.pci-0000_05_02.0.analog-surround-51.monitor
# Name: alsa_input.pci-0000_05_02.0.analog-stereo
#patrick@debian:~$


                                           


Format=( " ADCD, Mocp " " MONITOR " )
choice=$(zenity --list --radiolist --width=750 --height=300 \
        --title "Avconv" \
        --text="Sélectionner Un Choix" \
        --column="Choix" --column="Entrée                     Format" \
                TRUE           "${Format[0]}" \
                FALSE           "${Format[1]}");




echo "choice=$choice"
if    [ "$choice" == "${Format[0]}" ]; then
(
  echo "# Enregistrement  en cours..."

 avconv -f alsa -ac 2 -ar 44100 -f pulse -i alsa_input.pci-0000_05_02.0.analog-stereo -acodec pcm_s16le ~/Musique/MOC-$(date +%F-%H-%M-%S).wav
) | zenity --title="Avconv" --progress --width=600 --height=50 --pulsate --auto-close &
# Get Zenity Brother Process Which is Parent of All Running Tasks
PID_ZENITY=$(ps -C zenity h -o pid,command | grep "Avconv" | awk '{print $1}')
PID_PARENT=$(ps -p ${PID_ZENITY} -o ppid=)
PID_CHILDREN=$(pgrep -d ',' -P ${PID_PARENT})

# loop to check that progress dialog has not been cancelled
while [ "$PID_ZENITY" != "" ]
do
  # get PID of running processes for the children
  PID_GRANDCHILDREN=$(pgrep -d ' ' -P "${PID_CHILDREN}")

  # check if zenity PID is still there (dialog box still open)
  PID_ZENITY=$(ps h -o pid -p ${PID_ZENITY})

  # sleep for 2 second
  sleep 2
done

# if some running tasks are still there, kill them
[ "${PID_GRANDCHILDREN}" != "" ] && kill -9 ${PID_GRANDCHILDREN}

fi

if    [ "$choice" == "${Format[1]}" ]; then
(
  echo "# Enregistrement  en cours..."

avconv -ac 2 -ar 44100 -f pulse -i alsa_output.pci-0000_05_02.0.analog-surround-51.monitor -acodec pcm_s16le ~/Musique/MONITOR-$(date +%F-%H-%M-%S).wav
) | zenity --title="Avconv" --progress --width=600 --height=50 --pulsate --auto-close &
# Get Zenity Brother Process Which is Parent of All Running Tasks
PID_ZENITY=$(ps -C zenity h -o pid,command | grep "Avconv" | awk '{print $1}')
PID_PARENT=$(ps -p ${PID_ZENITY} -o ppid=)
PID_CHILDREN=$(pgrep -d ',' -P ${PID_PARENT})

# loop to check that progress dialog has not been cancelled
while [ "$PID_ZENITY" != "" ]
do
  # get PID of running processes for the children
  PID_GRANDCHILDREN=$(pgrep -d ' ' -P "${PID_CHILDREN}")

  # check if zenity PID is still there (dialog box still open)
  PID_ZENITY=$(ps h -o pid -p ${PID_ZENITY})

  # sleep for 2 second
  sleep 2
done

# if some running tasks are still there, kill them
[ "${PID_GRANDCHILDREN}" != "" ] && kill -9 ${PID_GRANDCHILDREN}

















else
    echo "Aucun Choix, Ou Quelque Chose S'est Mal Passé -- Arrêt"
   exit 1
fi
 



Choix
Capture
Cancel
Fichier de capture dans le dossier et bien fini


Ha que je suis content !!!! tongue

Dernière modification par Anonyme (09-09-2015 10:39:01)

#6 09-09-2015 12:01:08

paskal
autobahn
Lieu : ailleurs
Inscription : 14-06-2011
Site Web

Re : Un bout de script à garder sous le coude

cool

I'd love to change the world
But I don't know what to do
So I'll leave it up to you...

logo-sur-fond.png

Hors ligne

#7 09-09-2015 20:52:15

Anonyme
Invité

Re : Un bout de script à garder sous le coude

Et voilà pour l'instant

1441828111.jpg

Programmes utilisant qu'Alsa
Capture audio sur écran
Numérisation VHS
Screen Recorder

Maintenant, il faut que je trouve le moyen de choisir sa cate audio par choix tongue

Dernière modification par Anonyme (01-04-2017 19:37:10)

Pied de page des forums