scriptshell
Table des matières
Automatisation de copie de fichiers depuis une liste
- cop.sh
#!/bin/bash OUTPUT_DIR="/media/bvandepo/25228E1E7D338845/films/" INPUT_FILENAME="listepouralain.txt" #fichier qui contient une liste de dossier/fichier entouré de ' old_IFS=$IFS # sauvegarde de l'ancien séparateur de champ IFS=$'\n' #le séparateur par defaut (espace) ne va pas car les noms de fichiers listés peuvent en contenir mais doivent être traités en une seule fois #on règle un nouveau séparateur de champ, le caractère fin de ligne mkdir -p ${OUTPUT_DIR} while read line #for each line of list do if [ ! -z "${line}" ]; #avoid processing empty lines then echo processing ${line} #supprime le premier caractère ' et les 2 derniers caracteres ' et \r filename=${line:1:$((${#line}-3))} echo processing ${filename} #cp "${filename}" "${OUTPUT_DIR}" rsync -av "${filename}" "${OUTPUT_DIR}" fi done < $INPUT_FILENAME IFS=$old_IFS # rétablissement du séparateur de champ par défaut
Génération de pdf à partir de office impress
- createpdf.sh
#!/bin/bash #B. Vandeportaele 2018 OUTPUT_DIR="./pdf/" OUTPUT_FILENAME=cours_comm #check that soffice is not already run SOFFICE_RUNNING=$(pstree | grep soffice) if [ ! -z "$SOFFICE_RUNNING" ]; then echo soffice have to be closed before lauching this script! echo save your data and try pkill soffice exit -1 fi #create output directory mkdir -p ${OUTPUT_DIR} #generate list and convert files to pdf if required FILE_LIST="" while read line #for each line of list do echo processing ${line} if [ ! -z "${line}" ]; #avoid processing empty lines then OFFICE_FILE=${line} PDF_FILE="${OFFICE_FILE/".odp"/".pdf"}" PDF_FILE_WITH_FOLDER="${OUTPUT_DIR}${PDF_FILE}" # test if the office file is newer than the pdf, it works also if the pdf file is not existing if [ ${OFFICE_FILE} -nt ${PDF_FILE_WITH_FOLDER} ] then echo "this file has changed, converting it to pdf: ${OFFICE_FILE} -> ${PDF_FILE_WITH_FOLDER}" rm ${PDF_FILE_WITH_FOLDER} #convert each individual file to pdf echo "soffice --convert-to pdf --outdir ${OUTPUT_DIR} ${OFFICE_FILE}" soffice --convert-to pdf --outdir ${OUTPUT_DIR} ${OFFICE_FILE} else echo "this file has not changed, keeping the previous pdf: ${OFFICE_FILE} -> ${PDF_FILE_WITH_FOLDER}" fi #add to the list of file in variable and subsitute odp with pdf FILE_LIST="${FILE_LIST} ${OUTPUT_DIR}${line/".odp"/".pdf"}" fi done < listoffilestoconcatenate.txt #I'm obliged to use while .... in that order so the scope of ${FILE_LIST} is not only local inside the loop echo list of files: ${FILE_LIST} #concatenate the files to a single one gs -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=${OUTPUT_DIR}${OUTPUT_FILENAME}.pdf -dBATCH ${FILE_LIST} #count the number of pages in the concatened file # https://stackoverflow.com/questions/1672580/get-number-of-pages-in-a-pdf-using-a-cmd-batch-file NUMBEROFPAGES=$(pdfinfo "${OUTPUT_DIR}${OUTPUT_FILENAME}.pdf" | grep Pages | sed 's/[^0-9]*//') echo $NUMBEROFPAGES pages found #set the right number of pages to generate in numbers.tex from the generic numbers.in.tex file sed "s/NUMBEROFPAGESTOGENERATE/$NUMBEROFPAGES/g" <numbers.in.tex >${OUTPUT_DIR}numbers.tex cat ${OUTPUT_DIR}numbers.tex #compute the pdf for pages numbers pdflatex -output-directory ${OUTPUT_DIR} ${OUTPUT_DIR}numbers.tex #merge the pdf containing the content and the pdf containing the page numbers # http://cazencott.info/index.php/post/2015/04/30/Numbering-PDF-Pages # sudo apt install pdftk if false then #split files to individual pages pdftk ${OUTPUT_DIR}numbers.pdf burst output ${OUTPUT_DIR}number_%03d.pdf pdftk ${OUTPUT_DIR}${OUTPUT_FILENAME}.pdf burst output ${OUTPUT_DIR}page_%03d.pdf for i in $(seq -f %03g 1 $NUMBEROFPAGES) ; do pdftk ${OUTPUT_DIR}page_$i.pdf stamp ${OUTPUT_DIR}number_$i.pdf ${OUTPUT_DIR}output new_$i.pdf ; done pdftk ${OUTPUT_DIR}new_???.pdf output ${OUTPUT_DIR}${OUTPUT_FILENAME}_numbered.pdf else #direct method dealing with the 2 files without merging individual pages pdftk ${OUTPUT_DIR}${OUTPUT_FILENAME}.pdf multistamp ${OUTPUT_DIR}numbers.pdf output ${OUTPUT_DIR}${OUTPUT_FILENAME}_numbered.pdf fi #generate the 6 slides per page for printing pdfnup --nup 2x3 --no-landscape -o ${OUTPUT_DIR}${OUTPUT_FILENAME}_numbered_six.pdf ${OUTPUT_DIR}${OUTPUT_FILENAME}_numbered.pdf #add annexes if required....
Concaténation de vidéos GOPRO
Mise cote à cote de 2 vidéos
- accolevideo.sh
#!/bin/bash #cutting the video INFILE1="../2017_Photos/2017_11_14_gensac_parapente/VID_20171114_135427.3gp" START_TIME1="0:39" #de 39 à 53 =14 secondes #retournement à 43, soit apres 4 secondes INFILE2="../2017_Photos/2017_11_14_gensac_parapente/GOPR0844.MP4" #https://www.ffmpeg.org/doxygen/0.7/parseutils_8c-source.html#l00487 #d'après 00487 int av_parse_time(int64_t *timeval, const char *datestr, int duration) #la partie fractionnaire de secondes est exprimée en us START_TIME2="2:18.500000" #retournement à 2:23 DURATION="0:00:14" TMPDIR="/tmp/myvideo/" rm -rf $TMPDIR mkir -p $TMPDIR #INTERMEDIATEFILE="cutted.mkv" #OUTFILE="res.mkv" #ffmpeg -i $INFILE -ss $START_TIME -t $DURATION -c copy $INTERMEDIATEFILE #converting the video to images 1 mkdir -p $TMPDIR/imgs1 avconv -i $INFILE1 -r 30 -f image2 -ss $START_TIME1 -t $DURATION $TMPDIR/imgs1/im-%06d.bmp #converting the video to images 2 mkdir -p $TMPDIR/imgs2 avconv -i $INFILE2 -r 30 -f image2 -ss $START_TIME2 -t $DURATION $TMPDIR/imgs2/im-%06d.bmp #concatenate the images mkdir -p $TMPDIR/imgs3 rm $TMPDIR/list #ls -c1 *.pgm | sort >>list #genere la liste ordonnée des fichiers pgm du dossier dans un fichier list find $TMPDIR/imgs1 -type f -printf "%f\n" | grep bmp | sort >>$TMPDIR/list #pour chaque ligne de list cat $TMPDIR/list | while read line do echo ${line} convert $TMPDIR/imgs1/${line} $TMPDIR/imgs2/${line} +append $TMPDIR/imgs3/${line} rm $TMPDIR/imgs1/${line} rm $TMPDIR/imgs2/${line} done #extrait la piste audio rm $TMPDIR/audio.mp3 avconv -i $INFILE1 -ss $START_TIME1 -t $DURATION $TMPDIR/audio.mp3 #generate the movie file from file with name pattern: out-img0001.png avconv -i $TMPDIR/audio.mp3 -i $TMPDIR/imgs3/im-%06d.bmp -f avi -vcodec mpeg4 -b 4000k -g 300 -bf 2 -y ./video.mpg
Version fonctionnelle qui génère une liste de fichier texte avant de concaténer
- concat2.sh
#!/bin/bash #B. Vandeportaele #script to concatenate video files from the GOPRO using ffmpeg #if the filenames are not in sequence as generated by the script, a list of file can be used. The file containing the list should be #made of lines such as: file 'GOPR0650.MP4' #ffmpeg -f concat -safe 0 -i file-list_to_concatenate.txt -ss 1:16 -t 30:00 -c copy GOPR0650_complete_cut.MP4 NUMBER=0711 START_TIME="0:19" DURATION="10:00:00" rm ./filelisttoconcatenate.txt #begin with a list of 1 file echo "file './GOPR$NUMBER.MP4'" >> filelisttoconcatenate.txt #loop for 10 next files and try to detect if the file exists then add it to the list for I in `seq -w 1 10`; do file="GP$I$NUMBER.MP4" if [ -f "$file" ] then echo "$file found." # LIST="$LIST|$file" echo "file ./'$file'" >> filelisttoconcatenate.txt else echo "$file not found." fi done echo " " >> filelisttoconcatenate.txt #generate an output file name OUTFILE="GOPR${NUMBER}_completecut.MP4" #generate the command COMMAND="ffmpeg -f concat -safe 0 -i filelisttoconcatenate.txt -ss $START_TIME -t $DURATION -c copy $OUTFILE" echo "Do you want to execute the following command (y/n):" echo $COMMAND read line if [ "$line" == "y" ]; then #execute the command in the variable eval "$COMMAND" fi
Version qui ne fonctionne pas toujours
- concat.sh
#!/bin/bash #B. Vandeportaele #script to concatenate video files from the GOPRO using ffmpeg #if the filenames are not in sequence as generated by the script, a list of file can be used. The file containing the list should be #made of lines such as: file 'GOPR0650.MP4' #ffmpeg -f concat -safe 0 -i file-list_to_concatenate.txt -ss 1:16 -t 30:00 -c copy GOPR0650_complete_cut.MP4 NUMBER=0711 START_TIME="0:19" DURATION="2:0:00" #construct a string that contains all the necessary file names #LIST="\"concat:GOPR$NUMBER.MP4|GP01$NUMBER.MP4\"" #LIST="GOPR$NUMBER.MP4|GP01$NUMBER.MP4|GP02$NUMBER.MP4|GP03$NUMBER.MP4|GP04$NUMBER.MP4|GP05$NUMBER.MP4|GP06$NUMBER.MP4|GP07$NUMBER.MP4|GP08$NUMBER.MP4|GP09$NUMBER.MP4" #begin with a list of 1 file LIST="\"concat:GOPR$NUMBER.MP4" echo $LIST #loop for 10 next files and try to detect if the file exists then add it to the list for I in `seq -w 1 10`; do file="GP$I$NUMBER.MP4" if [ -f "$file" ] then echo "$file found." LIST="$LIST|$file" else echo "$file not found." fi done #close the list LIST="$LIST\"" echo $LIST #on peut aussi éviter de passer par une liste de fichier et utiliser # -i "concat:input1.mpg|input2.mpg|input3.mpg" #generate an output file name OUTFILE="GOPR${NUMBER}_completecut.MP4" #generate the command COMMAND="ffmpeg -i $LIST -ss $START_TIME -t $DURATION -c copy $OUTFILE" echo "Do you want to execute the following command (y/n):" echo $COMMAND read line if [ "$line" == "y" ]; then #execute the command in the variable eval "$COMMAND" fi
Renommage de fichier
- chext.sh
#!/bin/bash #exemple d'utilisation pour renommer tous les .mp4 en .avi: chext mp4 avi for file in *.$1 do #\" pour gérer les fichiers avec des espaces chaine=`echo "mv \"$file\" \"${file/$1/$2}\" "` #affichage echo $chaine #execution eval $chaine done
Effacement automatique de plusieurs fichiers .html et dossiers _fichiers créés par firefox
- rmhtml.sh
#!/bin/sh for fich in `ls *.html` do rep=`echo "$fich" | cut -d'.' -f 1 ` #echo $rep rep2=`echo "$rep""_fichiers"` #echo $rep2 #echo rm -r "$rep2" #echo "rm $fich" rm -r $rep2 rm $fich done
Gestion de liens dynamiques
- cre.sh
#/bin/bash #(ne pas utiliser sh car l'IFS \n ne fonctionne pas!!!! ) #Auteur Bertrand VANDEPORTAELE 2013 #Ce script permet de construire une arborescence dans un dossier vide (définit par $DEST) dans laquelle des liens dynamiques #vont pointer vers des fichiers/dossiers respectant la même arborescence mais sur plusieurs disques distincts #Utile pour un média center avec plusieurs disques, on peut ainsi lister dans une même dossier le contenu des différents disque et naviguer comme s'il n'y avait qu'un disque #exemple: 2 disques durs /media/HD1 et /media/HD2, contenant chacun les dossiers hd et 3D #on cree sur ~/films/ les dossiers hd et 3D #puis on crée des liens symboliques de tous les fichiers /media/HD1/hd et /media/HD2/hd vers ~/films/hd # et de tous les fichiers /media/HD1/sd et /media/HD2/sd vers ~/films/sd #pour cela régler #DEST="~/films/" #LISTCAT=$'hd\nsd\n' #LISTDRV=$'/media/HD1\n/media/HD2\n' # il faut que la partition destination supporte les liens dynamiques #http://www.commentcamarche.net/faq/5027-comment-lire-un-fichier-ligne-par-ligne #http://bash.cyberciti.biz/guide/$IFS old_IFS=$IFS # sauvegarde de l'ancien séparateur de champ IFS=$'\n' #le séparateur par defaut (espace) ne va pas car les noms de fichiers listés peuvent en contenir mais doivent être traités en une seule fois #on règle un nouveau séparateur de champ, le caractère fin de ligne #emplacement pour stocker les liens dynamiques, doit pointer sur un dossier vide car on va y effacer tout les contenus des #dossiers catégories DEST="/home/bvdp/films/" #liste de noms de dossiers correspondant à des catégories #il faut le $ au début pour que le \n soit interpreté correctement comme un IFS LISTCAT=$'hd\nsd\n3D\nseries\n3Dsound\n' #liste de noms de dossiers ou rechercher les catégories LISTDRV=$'/media/HD2TO/\n/media/HD2TO2/\n/media/HD2TO3/\n/media/HD2TO4/\n/media/HD3TO1/\n/media/JY500GO\n' echo destination=$DEST #-------------------------------------------------------- #-------------------------------------------------------- #-------------------------------------------------------- #-------suppression des fichiers existants et création des dossiers si besoin--------------- rm $DEST/lnscript for i in $LISTCAT do echo $i rm $DEST/$i/* mkdir $DEST/$i #au cas ou ils n'existeraient pas done #-------------------------------------------------------- for i in $LISTCAT do echo $i #echo "next" for j in $LISTDRV do echo $j #echo "noxt" for fich in `ls $j/$i` do echo "ln -s \"$j/$i/$fich\" \"$DEST/$i/$fich\"" >>$DEST/lnscript echo $fich done done done #-------------------------------------------------------- bash $DEST/lnscript #éxecute le script de génération des liens symboliques IFS=$old_IFS # rétablissement du séparateur de champ par défaut
- test.vhdl
-------------------------------------------------------------------------------- library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; entity vgaB1 is port(clk50_in : in std_logic; x : out std_logic_vector(9 downto 0); y : out std_logic_vector(8 downto 0); red_in : in std_logic; green_in : in std_logic; blue_in : in std_logic; red_out : out std_logic; green_out : out std_logic; blue_out : out std_logic; hs_out : out std_logic; vs_out : out std_logic; clk25_out : out std_logic; inside_x : out std_logic; inside_y : out std_logic); end vgaB1; architecture behavioral of vgaB1 is signal clk25 : std_logic; signal hcounter : integer range 0 to 800; signal vcounter : integer range 0 to 521; signal color: std_logic_vector(2 downto 0); signal colorb: std_logic_vector(2 downto 0); begin -- generate a 25Mhz clock process (clk50_in) begin if clk50_in'event and clk50_in='1' then clk25 <= not clk25; end if; end process; clk25_out<=clk25; --------------------------------------------------- p2: process (clk25, hcounter, vcounter) variable x: integer range 0 to 639; variable y: integer range 0 to 479; begin -- hcounter counts from 0 to 799 -- vcounter counts from 0 to 520 -- x coordinate: 0 - 639 (x = hcounter - 144, i.e., hcounter -Tpw-Tbp) -- y coordinate: 0 - 479 (y = vcounter - 31, i.e., vcounter-Tpw-Tbp) x := hcounter - 144; y := vcounter - 31; if clk25'event and clk25 = '1' then -- To draw a pixel in (x0, y0), simply test if the ray trace to it -- and set its color to any value between 1 to 7. The following example simply sets -- the whole display area to a single-color wash, which is changed every one -- second. if x < 640 and y < 480 then -- colorbv := x mod 64; --il faut une puissance de 2 forcement pour le modulo colorbv := x /64; case colorbv is when 0 => colorb<= "000"; when 1 => colorb<= "001"; when 2 => colorb<= "010"; when 3 => colorb<= "011"; when 4 => colorb<= "100"; when 5 => colorb<= "101"; when 6 => colorb<= "110"; when others => colorb<= "111"; end case; -- -- with colorbv select -- colorb<= "000" when 0, -- "001" when 1, -- "010" when 2, -- "011" when 3, -- "100" when 4, -- "101" when 5, -- "110" when 6, -- "111" when others; red_out <= colorb(0); green_out <= colorb(1); blue_out <= colorb(2); else -- if not traced, set it to "black" color red_out <= '0'; green_out <= '0'; blue_out <= '0'; end if; -- Here is the timing for horizontal synchronization. -- (Refer to p. 24, Xilinx, Spartan-3 Starter Kit Board User Guide) -- Pulse width: Tpw = 96 cycles @ 25 MHz -- Back porch: Tbp = 48 cycles -- Display time: Tdisp = 640 cycles -- Front porch: Tfp = 16 cycles -- Sync pulse time (total cycles) Ts = 800 cycles if hcounter > 0 and hcounter < 97 then hs_out <= '0'; else hs_out <= '1'; end if; -- Here is the timing for vertical synchronization. -- (Refer to p. 24, Xilinx, Spartan-3 Starter Kit Board User Guide) -- Pulse width: Tpw = 1600 cycles (2 lines) @ 25 MHz -- Back porch: Tbp = 23200 cycles (29 lines) -- Display time: Tdisp = 38400 cycles (480 lines) -- Front porch: Tfp = 8000 cycles (10 lines) -- Sync pulse time (total cycles) Ts = 416800 cycles (521 lines) if vcounter > 0 and vcounter < 3 then vs_out <= '0'; else vs_out <= '1'; end if; -- horizontal counts from 0 to 799 hcounter <= hcounter+1; if hcounter = 800 then vcounter <= vcounter+1; hcounter <= 0; end if; -- vertical counts from 0 to 519 if vcounter = 521 then vcounter <= 0; end if; end if; end process; end behavioral;
scriptshell.txt · Dernière modification : 2021/02/19 20:20 de 127.0.0.1