Wednesday, May 11, 2016

mp3split - How to split huge MP3 files in several parts

Let's say that you have to split an MP3 file in several MP3 files equally long,
for example to split an MP3 file long 60 minutes, in 6 MP3 files 10 minutes each.

To help you there is mp3split that is a script initially written by Alec Jacbson, later updated and published in github.

echo "----------------------------------------------"
duration_stamp=$(ffmpeg -i "$big" 2>&1 | grep Duration | sed 's/^.*Duration: *\([^ ,]*\),.*/\1/g')
title=$(ffmpeg -i "$big" 2>&1  | grep "title *:" | sed 's/^.*title *: *\(.*\)/\1/g')
# get minutes as a raw integer number (rounded up)
prefix=$(basename "$big" .mp3)
echo "Total audio duration =" $duration_stamp
echo "----------------------------------------------"
mins=$(echo "$duration_stamp" | sed 's/\([0-9]*\):\([0-9]*\):\([0-9]*\)\.\([0-9]*\)/\1*60+\2+\3\/60+\4\/60\/100/g' | bc -l | python -c "import math; print int(math.ceil(float(raw_input())))")
echo "Total audio duration in minutes =" $mins
echo "----------------------------------------------"
total_count=$(echo "$mins/$minutes_block"+1 | bc)
echo $total_count
while [ "$ss" -lt "$mins" ]
  zcount=$(printf "%05d" $count)
  ss_hours=$(echo "$ss/60" | bc)
  ss_mins=$(echo "$ss%60" | bc)
  ss_stamp=$(printf "%02d:%02d:00" $ss_hours $ss_mins)
  ffmpeg -i "$big" -acodec copy -t 00:$minutes_block:00 -ss $ss_stamp -metadata track="$count/$total_count" -metadata title="$title $zcount" "$prefix-$zcount.mp3" 
  echo $zcount $ss_hour $ss_mins $ss_stamp
echo "----------------------------------------------" 
echo "----------------------------------------------" 

Dependencies: python ffmpeg

How to execute: 

./ mysixtyminutesfile.mp3 10

It will produce several files like (keeping the original MP3):

Thursday, October 9, 2014

Dot dot-slash to run shell scripts

Let's say you have 2 shell scripts and you want to run them separately and manually, but the second depends on the first. Normally [1] to do this in Linux you type:


[other possible operations]


If the first script sets something for the second script you can have a surprise: the first script didn't have effects and the second one will break. How is it possible?

As well explained here:
Normally, the shell runs a command file in a subshell so that changes to the environment by such commands as cd, set, and trap are local to the command file.
This means that the effect of the first script are inside the subshell and when you come back to your previous shell, running the second script, you will not be able to access what has been set in the subshell.

To avoid this problem this is the correct way to execute the scripts

. ./first_script

[other possible operations]


Notice the dot before ./first_script. It means [2]: run the script in the current environment and then return. In this way the second script will not break, because the first (on which it depends) worked on the current environment.

A real case is when you use Apache Ant to build Java applications. When you set your ant environment in a shell and then you run the command ant to build you Java application, you will have the strange message that says "unable to locale ant", "'ant' is not recognized as an internal or external command”, or something similar. This happens when you used a first script to set your ant environment (ANT_HOME, PATH, etc.) and then you are trying to run the actual ant command, but given that the first script has been executed in a separate subshell you don't have the proper settings in your current environment.



Saturday, October 4, 2014

Tool for manipulating PDF documents: pdftk

Following this old post I want to suggest this fantastic and easy tool for manipulating PDF documents: pdftk. I used it to merge PDF files with this commands:

cd my_directory_with_pdf_files

pdftk chapter*.pdf cat output allchaptersmerged.pdf

A useful list of command is here

for example:
Split Select Pages from Multiple PDFs into a New Document
 pdftk A=one.pdf B=two.pdf cat A1-7 B1-5 A8 output combined.pdf
Join Two Files, One of Which is Encrypted (the Output is Not Encrypted)
pdftk A=secured.pdf mydoc.pdf input_pw A=foopass cat output comb.pdf
Uncompress PDF Page Streams for Editing the PDF Code in a Text Editor
 pdftk mydoc.pdf output mydoc.clear.pdf uncompress
Repair a PDF’s Corrupted XREF Table and Stream Lengths (If Possible)
 pdftk broken.pdf output fixed.pdf
Burst a Single PDF Document into Single Pages and Report its Data to doc_data.txt
    pdftk mydoc.pdf burst 

Wednesday, March 14, 2012

Thesis at Politecnico di Milano: Latex template

Here you can read a complete vademecum (written in italian) to write a thesis at Politecnico di Milano. All those instruction are provided in the AIRLab's wiki (AIRLab is the Artificial Intelligence and Robotics Laboratory of the Politecnico di Milano).

It is recommended to use LaTeX for an automated process of writing and well ordered output. It is also provided a useful template to start to set the structure of all the thesis.

To use LaTeX in a Linux system Ubuntu-like you have to install the package texlive.
So, for example, you can install it launching in a terminal the command:

sudo apt-get install texlive

Then you can start using LaTeX in two ways:

1) by command line

For example, once you have downloaded the template and you changed you directory in the folder where you extracted it, you can compile the thesis launching:

latex tesi

you will obtain a file .dvi which can be converted in .ps or .pdf by:

dvips tesi.dvi


There are many other arguments and commands to have a complete compilation of the LaTeX code: they are specified in the README.txt of the template. You can also compile your thesis using the provided script, which contains all the commands for a complete compilation of your thesis:

./ tesi

2) by an editor/compiler

Many of them are listed here.

Tuesday, April 26, 2011

How to fix the webcam for Skype in Ubuntu

There are some old problems to set the webcam for Skype in Ubuntu. The followings are two rapid methods to try to fix them.

1) First of all install cheese (to normally use your webcam). In a terminal type the command:

sudo apt-get install cheese

Then launch the program with the terminal (typing cheese) or using the menu Applications > Audio and Video. Do you see the webcam working? If not, there is something wrong (maybe with the webcam drivers, etc.) and you have to fix it first. If webcam works you can normally use cheese and you can set the correct resolution in Modify Preferences Resolution.
Then you have to modify the config.xml file:

sudo gedit ~/.Skype/name_user_skype/config.xml

Where name_user_skype is your username in Skype (like john.wayne). In this file look for the tag <video> and modify it like the following:


Where the numbers refer to the resolution you previously set in cheese. Save, exit, restart Skype and click on Try in Main menu Options Video device. Now your webcam should work properly also in normal videocalls.

Another way to fix the webcam is to launch Skype with this command (which include a library):

LD_PRELOAD=/usr/lib/libv4l/ skype

Check if the webcam works clicking on Try in Main menu Options Video device. If it doesn't work the problem is another. If it works you can set the default launcher in the menu Application in this way. Create a text file just with the command above. Rename it, copy it in /usr/share/applications/:

sudo cp /usr/share/applications/

Set execution permissions:

sudo chmod +x /usr/share/applications/

Then open the configuration file for the icon Skype in the Application menu:

sudo gedit /usr/share/applications/skype.desktop

You will see something like that:

[Desktop Entry]
Comment=Skype Internet Telephony

Modify only the Exec row in this way:


Save, exit, restart Skype using the icon in the Applitation menu and click on Try in Main menu Options Video device. Now your webcam should work properly also in normal videocalls.

How to join and split files with Ubuntu

Some rapid methods to split and/or join files in a system Ubuntu-like.

1) Commands split and cat with terminal

For example, to split the file enorme.bib in different parts each one 10000 bytes sized and named partaa, partab, partac, ..., you can launch this command

split -b 10000 enorme.bib part

Then to simply join the files in enormereborn.bib you can use:

cat part* > enormereborn.bib

For more information about this commands typ:

man split
man cat

in a terminal.

2) If you don't want to use command and terminal but you like graphical approaches, you can use HJSplit downloadable here. After you downloaded and extracted hjsplitlx.tar.gz you can enter the folder hjsplitlx and simply double click on hjsplit, so you will have a very easy interface to join/split everything.

3) Alternatively you can use FFSJ downloadable here only as EXE for Windows. So after the download of FFSJ.exe you can use wine to execute it (look here about how to install and use wine), simply launching:

wine FFSJ.exe

4) If you downloaded some files name like bigFile.001, bigFile.002, etc., you can also join them by simply using a compressing tool like that one preinstalled in Ubuntu systems, right clicking on the first file bigFile.001 and then chosing Extract here. Then the program will make the join automatically looking for other parts in the same folder.

Monday, November 15, 2010

Project APOCRYPHA: complete collection in italian/english

[versione ITALIANA di questo post]

After several months I started this project concluding a "first step": saving and sorting hundreds of apocryphal texts.

Why this interest? First of all because of curiosity to the ancient mysteries of Christianity that are not the "usual" mysteries, as they refer the origin of a religious movement spread all over the world and a they also refer to a spiritual and cultural revolution took place 2000 years ago and beyond. Then, given the availability of free downloadable texts, I got the "collector mania" and I started the collection of apocryphal gospels downloadable online. I also noticed that many people ignore the fact that the Apocrypha are hundreds and they are very important from the perspective of literary history and many stories told in them are also funny. These people, also if they would be interested, give up easily in the search for these texts, because this is likely to get lost in an ocean of information.
So: why not gather all the apocryphal text available online (with relative information) and then redistribute them all in a tidy package?

I divided the original package in these packages (only in Italian).
I highly recommend to first download the package (156 KB) containing the index and introduction to the collection. You can then download the rest interested packages.
Links are here (from Microsoft OneDrive, to download just click on one of the following links, you will see the file inside a OneDrive window, then double click on the file or right-click on it and select "Download"/"Scarica"): [156 KB]
LIBRI [4,65 MB]
Documentazione generale [5,64 MB]

I wrote that the project is "started" because my job is only a small percentage of the whole (just take a look to the section called DOCUMENTI NON CATALOGATI [not cataloged documents]). There are many other points to be completed (as indicated in the file INTRODUZIONE.doc). So I'm at your disposal for suggestions, changes, corrections, insights, updates, etc.

[If you have problems with links please send me a mail or put a comment down here. Thanks.]