Sunday, May 19, 2013

Health Notes 04/2013

Introduction

Each month I read several articles on health and fitness. This page summarises my personal health notes from April 2013

From time to time I will upload my monthly health notes to this blog,  however given that I have a substantial backlog of health notes they will not be published in chronological order.

I am unable to provide sources for my health notes for two reasons:
  1. I don't record the original sources of the health information, just the  basic information.
  2. I want you to do some research yourself, my notes are merely designed to get you started.
Also please note that the health notes I publish here are of interest to me personally, you should always carefully check to determine if they are accurate and applicable to your own personal health circumstances.

Don't blame me if you die from this advice!
:~)



April 2013 Health Notes


You can cut the risk of heart disease by 40% simply by getting your RDA of vitamin D.
Conclusion: Ensure daily multivitamin supplement contains 100%+ of Vitamin D RDA.

An apple a day reduces bad cholesterol LDL by 40%.
Conclusion: Every day eat an apple or in smoothie.

The chemical Melatonin plays a key role in preventing weight gain, a handful of almonds will enhance your daily consumption.

A glass of Watermelon juice has been shown to reduce weight gain. The key ingredient is Citulline, which reduces blood pressure. As little a one glass per week is sufficient.
Conclusion: A carton of Watermelon juice per week should suffice.

A mere 5% drop in bodyweight can reduce ED.

Belly fat is linked to low testosterone levels, so if you can reduce your belly fat the odds are that your testosterone levels with be higher.

Avocado is rich in testosterone raising healthy fats.

Spinach is packed with iron which speeds oxygen transport to your muscles.

Beef is high in creatine which provides improved bursts of strength.

Creatine increase muscle power so you can lift more and grow more.
Creatine is naturally found in red meat.

The plant Fenugreek increases libido by 28% according to a study.

Beef steak is packed full of zinc.

Eating red meat raises your modified cholesterol, however drinking red wine at the same time results in unchanged or slightly decreased levels.

Caffeine raises your risk of glaucoma.

Eating 75g of walnuts per day results in healthier and better shaped sperm.

Sleeping for 10 minutes after learning something new helps your brain to retain it.

20 minutes of aerobic exercise immediately after learning something new results in chemicals being released that help you retain the new skill.

Eating strawberries three times per week reduces your risk of heart attack by 30%+. Strawberries are a rich source of flavonoids which dilates your arteries, which helps to clear fatty build ups.

Just 15 minutes exercise per day (e.g.walking) adds three years to a  man's life.

Dairy products such as milk are rich in vitamin D, which boosts brainpower.

Consuming coconut oil every day might stave off the effects of Alzheimer's disease, as the oil contains the fat MCTs. The brain is able to easily use MCTs as fuel, which helps you store short-term memories better.

Going to the gym before breakfast burns 30% more body fat than a post breakfast workout. If you can go to the gym before breakfast you are a better man than me!





Saturday, May 11, 2013

Converting FLAC files for your iPad


Introduction

The Free Lossless Audio Codec (FLAC) is a widely supported audio file format on many devices, but unfortunately is not supported on Apple's various iDevices such as iPads.

The key advantage of FLAC is that it is a lossless compression format, which means that you don't lose any information when converting to this format from the original recording. Many other audio formats are lossy, such as MP3, which means that smaller file sizes are achieved by discarding some less important information. 

Given that Apple devices can't play FLAC files, how to play your FLAC files on iDevices?

There are essentially two choices:
  1. Convert the FLAC files to an inferior lossy format such as MP3 or AAC
  2. Convert the FLAC files to another lossless format.
Option 1 isn't an alternative if you want to retain all of the information in the FLAC file.

Option 2 can be achieved by converting to the Apple Lossless Audio Codec (ALAC) which is supported by Apple's iDevices.

ALAC files have the extension .m4a

A free conversion tool from FLAC to ALAC is FFmpeg or its fork avconv
Here we use  avconv since that is what Ubuntu / Debian supports.

avconv -i input.flac -c:a alac output.m4a

ffmpeg -i input.flac -acodec alac -map_meta_data 0:0,s0 output.m4a

Note the ffmpeg command should all be on one line.

How do .m4a ALAC files sound?

