It is currently Jan 23rd, '19, 21:38

Topic: From Scripts to Packages:

Development forum
Various experiments, side projects and documentation

From Scripts to Packages:

Unread postby Konomi » Nov 3rd, '14, 02:02

So basically anything I am working on (and I mostly script but I have aspirations for using lower level languages) generally starts it's life in ~/Scripts/ or if I am feeling really lazy ~/ (Equips suit of rage resistance). Anyway I cooked this up last night, it is by no means to be considered safe or official! You have been warnnnneedddddded.

Anyway I wanted to convert a bunch of troublesome m4a files that end up with the fourcc of dash instead of say mpeg-4, this confuses a lot of programs that can actually work on the aac audio inside the m4a container but have never heard of mpeg-dash. Now if I spend enough time on this script eventually it might become an unofficial package fore Debian! (Unofficial means in my little collection of packages but I may soon be making those public) So the code:

Code: Select all
#!/usr/bin/env bash

# ffmpeg explodes the file if you use the extension .aac
# makes malformed files never use that file extension for
# file_extension_out


nano_secs() {
   ns="$(date +'%N')"
   if [ -z "$ns" ]; then
      echo "Nanoseconds null, error"
      exit "1"
}; nano_secs

# need our list of files probably should handle shopts better though
file_list() {
   shopt -s globstar nullglob
   shopt -u globstar nullglob
}; file_list

# some asking of the user aka me cause I make mistakes
for i in "${file_list[@]}"; do
   echo "$i"
read -p "Process these files? [y/n] " choice
if [ "${choice,,}" != "y" ]; then
   echo "Cancelled"
   exit "0"

# using a main function has the advantage of being able to return
# out of the function at any time instead of using exit to finish
# the script
main() {
   for i in "${file_list[@]}"; do
      # move i to file_in
      # generate a file name temporarly to move the file_in to
      # a new file name
      # move the file
      mv "$file_in" "$file_mv"
      # generate the file out name
      # process with ffmpeg
      ffmpeg -i "$file_mv" -vcodec copy -acodec copy "$file_out"
      # remove the file on successful conversion
      if [ -e "$file_out" ] && [ "$ffmpeg_exit_code" == "0" ]; then
         # remove the original file
         rm "$file_mv"
}; main "$@"
1. Follow the order of operations
2. Don't hurt anyone
3. Do what you want
4. Don't talk about fight club :3
User avatar
Obey the ears
Posts: 29
Dec 2nd, '13, 02:45
[♀] Female
Forum role:
Tech Guru
Operating system:

Return to General Development


Who is online

Users browsing this forum: No registered users and 1 guest