amiaopensource / ffmprovisr

Repository of useful FFmpeg commands for archivists!
https://amiaopensource.github.io/ffmprovisr/
528 stars 66 forks source link

audio phase shift #195

Closed bturkus closed 7 years ago

bturkus commented 7 years ago

wondering if anyone else thought it'd be worthwhile to add a phase shift command. I just received a file that was 90 degrees off, and the following command (from superuser.com) seemed to help:

ffmpeg -i input.wav -af "aeval='-val(0)':c=same" output.wav

I'd be happy to add (once I complete eia608!), but I was hoping someone could confirm: is this the right was to do it? And: would it make any sense to add a phase check command? I don't really understand how the one in mmfunctions functions (https://github.com/mediamicroservices/mm/blob/master/phasecheck)

ablwr commented 7 years ago

👍

privatezero commented 7 years ago

It was 90 degrees as opposed to 180 degrees? I haven't tested aeval for phase issues, but if things are a fully reversed you can use the pan filter with a negative multiplier to reverse the phase of one of the tracks like such:

-af pan="stereo| c0=c0| c1=-1*c1"

This command maps the output's first channel (c0) to the input's first channel and the output's second channel (c1) to the inverse of the input's second channel

privatezero commented 7 years ago

I think actually the * isn't even required. This is how the phase reverse option is set up in vrecord: https://github.com/amiaopensource/vrecord/blob/master/vrecord#L382

bturkus commented 7 years ago

I struggle with audio in general, but the technician's notes said 90. The orig transfer looked this this:

screen shot 2017-06-08 at 5 19 58 pm

And the script I ran turned it to this:

screen shot 2017-06-08 at 5 41 01 pm

Yours did this:

screen shot 2017-06-08 at 5 40 37 pm

I'm super confused at this point, so I'll defer to @privatezero if that's okay. Maybe it's a "half a dozen of one" type thing, though whatever I did looks skinny and weird in QCTools (though it sounded okay). QCTools audio vectorscope is also acting funky (poss a separate issue)

privatezero commented 7 years ago

Hi Ben! That first example is of two mono tracks that have waveforms 180 degrees out of phase with each other. This will show up as a flat line on the phase scope (which is probably why the tech referred to it as 90 degrees, because visually it is a 90 degree shift...eeek! Confusing terminology!) This is what will cause the waves to cancel each other out when played back.

The last example is a healthy representation of two mono tracks that are in correct phase (more or less anyway - I won't go off on an azimuth tangent lol). Two identical mono tracks should always form a vertical line. Because the tracks are coming from an analog source, they won't be EXACTLY the same, which is why they look like a very thin vertical blob (and again, azimuth of playback head affects this but I won't go there).

The result in the middle looks like it has lost data/been digitally combined somehow, as it is TOO perfectly thin and straight. This is what two perfectly identical digital mono tracks would look like, but something from an analog source wouldn't usually be THAT perfect. And in this case we know from the initial out of phase example that they weren't! (For another example here is a picture of me recording two identical channels in audiorecorder via my computer's built in mono microphone. This is digital so tracks are perfectly identical and form a perfect vertical line).

image

privatezero commented 7 years ago

Oh, as a side note - if you run into tapes with this problem in the future, vrecord (via the gui) supports reversing the phase of one of the input channels during capture!

bturkus commented 7 years ago

Wow, Andrew, thank you so much. I think I might be starting to understand some things that've confused me for a long time. I gotta say: you've got a gift for making confusing shit understandable. Someone get metro on the line--we need an "Andrew Weaver Teaches Audio" class asap!

Resolved: aeval is no bueno. I'll work on getting the pan command into ffmprovisr, but again, it might take me a minute.

ablwr commented 7 years ago

@privatezero is the best!! Miss you Andrew!!!!!!

todrobbins commented 7 years ago

I gotta say: you've got a gift for making confusing shit understandable.

giphy

privatezero commented 7 years ago

Awww guys! Happy to help!!

kieranjol commented 7 years ago

Yeah, I reread that explanation and I understand audio phase better than ever even if I still don't 100% get it, thanks Andrew!

On 9 Jun 2017 06:55, "Andrew Weaver" notifications@github.com wrote:

Awww guys! Happy to help!!

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/amiaopensource/ffmprovisr/issues/195#issuecomment-307302200, or mute the thread https://github.com/notifications/unsubscribe-auth/ABEyvj-y1gpOZgCea-sUSsEoRiAr1OCqks5sCN5ogaJpZM4N0k-R .

ablwr commented 7 years ago

So the perfect command is... ffmpeg -i input.wav -af pan="stereo| c0=c0| c1=-1*c1" output.wav, is that right? I'm grabbin' this one from @bturkus because I have some free time!