LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
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 08-24-2015, 08:41 PM   #31
damn.snarky.bastard
Member
 
Registered: Aug 2015
Posts: 39

Original Poster
Rep: Reputation: Disabled

Didn't quite work out the way I expected grail.

Line 7 says
Code:
ffmpeg -i "$movie" -af volume="$vfvol" "./encoded1/$movie"
Now, when I run the volumedetect on its own, the result is a negative number. In order to counter that I need a positive number, but can't see if it's being done. do I not have to multiply vfvol X -1?

Other than that my build insists the codec is experimental and to add
Code:
 -strict -2
.

Its so close I can almost taste it.
 
Old 08-25-2015, 07:05 AM   #32
damn.snarky.bastard
Member
 
Registered: Aug 2015
Posts: 39

Original Poster
Rep: Reputation: Disabled
grail, we've been proceeding on the assumption that running
Code:
 #! /bin/bash
mkdir ./encode
for IFS in *.mp4; do
vfvol=$(ffmpeg -i "${IFS}" -af volumedetect -f null /dev/null| sed '/max_volume:/ s/\ \-[0-9]+\.[0-9]\ dBs/-vf "volume=\p')
echo "$vfvol"
will give us an output similar to

[Parsed_volumedetect_0 @ 0x16c14a0] n_samples: 462422016
[Parsed_volumedetect_0 @ 0x16c14a0] mean_volume: -26.7 dB
[Parsed_volumedetect_0 @ 0x16c14a0] max_volume: -1.9 dB
[Parsed_volumedetect_0 @ 0x16c14a0] histogram_1db: 1
[Parsed_volumedetect_0 @ 0x16c14a0] histogram_2db: 274
[Parsed_volumedetect_0 @ 0x16c14a0] histogram_3db: 1734
[Parsed_volumedetect_0 @ 0x16c14a0] histogram_4db: 3879
[Parsed_volumedetect_0 @ 0x16c14a0] histogram_5db: 8453
[Parsed_volumedetect_0 @ 0x16c14a0] histogram_6db: 19589
[Parsed_volumedetect_0 @ 0x16c14a0] histogram_7db: 43251
[Parsed_volumedetect_0 @ 0x16c14a0] histogram_8db: 87977
[Parsed_volumedetect_0 @ 0x16c14a0] histogram_9db: 164030
[Parsed_volumedetect_0 @ 0x16c14a0] histogram_10db: 280869


and that we have picked up a quantifiable value for vfvol, but we have not Something seemed off, so I ran
[code]
#! /bin/bash
mkdir ./encode
for IFS in *.mp4; do
vfvol=$(ffmpeg -i "${IFS}" -af volumedetect -f null /dev/null| sed '/max_volume:/ s/\ \-[0-9]+\.[0-9]\ dBs/-vf "volume=\p')
echo "1"
echo ${vfvol}
done
[\code]
and the result was:
[Parsed_volumedetect_0 @ 0x16c14a0] n_samples: 462422016
[Parsed_volumedetect_0 @ 0x16c14a0] mean_volume: -26.7 dB
[Parsed_volumedetect_0 @ 0x16c14a0] max_volume: -1.9 dB
[Parsed_volumedetect_0 @ 0x16c14a0] histogram_1db: 1
[Parsed_volumedetect_0 @ 0x16c14a0] histogram_2db: 274
[Parsed_volumedetect_0 @ 0x16c14a0] histogram_3db: 1734
[Parsed_volumedetect_0 @ 0x16c14a0] histogram_4db: 3879
[Parsed_volumedetect_0 @ 0x16c14a0] histogram_5db: 8453
[Parsed_volumedetect_0 @ 0x16c14a0] histogram_6db: 19589
[Parsed_volumedetect_0 @ 0x16c14a0] histogram_7db: 43251
[Parsed_volumedetect_0 @ 0x16c14a0] histogram_8db: 87977
[Parsed_volumedetect_0 @ 0x16c14a0] histogram_9db: 164030
[Parsed_volumedetect_0 @ 0x16c14a0] histogram_10db: 280869
1

terry@TP500LA:~/shell scripts/1$


There, below the number one, we see that the value of vfvol is, for practical purposes, null. I would not want to accuse syg00 of making a mistake, in his sed, but either he did or I have screwed up somewhere along the way. Unless we can find a way to obtain and use the value of vfvol we are at a standstill. I don't know how good you are with sed, but I have proven that I do not make big bucks as a programmer.

I hate to give up, but I am in way over my head and can see it if you would prefer to spend your time more productively helping others. If, however, you want to continue I am open to suggestions. Either way I'd like to thank you for your time and patience, you've been a big help.
 
Old 08-25-2015, 10:31 AM   #33
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,425

Rep: Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826
Quote:
Originally Posted by damn.snarky.bastard View Post
grail, we've been proceeding on the assumption that running
Code:
 #! /bin/bash
mkdir ./encode
for IFS in *.mp4; do
vfvol=$(ffmpeg -i "${IFS}" -af volumedetect -f null /dev/null| sed '/max_volume:/ s/\ \-[0-9]+\.[0-9]\ dBs/-vf "volume=\p')
echo "$vfvol"
will give us an output similar to

[Parsed_volumedetect_0 @ 0x16c14a0] n_samples: 462422016
[Parsed_volumedetect_0 @ 0x16c14a0] mean_volume: -26.7 dB
[Parsed_volumedetect_0 @ 0x16c14a0] max_volume: -1.9 dB
[Parsed_volumedetect_0 @ 0x16c14a0] histogram_1db: 1
[Parsed_volumedetect_0 @ 0x16c14a0] histogram_2db: 274
[Parsed_volumedetect_0 @ 0x16c14a0] histogram_3db: 1734
[Parsed_volumedetect_0 @ 0x16c14a0] histogram_4db: 3879
[Parsed_volumedetect_0 @ 0x16c14a0] histogram_5db: 8453
[Parsed_volumedetect_0 @ 0x16c14a0] histogram_6db: 19589
[Parsed_volumedetect_0 @ 0x16c14a0] histogram_7db: 43251
[Parsed_volumedetect_0 @ 0x16c14a0] histogram_8db: 87977
[Parsed_volumedetect_0 @ 0x16c14a0] histogram_9db: 164030
[Parsed_volumedetect_0 @ 0x16c14a0] histogram_10db: 280869
The above is completely wrong. We do not assume any such thing about the output.

I understand this is all new to you but you really need to read the information provided a lot more carefully.

So using the above I will start again:

1. First and foremost, do not use IFS as a variable

2. The output of the call to ffmpeg and the sed will be exactly as below (assuming the typos in your sed were a mistake):
Code:
-vf "volume=1.9"
3. Given the above is the exact output, this will error or give erroneous results if used in the following:
Code:
ffmpeg -i "$movie" -af volume="$vfvol" "./encoded1/$movie"
The reason the above will error or give wrong results is because the variable expands to what I have shown above.
So the once expanded it will look like:
Code:
ffmpeg -i "$movie" -af volume="-vf "volume=1.9"" "./encoded1/$movie"
As you can see, the part in red is all wrong. It should read:
Code:
ffmpeg -i "$movie" -af volume="1.9" "./encoded1/$movie"
You need to go back and re-read all the information supplied. syg00's sed works just fine as we had shown previously. I had also advised previously that his sed
will not provide the solution you want. You need to reduce it so it only returns the numbers you are interested in (which if you review post #30 you will see a solution)
 
Old 08-25-2015, 09:47 PM   #34
damn.snarky.bastard
Member
 
Registered: Aug 2015
Posts: 39

Original Poster
Rep: Reputation: Disabled
grail, that code was from earlier on. I was using it to try and get an output for vfvol.

PLEASE FORGET ALL THAT!

I've been searching and cat napping and I just now discovered a work-around. Simply by adding
[code]
-report]
[\code]
to the line containing
[code]
-af volumedetect
[\code]

I was able to generate a file designated "ffmpeg-20150825-184828.log", which contained every line generated by volumedetect. Next, I tried
[code] grep -E "max_volume" [\code]

I won't post everything here, as I'm actually bouncing back and forth between two computers. I started off on my lappie but since I replaced the faulty ram, I started using Gargatubrain and a 50" tv, so the rest is over there. But long story made short, I have managed to isolate the line containing "max_volume."

My stress level is too high because I was obsessing over this. I knew there was an easy way to do it. The next thing to do is pump it through the sed, verify the output, and pop the variable into the last section where the volume adjustment is made and the final file generated. I'll also apply an if then to skip any file with a value of less than 1. I ran a file with a max_volume of 0.0db through volume=0.0 and the result was a disaster - a max_volume of -91db.

I really need a break now, but the end is in sight.

1) run volumedetect with -report in it.
2) grep -E "max_volume" on file "ffmpeg*.log"
3) run the sed for value of "max_volume"
4) if $ -lt 1 skip encoding. move to ~/Videos/Movies
5) apply to "volume=", move to Movies
6) delete log file.

That part was more for my benefit than anything else. I'm going to crash soon whether I want to or not, and it takes a bit for my brain to achieve optimal operating temperature. I'm not dumb, but this freaking depression really slows things down. If you want to write it, and you probably do just to see if it works, feel free.

Thanks for sticking with me through this, I never would have made it this far without you.
 
Old 08-26-2015, 03:43 AM   #35
ondoho
Senior Member
 
Registered: Dec 2013
Posts: 4,658

Rep: Reputation: 987Reputation: 987Reputation: 987Reputation: 987Reputation: 987Reputation: 987Reputation: 987Reputation: 987
you know you can edit your posts, right?

you got the code tags right twice, but now it's worse than before:

[code]just some $CODE[\code]

this is wrong.
the backslash \ should be a slash /.

you know you can edit your posts, right?

and, sorry if i sound like a heartless a***hole, but if you're coding with the same level of attention as you're writing forum posts, no wonder it's difficult.
take it slow, most of all!
there's no hurry!
read it through, try it again, read it again, make some corrections...

so next time, post the whole script, and post the whole output of the script (incl. error messages).
how are we to know how far you've gotten along with improving your code?

btw, i hope you're using an editor with a monospaced font & syntax highlighting?

and please, use code tags.
 
Old 08-28-2015, 07:58 PM   #36
damn.snarky.bastard
Member
 
Registered: Aug 2015
Posts: 39

Original Poster
Rep: Reputation: Disabled
ondoho, I think I've done pretty well, all things considered. I'm not sure what you know about depression, but that is what put me on disability. I still have a few years until I reach retirement age, but there is no way I could handle the stress. Stress worsens my depression which in turn further impairs my ability to think clearly. A few months ago my neighbor comes in telling me what he got me at the store as he began unloading the bags. When I asked him what this was all about as I really had no idea he told me that I had given him some money the day before to pick up a few things for me. If my mind can get so muddled because of my depression, which I did mention in a much earlier post, that I can't remember a conversation from the night before, what right have you to come down on me because I misremembered which way a slash goes?

I was so stressed and so depressed that when I awoke yesterday I laid there for nearly 90 minutes barely able to move. Yes, I am mentally ill, but I'm doing the best I can with what I've got.

Picture yourself with a brutal hangover trying to figure out how to accomplish a task you have little knowledge about in the first place. You know that persistant fog you just can't shake? That's what I have to contend with all day, every day of my life. Yes, you are being an A.....

I'll post my completed script in a moment. It is working right now. Then go back and see what others have contributed and what I, a scripting noob, have had to discover for myself. If you are fair and honest you just may be a little more tolerant in the future.
 
Old 08-28-2015, 09:31 PM   #37
damn.snarky.bastard
Member
 
Registered: Aug 2015
Posts: 39

Original Poster
Rep: Reputation: Disabled
Success!

Edit: Not exactly right.
I wrote a little script to check the max_volume on the completed files and save the results to a log file. See post #43

I have been at this for, what, three days now and my script is finally working the way I want it too. It parses a single folder, calculates whay the volume level is for each file, and how far, if at all it is from the "ideal" level, designated 0.0 db. What got me started on this little project was having to constantly turn the volume up or down to a comfortable level. Say you just watched a movie with a max_volume of - 12.3 db, so you had to crank the volume way up. Later you play a video with a max_volume of 0.0 db and you're blasted out of your chair in a mad scramble for the remote. I learned that ffmpeg had an audio filter called "volumedetect" (-af volumedetect) that would give you a numerical value that you would then run a second instance of ffmpeg using the audio filter "volume: (-af volume=foo), changing a negative integer to a positive along the way.

For lack of a better term I call it volume leveling, making all video files have audio tracks at the same level. I seen music players that can apply the gain, the aforementioned "difference" across a series of audio tracks, but nothing for videos. Syg00 supplied the sed seen in the script, which worked perfectly to strip away unneeded characters to give me the value for gain once I figured out what to do with it. Special thanks to grail for support and encouragement while we were both crawling around in circles with our tongues nailed to the floor. Here is the final, hopefully, incarnation.

Code:
#!/bin/bash

mkdir -p ./encoded  # the use of -p here will stop you getting errors telling you that the directory already exists
filename=$(basename "$fullfile")
extension="${filename##*.}"
filename="${filename.*}"
for filename in * ; do
ffmpeg -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
s="$(<ffmpegnew.log)"
t=s*10
if [ t -lt 10 ]
then 
/home/terry/Builds/ffmpeg-2.7.1-64bit-static/ffmpeg -i "$filename" -y -f matroska -r 29.97 -vcodec libx264 -preset slow -vf scale=704:384 -b:v 1000k -aspect 16:9 -flags +loop -cmp chroma -b:v 1250k -maxrate 1M -bufsize 4M -bt 256k -refs 1 -bf 3 -coder 1 -me_method umh -me_range 16 -subq 7 -partitions +parti4x4+parti8x8+partp8x8+partb8x8 -g 250 -keyint_min 25 -level 30 -qmin 10 -qmax 51 -qcomp 0.6 -trellis 2 -sc_threshold 40 -i_qfactor 0.71 -acodec ac3 -b:a 112k -ar 48000 -ac 6 /home/terry/Videos/Movies/"${filename%.*}".mkv; mv "$filename".mkv ./encoded;
else
/home/terry/Builds/ffmpeg-2.7.1-64bit-static/ffmpeg -i "$filename" -y -f matroska -r 29.97 -vcodec libx264 -preset slow -vf scale=704:384 -b:v 1000k -aspect 16:9 -flags +loop -cmp chroma -b:v 1250k -maxrate 1M -bufsize 4M -bt 256k -refs 1 -bf 3 -coder 1 -me_method umh -me_range 16 -subq 7 -partitions +parti4x4+parti8x8+partp8x8+partb8x8 -g 250 -keyint_min 25 -level 30 -qmin 10 -qmax 51 -qcomp 0.6 -trellis 2 -sc_threshold 40 -i_qfactor 0.71 -acodec ac3 -af volume="$s" -b:a 112k -ar 48000 -ac 6 /home/terry/Videos/Movies/"${filename%.*}".mkv; mv "Sfilename".mkv ./encoded;
fi
rm *.log;
done
I didn't document it well, so I'll try to explain. Running volumedetect was straightforward, but how to take the value from the screen and put it in the script. Lots of mistakes were made, especially the idea that we could just push it through the sed. no such luck. What outputting to a file? More mistakes and false starts, lots and lots of crashing as my depression overwhelmed me and I pulled a Brian Wilson. (Open a tab and google the name, you might want to include "beach boys") Finally I stumbled upon " - report" which created a novel length file. More searching led me to the grep line.

I'm not going to try and explain grep, but found out that grep -Ev "foo123" would remove all lines with the words/letter/number/combination-of-these contained within the quotes, which was the opposite of what I wanted, but grep -E "foo123" would discard everything but that line. Hundreds, perhaps even thousands of syntax errors later I was able to isolate number-dot-number combination in the text file by pumping it through the sed so--- assign to variable. Since previous experience proved that using "0." for the volume yielded a file with "max_volume -91 db" a conditional loop -if/then/else brought on three separate, distinct eternities of inventing swear words as it seemed to bypass the loop and any file with "0.0" put out files with "-91 db" when tested.

More crashing, not caring if the world ended, more searching and "bash does not recognize floating point numbers" impinged on my consciousness, so, new variable of 10xvolume adjustment, fix if statement to reflect same and computer is now churning out files with the volumes adjusted.

Not bad for a scripting noob who keeps crashing, unable to move for hours.

Next project - automatically seek and unpacking packed bitstreams. Perhaps when I've had time to refine them I'll contact Winff ans see if they'll incorporate it in their GUI.

Last edited by damn.snarky.bastard; 09-01-2015 at 04:56 PM. Reason: Not exactly right
 
Old 08-29-2015, 04:50 PM   #38
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,425

Rep: Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826
Well I am not sure you will want to read this, so you can ignore if you like, however, your script is riddled with problems that may not be obvious
but I would guess they do not help yield the results you are looking for.

I will take it from the top:

1. Upto the command, mkdir -p ./encoded ... all good

2. The variable 'fullfile' does not exist, so the 3 lines below serve no purpose
Code:
filename=$(basename "$fullfile")
extension="${filename##*.}"
filename="${filename.*}"
3. Your for loop re-uses the variable name that you attempted to set outside the loop. But as each iteration of the loop will populate the variable, anything previously set would be over-written

4. ffmpeg line works but I think we can use it straight with the sed instead of creating a file... will comeback to this

5. The grep line, apart from displaying on the screen that the 'max_volume' line exists, serves no purpose

6. Assuming the sed is now returning the correct data, it can just as easily be applied to the stream as the file: (I have used the below and confirm it works)
Code:
s=$(ffmpeg -i "$filename" -af volumedetect -f null /dev/null |& sed -nr '/max_volume:/ s/.*[[:space:]]-?([[:digit:]\.]+)[[:space:]]+dB$/\1/p')
7. The above would of course replace your current setting of the 's' variable

8. I would suggest you place an echo in your script for the 't' variable. You can also do the following at the command prompt:
Code:
$ t=s*10
$ echo $t
s*10
As you can see, 't' does not have what you expected. Also, bash does not perform arithmetic directly

9. As we are concerned with mainly round numbers, I would simply remove the decimal portion using your already learnt parameter substitution:
Code:
if (( ${s.*} < 10 ))
You will also notice the use of round brackets to perform arithmetic operations

10. Your current 'if' will always error and hence the 'else' portion will always run with any file you submit (see point 8 and try your test on the command line)

11. The 'if' has me a little confused (assuming it worked). I would think one of the commands is not required as you want to essentially leave the file with its current settings?? So i would play with your 'if' test and return only the one that needs to change the file (which would appear when it is true, ie. when you do not pass through -af volume)

12. I was also curious why your very first call to ffmpeg is the system one but when you alter the file you call a custom version. Why not just use the same one all the time so you get equivalent results for all parts of the program

13. Here I nearly said, why don't you place the 'mv' command after the 'if' so you only have to call it once, but then a few things caught my eye:

a. You are creating your newly encoded files under /home/terry/Videos/Movies/
b. You are moving a file of the format ... "Sfilename".mkv ... into the encoded directory, but as far as I can tell, this file does not exist anywhere.

An example for part 'b' above:

1. you currently have a file called movies.mp4
2. you encode this with the above script
3. this will create the following file: /home/terry/Videos/Movies/movies.mkv
4. you now attempt to 'mv' which will look like this: mv movies.mp4.mkv ./encoded - - - As you can see, there will never be a file with this name in this directory. So this will simply error.

14. You do not require a semi-colon (;) after every command. A new line in the script serves as the same purpose

Now i will have to leave the 'if' part to you as I am still not certain of the desired outcome there, however, the first portion could be as simple as;
Code:
#!/bin/bash

mkdir -p ./encoded

for filename in *
do
  s=$(ffmpeg -i "$filename" -af volumedetect -f null /dev/null |& sed -nr '/max_volume:/ s/.*[[:space:]]-?([[:digit:]\.]+)[[:space:]]+dB$/\1/p')

  if (( ${s%.*} < 10 ))
  then
    ...
  fi
done
As usual, hope some of that helps

Last edited by grail; 08-29-2015 at 04:52 PM.
 
Old 08-29-2015, 09:42 PM   #39
damn.snarky.bastard
Member
 
Registered: Aug 2015
Posts: 39

Original Poster
Rep: Reputation: Disabled
Oh, I had no illusions that there was no room for improvement. What we have here is a bona fide Frankenstein's monster with bits and pieces literally stolen from many different sources, mainly forums. I knew those three lines were almost useless, but for some reason even though it was encoding in mkv, for some reason it wrote the extension as mp4. I verified the encoding method first, then copied that over to output the right extension. Your way of dealing with "s" is a lot simpler than the "comparable in length to War and Peace" method I started off with. I figured a new variable was a lot easier than trying to come up with a more elegant solution. I had taken a pretty nasty downturn taking nearly 90 minutes after waking one morning until I was able to get moving. Some people eat when they're depressed, I go horizontal, getting out of bed only when hydralic pressure forces me to make that trip down the hall.

For the moment it is doing what I intended and I'm crawling out of that hole I was in. I did learn from the experience and even knew the proper answers to some of the questions posed by others from my research. I will probably go through and refine it in the near future. I will likely need it again in the future, and learning a better way is worth the effort.

In short, I think of my script as an attempt at art by employing explosives as compared to, say, Rodin's sculpture, "The Thinker."

Thanks again for the help. I probably would have given up without the effort you were putting in to help someone you've never met.

Last edited by damn.snarky.bastard; 08-29-2015 at 09:45 PM.
 
Old 08-30-2015, 12:43 AM   #40
Shadow_7
Senior Member
 
Registered: Feb 2003
Distribution: debian
Posts: 2,517
Blog Entries: 1

Rep: Reputation: 494Reputation: 494Reputation: 494Reputation: 494Reputation: 494
Your -vol type stuff is over thinking it IMO.

cat $VAR_of_FILES | ffmpeg -i -

Although if your intent it to concatenate several movies into one long one. I tend to -f rawvideo and .raw the individual clips. Then "cat clips*.raw > newclip.raw" and run the encode on the newclip.raw file. You chew up a lot of temporary storage that way, but something that's possible in every version of ffmpeg for over a decade. Audio of course needs separate handling but basically the same approach.
 
Old 08-30-2015, 06:29 AM   #41
damn.snarky.bastard
Member
 
Registered: Aug 2015
Posts: 39

Original Poster
Rep: Reputation: Disabled
You would not believe how widely they vary. Besides, I have 24/7/365 on my hands and not a whole hell of a lot to fill it with. While my depression does dull my thinking, I don't want my brain to atrophy too much and a gordian knot type of problem does tend to keep one's brain alive, even if I do have to tolerate those hours of oblivion I get when I crash.
 
Old 08-30-2015, 10:41 PM   #42
damn.snarky.bastard
Member
 
Registered: Aug 2015
Posts: 39

Original Poster
Rep: Reputation: Disabled
Hey grail! I was just looking back on the script and realized you brought up a point that I did not explain properly.

you wrote:
An example for part 'b' above:
Quote:
1. you currently have a file called movies.mp4
2. you encode this with the above script
3. this will create the following file: /home/terry/Videos/Movies/movies.mkv
4. you now attempt to 'mv' which will look like this: mv movies.mp4.mkv ./encoded - - - As you can see, there will never be a file with this name in this directory. So this will simply error.
Allthough it was encoding in matroska it appended the file with "mp4", hence the crap up top I just copied and pasted. It strips away everything past "filename" allowing me to input mkv for the extenstion. Parsing the ffmpeg you are correct about the input "movie.mp4". It re-encodes the file with the corrected extension, giving me ./movie.mkv in the subfolder and halts. The semi-colon, of course indicates a new command to mv the file movie* to ./converted. Now we do not have two files in the folder, only one. mkv is in a child folder leaving only the original movie.mp4 to move.

Upon completion it goes back to the top, picks up a different file and goes through the loop again.

It confused the hell out of me 30 odd years back when I learned B.A.S.I.C., might look strange at first but there is never a point when two files with the exact same name or prefix are trying to co-exist in the same folder at the same time.

Regards.
 
Old 09-01-2015, 04:51 PM   #43
damn.snarky.bastard
Member
 
Registered: Aug 2015
Posts: 39

Original Poster
Rep: Reputation: Disabled
Still not right

Having an issue with completed files having a max_volume of -91 db, which happens when you apply -af volume=foo. Working on it.
 
Old 09-01-2015, 04:59 PM   #44
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,425

Rep: Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826
Quote:
Originally Posted by damn.snarky.bastard View Post
Hey grail! I was just looking back on the script and realized you brought up a point that I did not explain properly.

you wrote:
An example for part 'b' above:


Allthough it was encoding in matroska it appended the file with "mp4", hence the crap up top I just copied and pasted. It strips away everything past "filename" allowing me to input mkv for the extenstion. Parsing the ffmpeg you are correct about the input "movie.mp4". It re-encodes the file with the corrected extension, giving me ./movie.mkv in the subfolder and halts. The semi-colon, of course indicates a new command to mv the file movie* to ./converted. Now we do not have two files in the folder, only one. mkv is in a child folder leaving only the original movie.mp4 to move.

Upon completion it goes back to the top, picks up a different file and goes through the loop again.

It confused the hell out of me 30 odd years back when I learned B.A.S.I.C., might look strange at first but there is never a point when two files with the exact same name or prefix are trying to co-exist in the same folder at the same time.

Regards.
You need to go back and look at your code and what I have written as in this case I am not talking about 2 files with same name but the fact you are trying to move a file which does not exist at all.

Your latest issue also does not surprise me as ALL your files will undergo the same process as your 'if' was not working as intended
 
Old 09-02-2015, 01:11 PM   #45
damn.snarky.bastard
Member
 
Registered: Aug 2015
Posts: 39

Original Poster
Rep: Reputation: Disabled
grail, if you're referring to that bit you posted about the if statement, I finally figured out that I forgotten to change that. As I am sure you know, one rule of diagnoses is to change ONE thing and see how that affects the outcome, which is what I did and forgot to go back to your stuff. I corrected that last night and everything seems to be fine. Here is the version I'm running now:

Code:
#!/bin/bash

mkdir -p ./encoded  # the use of -p here will stop you getting errors telling you that the directory already exists
filename=$(basename "$fullfile")
extension="${filename##*.}"
filename="${filename.*}"
for filename in * ; do
ffmpeg -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
s="$(<ffmpegnew.log)"
echo "$filename - ""$s" >> list.txt
if (( ${s%.*} -ne 0 ))
then 
/home/terry/Builds/ffmpeg-2.7.1-64bit-static/ffmpeg -i "$filename" -y -f matroska -r 29.97 -vcodec libx264 -preset slow -vf scale=704:384 -b:v 1000k -aspect 16:9 -flags +loop -cmp chroma -b:v 1250k -maxrate 1M -bufsize 4M -bt 256k -refs 1 -bf 3 -coder 1 -me_method umh -me_range 16 -subq 7 -partitions +parti4x4+parti8x8+partp8x8+partb8x8 -g 250 -keyint_min 25 -level 30 -qmin 10 -qmax 51 -qcomp 0.6 -trellis 2 -sc_threshold 40 -i_qfactor 0.71 -acodec ac3 -af volume="$s" -b:a 112k -ar 48000 -ac 6 /home/terry/Videos/Movies/"${filename%.*}".mkv; mv "$filename" ./encoded
else
/home/terry/Builds/ffmpeg-2.7.1-64bit-static/ffmpeg -i "$filename" -y -f matroska -r 29.97 -vcodec libx264 -preset slow -vf scale=704:384 -b:v 1000k -aspect 16:9 -flags +loop -cmp chroma -b:v 1250k -maxrate 1M -bufsize 4M -bt 256k -refs 1 -bf 3 -coder 1 -me_method umh -me_range 16 -subq 7 -partitions +parti4x4+parti8x8+partp8x8+partb8x8 -g 250 -keyint_min 25 -level 30 -qmin 10 -qmax 51 -qcomp 0.6 -trellis 2 -sc_threshold 40 -i_qfactor 0.71 -acodec ac3 -b:a 112k -ar 48000 -ac 6 /home/terry/Videos/Movies/"${filename%.*}".mkv; mv "$filename" ./encoded
fi
rm *.log;
done
Figuring a little paranoia can be a good thing I altered the hell out of it, making it only do the volumedetect and appending it to a list, and running it on the destination directory. It seems that the odd one slips through, perhaps recoding the file interferes somehow, and make the adjustment manually.

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
And just for the hell of it, the command for the volume adjust by itself because when I was first learning Linux I'd be searching for answers and some of them were almost what I wanted, but lacked the skill to adapt it.

Code:
 ffmpeg -i foo -af volume=value_taken_from_the_list_generated_by_the_script_above ------/destintation directory
I usually just make a new folder named "1", put the new file in there, verify it, and if it is good cut and paste it up one level to overwrite the file there.

Finally, for those less experienced, the filter -af volume=foo automagically sets the video codec to copy so there is no need to add that to the command.

It is long past time to close this thread. Thank you again to those who offered their help. I never seem to learn anything from "Hello World" exercises, but let me dissect something where I've really got to use the old cocoanut and I get a far deeper understanding. My confidence level is way up. I have successfully written a little script to seek out avi files with packed bitstreams and unpack them. It isn't perfect as it places all the unpacked in the parent directory, but not as many people are using packed bitstreams these days and it beats the hell out of checking each one separately.

Now I just have close to 1000 files to work on.

Last edited by damn.snarky.bastard; 09-02-2015 at 01:13 PM. Reason: spelling
 
  


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 12:27 AM.

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