Tuesday, 19 June 2012

Converting flv to mp4

Recently, I had the need to convert a number of flash movies into mp4. I had some issues with the time needed for this operation, while using ffmpeg for this. A quick search revealed this tip:

http://www.learnosity.com/techblog/index.cfm/2010/12/29/Convert-FLV-to-MP4-with-ffmpeg-Howto

I recently needed to convert a lot of FLV files which were H264 encoded to MP4 so that they would play nice on my Mac Mini.
Initial attempts using ffmpeg were making it re-encode the entire video which would take ages and result in a larger file or worse quality.

The Solution

ffmpeg -i input.flv -vcodec copy -acodec copy output.mp4

The final comments included a question about converting multiple files but the answer did not fulfill my needs, because I had files inside a directory tree.

So I ended doing this to find all flv files and perform a quick conversion, overwriting existent files:

for file in $(find . -type f -iname *.flv -print); do \
ffmpeg -i $file -y -vcodec copy -acodec copy ${file%%.flv}.mp4; done


Monday, 11 June 2012

Portable random number generator

A couple of days ago, I was asked for a way to generate random numbers within a certain range (e.g. the interval [1,10]). But there was a catch: we had an Android system with ash only and no bc.

If we had bash, we could do:
echo $[ ( $RANDOM % 10 ) + 1 ]

With ash but with bc, we could go:
echo "$RANDOM % 10 + 1" | bc

Fortunately we had awk:
echo|awk "{ print $RANDOM % 10 + 1 }"