Github Tutorial App Shows You How to Use… Github

Github can get pretty complicated and using it can become quite daunting, especially … more

Google Glass-like Clip-On For Regular Glasses Developed by Sony

For the price of $2,000, a pair of glasses that can run apps, take pictures, … more

Micromax Takes OnePlus to Court! Android Wear Receives Lollipop – XDA TV

Android 5.0 Lollipop is available officially for the Moto 360! … more

Google Invites Selected Devs to Buy Project Tango Development Kit

Just about a month ago, the curious Project Tango development kit was … more

Welcome to XDA

Search to go directly to your device's forum

Register an account

Unlock full posting privileges

Ask a question

No registration required
Post Reply

Simple bash video convertor

OP Spec-Chum

12th April 2014, 11:37 PM   |  #1  
Spec-Chum's Avatar
OP Senior Member
Thanks Meter: 87
 
272 posts
Join Date:Joined: Mar 2013
Hi all, just thought I'd share this simple bash script I've done to make any movie file that ffmpeg can open into ChromeCast Streamable mp4:

Code:
#!/bin/bash

CODECS=$(ffprobe -v quiet "$1" -show_entries stream=codec_name | grep "codec_name" | cut -d= -f2)

V_CODEC=$(echo $CODECS | cut -d' ' -f1)
A_CODEC=$(echo $CODECS | cut -d' ' -f2)

echo "Video codec is" $V_CODEC

if [ $V_CODEC = "h264" ]; then
	echo "No video conversion needed"
	V_FLAGS="copy"
else
	echo "Converting video to h264..."
	V_FLAGS="libx264 -profile:v high -level 5 -preset superfast -crf 18 -maxrate 10M -bufsize 16M -pix_fmt yuv420p -movflags faststart"
fi

echo "Audio codec is" $A_CODEC

if [ $A_CODEC = "mp3" ] || [ $A_CODEC = "aac" ]; then
	echo "No audio conversion needed"
	echo "Copying/transcoding video and creating mp4 file..."
	eval ffmpeg -v quiet -i "$1" -c:v "$V_FLAGS" -c:a copy "$2".mp4
else
	echo "Converting audio to aac..."
	eval ffmpeg -v quiet -i "$1" -c:a pcm_s16le -f wav - | neroAacEnc -if - -ignorelength -of "$2".mpa

	echo "Copying/transcoding video and creating mp4 file..."
	eval ffmpeg -v quiet -i "$1" -i "$2".mpa -c:v "$V_FLAGS" -c:a copy -map 0:v:0 -map 1:a:0 "$2".mp4

	echo "Removing intermediate files"
	rm "$2".mpa
fi

echo "$2.mp4 created"
It's certainly nothing fancy and I know improvements could be made, it doesn't check to make sure you'd put an output file for example, but it's fine for me

I've used neroaacenc here as it's the best quality encoder for aac but this could easily be made to use fdk or plain ffmpeg aac, that'd even make the script smaller as it wouldn't need an intermediate audio file, but I wanted nero.

Usage is simple, save the script (I called it CCConv (ChromeCastConvertor)) and make it executable:
Code:
CCConv "inputfile.mkv" "outputfile"
no need to put .mp4 on the end of the output file, it'll automatically add that.

Any questions, just ask.

Thanks
Last edited by Spec-Chum; 12th April 2014 at 11:56 PM.
13th April 2014, 08:30 AM   |  #2  
paracha3's Avatar
Senior Member
Flag Jeddah
Thanks Meter: 15
 
181 posts
Join Date:Joined: Jan 2008
More
Very nice. What binaries you need to install to make this bash script run on Mac OS X?
13th April 2014, 11:26 AM   |  #3  
Spec-Chum's Avatar
OP Senior Member
Thanks Meter: 87
 
272 posts
Join Date:Joined: Mar 2013
Quote:
Originally Posted by paracha3

Very nice. What binaries you need to install to make this bash script run on Mac OS X?

Thanks buddy.

No idea if NeroAACEnc works on Mac tho, sorry.

Did you compile ffmpeg to use libfdk-aac at all? I could just rewrite the script to use that too.

What's the output of typing 'ffmpeg' with no parameters?
13th April 2014, 11:28 AM   |  #4  
Spec-Chum's Avatar
OP Senior Member
Thanks Meter: 87
 
272 posts
Join Date:Joined: Mar 2013
Oh, and I really wouldn't used the ffmpeg built-in aac encoder, the quality isn't very good and the channels are wrong when using 6 channels...

Nero encodes DTS and AC3 into 6 channel aac fine, receiver says "HDMI Multi-Chan Audio"
13th April 2014, 01:02 PM   |  #5  
paracha3's Avatar
Senior Member
Flag Jeddah
Thanks Meter: 15
 
181 posts
Join Date:Joined: Jan 2008
More
Quote:
Originally Posted by Spec-Chum

Oh, and I really wouldn't used the ffmpeg built-in aac encoder, the quality isn't very good and the channels are wrong when using 6 channels...

Nero encodes DTS and AC3 into 6 channel aac fine, receiver says "HDMI Multi-Chan Audio"

well i guess let me ask, what binaries you need for windows?
13th April 2014, 04:36 PM   |  #6  
Spec-Chum's Avatar
OP Senior Member
Thanks Meter: 87
 
272 posts
Join Date:Joined: Mar 2013
Quote:
Originally Posted by paracha3

well i guess let me ask, what binaries you need for windows?

If you're using Nero, which I recommend, then any ffmpeg and NeroAacEnc from here: http://www.nero.com/eng/company/abou...-aac-codec.php
Post Reply Subscribe to Thread
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes