LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-04-2015, 03:23 AM   #46
damn.snarky.bastard
Member
 
Registered: Aug 2015
Posts: 39

Original Poster
Rep: Reputation: Disabled

Gosh darn! Heck! Spit! I thought I had it, but no joy. The hang-up is in reading the floating point number from ffmpegnew.log. Bash does not recognize floating point numbers so can't perform arithmatic functions on them. Someone with experience in sed or awk could remove the decimal point and use that number in the if statement. Python, Ruby, Perl and a bunch of other goodies can manipulate them but I can't find out how to do that while/before assigning to a variable. Then there's zsh.....

I'm going to
a) drink too much Kool-Aid
b) transcode all my files to mkv
c) run
Code:
 #!/bin/bash

for file in * ; do
ffmpeg -i "$file" -af volumedetect -report -f null /dev/null
grep -E "max_volume" ffmpeg*.log > ffmpegnew.log
max=$(<ffmpegnew.log)
echo "$file - ""$max" >> list.txt
rm ff*.log;
done
d) consult list.txt and make the adjustments manually.

I started on this so I wouldn't have to check each file by hand, and the little script above will save countless hous. Not exactly what I had envisioned, but half a loaf is better than none. This is not a failure as I learned from it. No venture where you walk away wiser is ever a total waste of time.
 
Old 09-05-2015, 06:12 PM   #47
Shadow_7
Senior Member
 
Registered: Feb 2003
Distribution: debian
Posts: 2,330
Blog Entries: 1

Rep: Reputation: 449Reputation: 449Reputation: 449Reputation: 449Reputation: 449
You can use "bc" to do floating point math in bash. But your comparisons will be basically string literals in bash. You can also multiply by 10/100/1000 to simulate floating point in whole numbers. Which gets a little cumbersome if the input is floating point numbers. Various means to an end. Any reason for not using ffprobe for getting the video details?

I tend to prefix my videos with the specs. p30r1280x720__some_video.webm . It makes using wild cards based on specs for playback a little simpler.
 
Old 09-08-2015, 04:45 AM   #48
damn.snarky.bastard
Member
 
Registered: Aug 2015
Posts: 39

Original Poster
Rep: Reputation: Disabled
You didn't really think I was going to quit this close to the final solution, did you? Took some "Mental health" time.

Thanks, shadow7. I looked in to that but my brains were pretty well fried at the time and ended up exploring a different avenue. There is more than one possible route to a workable solution and I found one I'm happy with.

Point: Bash does not recognize floating point numbers. That is to say numbers with decimals. There are a number of ways around this. You can invoke a bit of code from python, or other language, as shadow7 pointed out, you can use bc as well to get your variable, say 8.3 for example, and adjust your volume level that way. I took a different route.

I installed zsh, with recommends, changed

Code:
 #!/bin/bash
to
Code:
 #!/bin/zsh
reworked the formula for the variable to add spaces where needed, and, after banging my head for a while, discovered that the higher math functions were not enabled by default and how to invoke them. I was going for an all-in-one solution but occasional errors crept in, possibly due to transcoding the files.

Step 1 obtained a copy of unpackmp4.jar from
http://www.xmixdrix.com/tools/unpackmp4.html
and wrote a little script to search for files with packed bitstreams and unpacked them.

Code:
 #!/bin/bash

# unpack avi files in branch adding "unpacked" to file name
# you will need the file unpackmp4.jar in your path
find . -type f -name "*.avi" -exec java -jar ./unpackmp4.jar -s unpack -d ./  {} \;
done
Make sure you put a copy of unpackmp4.jar in the parent folder and it will recurse through all folders in the branch, placing the unpacked file in the parent folder, appending the word "unpack" without the quotes before the extension. The are lots of renaming programs that are easy to use. I used "pyrenamer" to remove "unpack", then manually cut and paste them into their respective folders, overwriting the originals.

Step 2: Transcode your videos to the desired format. There are a myriad numbers of programs to do this for you and I don't feel it necessary to tell you how you should go about this. Having over 1700 files I moved them all into one folder and wrote a loop script with my parametersb (copied from a winff preset) and as I have way more disk space than I need, moved the original file to a new directory. That way if my machine went down for and reason (blown power transformer a couple of days ago, took them about three hours to restore power), I can simply restart my script and it picks up where it left off.

Step 3: THE FUN PART

I lied, but here is where we make the actual adjustment. The script runs -af volumedetect against each file in sequence, outputs what would normally be echoed on your screen to a log file, strips away every line that does not contain "max_volume", then the sed removes everything else, saving the value to a new log file, adjusts the volume level and on to the next file.

The file name and the adjustment value are appended to list.txt, the file with the adjusted volume goes in a subfolder for verinifation.

Note: copy both volumeadjust.sh and volumedetect.sh to working folder

volumeadjust.sh

Code:
#!/bin/zsh

for filename in * ;
do
ffmpeg -y -i "$filename" -af volumedetect -report -f null /dev/null
grep -E "max_volume" ffmpeg*.log
sed -nr '/max_volume:/ s/.*[[:space:]]-?([[:digit:]\.]+)[[:space:]]+dB$/\1/p' ffmpeg*log >ffmpegnew.log
zmodload zsh/mathfunc
s=$(<ffmpegnew.log)
mkdir -p 1
mkdir -p encoded
if (( s < 0.1 )) ; then
ffmpeg -i "$filename" -y -af volume="$s" ./1/"$filename"
fi
mv "$filename" ./encoded/
rm *.log;
done
Step 4:
cd ./encoded
Run "volumedetect.sh", which will run -af volumedetect against each file, appending to list.txt. If you are happy with the results move to final destination. Personally I move them up one directory, overwriting the original to avoid duplicated files with different volume levels.

volumedetect.sh

Code:
#!/bin/bash

for file in * ; do
ffmpeg -i "$file" -af volumedetect -report -f null /dev/null
grep -E "max_volume" ffmpeg*.log > ffmpegnew.log
max=$(<ffmpegnew.log)
echo "$file - ""$max" >> list.txt
rm ff*.log;
done

Step 5: POPCORN - you're on your own on this one.

Once again thanks for all the input. I'm not a programmer and this whole inelegant mess has been kluged together in what may seem to be a real tangle, but every line is there for a reason, if it doesn't do something, it fixes something.

I'm going to watch a video now. Good luck.

Last edited by damn.snarky.bastard; 09-14-2015 at 06:28 AM. Reason: syntax error
 
  


Reply

Tags
solved


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
bash scripting: read csv to multiple arrays spezticle Programming 5 01-08-2014 02:32 AM
Bash shell scripting --> comparing elements in different arrays via if/elif lord_brand Programming 5 06-21-2012 04:49 AM
[SOLVED] How to make arrays in sh scripting? ameylimaye Linux - Newbie 14 04-06-2012 01:23 PM
bash scripting - arrays and indirect referencing soulcurry Programming 7 04-21-2011 07:41 AM
[SOLVED] Bash Scripting - Using Arrays mrm5102 Linux - Newbie 4 04-05-2011 10:20 AM


All times are GMT -5. The time now is 04:52 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration