Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,732,778 Members 52,324 Now Online
XDA Developers Android and Mobile Development Forum

Simple bash video convertor

Tip us?
 
Spec-Chum
Old
(Last edited by Spec-Chum; 12th April 2014 at 10:56 PM.)
#1  
Spec-Chum's Avatar
Senior Member - OP
Thanks Meter 87
Posts: 266
Join Date: Mar 2013
Default Simple bash video convertor

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
Google Nexus 4 - KitKat
 
paracha3
Old
#2  
paracha3's Avatar
Senior Member
Thanks Meter 14
Posts: 174
Join Date: Jan 2008
Location: Jeddah
Very nice. What binaries you need to install to make this bash script run on Mac OS X?
HTC One M8
ROM: Android Revolution HD 8.0
FIRMWARE: 1.54.401.10 | RECOVERY: TWRP 2.7.0.2 | S-OFF | SUPER CID
 
Spec-Chum
Old
#3  
Spec-Chum's Avatar
Senior Member - OP
Thanks Meter 87
Posts: 266
Join Date: Mar 2013
Quote:
Originally Posted by paracha3 View Post
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?
Google Nexus 4 - KitKat
 
Spec-Chum
Old
#4  
Spec-Chum's Avatar
Senior Member - OP
Thanks Meter 87
Posts: 266
Join Date: 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"
Google Nexus 4 - KitKat
 
paracha3
Old
#5  
paracha3's Avatar
Senior Member
Thanks Meter 14
Posts: 174
Join Date: Jan 2008
Location: Jeddah
Quote:
Originally Posted by Spec-Chum View Post
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?
HTC One M8
ROM: Android Revolution HD 8.0
FIRMWARE: 1.54.401.10 | RECOVERY: TWRP 2.7.0.2 | S-OFF | SUPER CID
 
Spec-Chum
Old
#6  
Spec-Chum's Avatar
Senior Member - OP
Thanks Meter 87
Posts: 266
Join Date: Mar 2013
Quote:
Originally Posted by paracha3 View Post
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
Google Nexus 4 - KitKat
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


XDA PORTAL POSTS

Run, Jump, and Shoot in Tales of Ciaxia

There are certain types of games that have become paramount of the portable gaming world. As we have … more

Samsung Gear Live Stock Firmware Image Pulled, Temp Root

Just yesterday,XDA Recognized Developer and TV ProducerAdamOutlertore apart … more