Well to my untrained ear I prefer the ALAC file to the original FLAC file. This may simply be due to the players I have tried. The experts seem to conclude that there shouldn't be any real difference between ALAC and FLAC since they are both merely compressed, i.e. no data lost. Still I prefer the sound of ALAC files to FLAC files, but I guess this is what separates humans from computers. What makes my conclusion all the more interesting is that I have a natural anti-Apple bias.

As a general rule I keep all of my original music files in FLAC format and convert them as needed to ALAC and other formats.

The big problem with ALAC is that support for the file format centers around iDevices. My Playon!HD Mini2 Full HD Network Media Player for example, refuses to play ALAC files despite being less than a year old.


Conclusion


Despite not being a supporter of Apple or its approach to business and consumers, I have to admit I have been quietly impressed by ALAC. There is no doubt that ALAC is comparable to FLAC and performs a similar role.

In summary, ALAC is highly recommended as a lossless format for Apple's iDevices. Just remember though that ALAC support is at best patchy away from Apple devices and so doesn't have the widespread support of  FLAC.


Basic Bash Shell Script


A basic Bash Shell script would look something like:

#!/bin/bash
# This script converts FLAC files to Apple Lossless 
# Audio Codec for use on iPad etc.
# Note the main issue seems to be retaining any meta 
# data.
# Note I use avconv in place of FFmpeg since avconv is 
# a fork of FFmpeg and is supported by Ubuntu / Debian.

mkdir -pv ALAC
for f in *.flac
do 
avconv -y  -i "$f" -c:a alac "./ALAC/${f%.*}.m4a"
echo "$f finished"
done

A full Bash Shell Script can be found towards the bottom of the page.


Further Reading


How can I convert my FLAC music collection to Apple Lossless?

Audio conversion between FLAC and ALAC in Ubuntu


Bash Shell Script


#!/bin/bash
# This script converts FLAC files to Apple Lossless Audio Codec for use on iPad etc.
# Note the main issue seems to be retaining any meta data.
# Note I use avconv in place of FFmpeg since avconv is a fork of FFmpeg and is supported by Ubuntu / Debian.

mkdir -pv ALAC

for f in *.flac
do 

avconv -y  -i "$f" -c:a alac "./ALAC/${f%.*}.m4a"

echo "$f finished"
echo
echo
echo
sleep 3

done


# Further Information
# Use Heredoc example from http://tldp.org/LDP/abs/html/here-docs.html
echo <<END
For more information see:

http://en.wikipedia.org/wiki/Apple_Lossless
Wikipedia: Apple Lossless Audio Codec (ALAC)

Ubuntu FFmpeg man page
http://manpages.ubuntu.com/manpages/lucid/man1/ffmpeg.1.html
http://linux.die.net/man/1/ffmpeg

How can I convert my FLAC music collection to Apple Lossless?
http://askubuntu.com/questions/108043/how-can-i-convert-my-flac-music-collection-to-apple-lossless

See also
https://lists.ffmpeg.org/pipermail/ffmpeg-user/2011-March/000010.html
which recommends

for i in *.flac
do 
ffmpeg -i "$i"  -acodec alac -map_meta_data 0:0,s0 "`basename "$i" .flac`.m4a" 
done;

in order to keep meta data.

Free batch conversion from FLAC to Apple Lossless (ALAC)?
http://avp.stackexchange.com/questions/1139/free-batch-conversion-from-flac-to-apple-lossless-alac
recommends:

for f in *.flac
do 
ffmpeg -i "$f"  -vf "crop=((in_w/2)*2):((in_h/2)*2)" -c:a alac "${f%.flac}.m4a"
done


For informaton on HERE DOCUMENT see

Shell script put multiple line comment
http://www.cyberciti.biz/faq/bash-comment-out-multiple-line-code/


bash/shell script comment multiple lines of code 
http://viewsby.wordpress.com/2011/12/17/bashshell-script-comment-multiple-lines-of-code/

Advanced Bash-Scripting Guide: 
Chapter 19. Here Documents
http://tldp.org/LDP/abs/html/here-docs.html
A here document is a special-purpose code block. It uses a form of I/O redirection to feed a command list to an interactive program or a command, such as ftp, cat, or the ex text editor.


Block Comment in Shell script
http://www.unix.com/shell-programming-scripting/39478-block-comment-shell-script.html


END


echo "Conversions Completed!"















Friday, May 10, 2013

Command Substitution
$(command)

Introduction

Bash Command Substitution allows you to replace $(command) with the result of the command, usually in a script.

So wherever $(command) is found its output is substituted prior to interpretation by the shell.


HCSIZE=$(wc -l ~/bashrc)

or

HCSIZE=`wc -l ~/bashrc`


Note these are BackTicks / backquotes ` not single quotes '

The BackTick key is normally the top left hand key on a US English keyboard.

The above command creates a new variable $HCSIZE that is equal to the number of lines in your bashrc file.

The second (and older) version allows the backslash \ character to escape

1. Dollar symbol $
2. Backquote `
3. Another backslash \

The $(command) syntax avoids this complexity by treating all characters between the brackets literally.



BackTicks

BackTicks ` ` are a common method of Command Substitution.

Command Substitution allows you to use the results of a command in a shell script.

To use Command Substitution put the command you want to use between BackTicks.

echo "today is `date +%d-%m-%y` "
today is 27-09-10 
or alternatively
TODAY=`date +%d-%m-%y`
echo "today is $TODAY "
today is 27-09-10 



Further Reading



Beginning the Linux Command Line 2009 APress.
Chapter 14: Introduction to Bash Shell Scripting pages 319 - 351.




See Page 357 LPI Linux Certification in a Nutshell by Jeffrey Dean, O'Reilly.

See An LPI Level 1 Crash Course for more details on the above book.


Friday, May 3, 2013

Convert MKV files to MP4 files

Note the solution described here uses Linux with avconv or FFmpeg  to do the file conversion, however the converted MP4 file can be played anywhere. Since FFmpeg is also available for Windows, my Linux based solution can also be implemented within Windows. Bottom line - don't let my use of Linux spook you!


Short version

avconv -i input.mkv -vcodec copy -acodec copy output.mp4
or
ffmpeg -i input.mkv -vcodec copy -acodec copy output.mp4

which can be run on multiple files via a simple Bash Shell Script:

#!/bin/bash
#avconv --help
IFS=$'\n' 
clear
for filename in *.mkv
do
echo "$filename"
newfilename="${filename%.mkv}.mp4"
echo "${newfilename}"
avconv -i $filename -vcodec copy -acodec copy $newfilename
done


Long Version
By default many media devices will only play MP4 (MPEG-4 Part 14) files, particularly Apple devices such as iPads and iPods. Google's Android OS is much more forgiving about what media files it will play.

Ultimately it is usually possible to install another media player app onto portable media devices (e.g. Apple's iPad / iPod for example) and get around non-mp4 container format restrictions. Sometimes this approach can be inconvenient or impossible in the case of devices when there is no possibility of installing alternate media players.

The question then becomes 'How to convert your existing files (in MKV container format or an other format for that matter) into acceptable MP4 container files?'

Note that it is important to realise that MKV and MP4 are just container file formats. In the words of Wikipedia 'A container or wrapper format is a metafile format whose specification describes how different data elements and metadata coexist in a computer file.' 

Container file formats are used to store video, audio and subtitles etc. So you can have an MKV file for example that has completely different video codec, audio codec and subtitle format from an otherwise apparently identical MKV file (e.g. the video may be in H.264/AVC or mpeg2, DIVX, XVID etc or mp3 rather than AAC or FLAC in the case of audio). So the MKV and MP4 container file formats just contain a mixture of video and audio codecs with possibly some subtitles. This is why a video file with an MP4, MKV or AVI extension may play but another file with the same extension will not play.

Understanding that MP4 and MKV are just container files, essentially envelopes containing various video and audio codecs etc, is really important. Once you understand this distinction everything else follows.

It is the codecs used within the container file itself that are important, but in this case (where the MP4 container file format is supported but not MKV or AVI container file formats - for example) the problem is that only the MP4 container file is supported.

I normally create my video file collection (from conversions of DVDs and Blu-rays etc) using HandBrake. I use the High Profile preset (for a high quality conversion) and the lower quality iPod Legacy preset to view on my Google Nexus tablets (7") and Samsung Galaxy S3 mini mobiles.

Both of my chosen HandBrake presets use the H.264/AVC (MPEG-4 Part 10) video codec which is widely supported by most modern devices. Cheaper devices may use the MPEG-4 Part 2 (e.g. DIVX / XVID) or even MPEG-2 Part 2 (e.g. DVD) video format.

My default container file format is MKV since it supports virtually any video and audio codecs (see Wikipedia's discussion), unlike the more limited MP4 container file format. To convert from MKV to MP4 the simplest approach is to use FFmpeg or the fork avconv (Libav). Note that Ubuntu uses avconv (Libav), hence I do the same.

Since I already have my default MKV file in the video and audio codecs I want, all I want to do is change the container file format from MKV to MP4. So re-coding is not necessary. All we need to do is to copy the existing data in the video and audio codecs from the MKV file to the MP4 file thus:


avconv -i input.mkv -vcodec copy -acodec copy output.mp4
or
ffmpeg -i input.mkv -vcodec copy -acodec copy output.mp4


I have also developed the following basic Bash shell script to convert multiple MKV files in a directory. Not the best Bash shell script you will ever see but it works for me, so it is 'good enough'.

mkvTOmp4.sh

#!/bin/bash
#avconv --help
IFS=$'\n' 
clear
for filename in *.mkv
do
echo "$filename"
newfilename="${filename%.mkv}.mp4"
echo "${newfilename}"
avconv -i $filename -vcodec copy -acodec copy $newfilename
done

Note that the code
avconv -i $filename -vcodec copy -acodec copy $newfilename

should all be on one line, but Blogger isn't always co-operating!

I hope someone finds the above MKV to MP4 container file conversion information useful.

Further Reading

Further reading in split into two parts:
  1. Converting from MKV to MP4
  2. Bash shell script tips for multiple conversions.

1. Converting from MKV to MP4

Handbrake settings to convert MKV to MP4 while retaining the original quality notes that If you only want to change the container from MKV to MP4, you don't need to encode anything, you just change the "wrapping" around the video. This doesn't lose quality. You can swap containers easily with FFmpeg – you just have to tell it to copy the video and audio bitstreams:


ffmpeg -i input.mkv -c:v copy -c:a copy output.mp4


Convert mkv to mp4 with ffmpeg notes that

-vcodec copy -acodec copy 
and
-codec copy
or
-c copy
are identical so that

avconv -i input.mkv -c copy output.m4v

can also be used.

How to convert .mkv file into .mp4 file losslessly? has the following suggestions. Changing container without re-enconding content could not be simpler:

avconv -i input.mkv -codec copy output.mp4

It auto-detects a Matroska > MPEG4 container conversion based on input/output filenames. -codec copy tells all content should be copied as-is without re-encoding.

If format auto-detection fails, you can use the -f option before either input, output, or both. From the manual:

f fmt (input/output) forces input or output file format. The format is normally autodetected for input files and guessed from file extension for
output files, so this option is not needed in most cases.

It is worth noting: the above syntax will copy all the files' content to the new container, but some containers may not support some content. So check if your chosen container format, be it mkv, mp4 or even avi has support for all the content in your files (video type, audio type, subtitles, etc). For example, mp4 does not support soft subtitles (.str files)eeded in most cases.

If you want to transfer both the video and audio (both losslessly) and for it not to choke on subtitles then:

avconv -i input.mkv -c:v copy -c:a copy -sn output.mp4

MP4 supports the most of the common audio formats used in MKVs including MP3 and AAC. 

It is also noted that
-codec copy 
means all tracks (formally called "streams", which can be audio, video, subtitles, etc) will be losslessly copied to the new container. So it will change the container from MKV to MP4 without changing the content. 

Avidemux is also recommended for this task. It is noted that it has good GUI interface and that when converting from MKV to MP4 it is not re-encoded. The conversion is done within a minute (for a 60-min video).

sudo apt-get install avidemux

Open the mkv file in avidemux. Select safe mode if prompted. Leave the video as copy. Choose File-> Properties. Check if the audio codec is aac.

If audio codec is NOT aac, select aac(faac). Otherwise, leave it as copy. (Sometimes using this option the audio may be out of sync or distorted, in that case select aac(faac) instead.) Select mp4 for format. Select save, choose location and type a filename with .mp4 as the extension.

The Arista transcoder is also recommended as one option. You can also download various Arista presets from http://www.transcoder.org/presets/


2. Bash Shell Script Tips for Multiple Conversions

There are several things to note about the above shell script mkvTOmp4.sh
  1. IFS=$'\n' 
  2. "${filename%.mkv}.mp4"
  3. for filename in *.mkv