Пример #1
0
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
"""

import sys
from scipy.io import wavfile
import numpy as np
from os import path as op

import pyvideomeg

for aud_file in sys.argv[1:]:
    if not op.isfile(aud_file):
        raise IOError('file not found: %s' % aud_file)
    if op.splitext(aud_file)[1] != '.aud':
        raise ValueError('unknown extension "%s"' % op.splitext(aud_file)[1])
    out_file = op.splitext(aud_file)[0] + '.wav'
    if op.isfile(out_file):
        print('Skipping, output file exists: %s' % out_file)
        continue
    print('Creating file: %s' % out_file)
    sys.stdout.flush()
    aud_file = pyvideomeg.AudioData(aud_file)
    rate = aud_file.srate
    n_ch = aud_file.nchan
    aud_file = np.frombuffer(aud_file.raw_audio, '<i2').reshape(-1, n_ch)
    wavfile.write(out_file, rate, aud_file)
Пример #2
0
along with this program.  If not, see <http://www.gnu.org/licenses/>.
"""

import sys

import pyvideomeg

try:
    vf = pyvideomeg.VideoData(sys.argv[1])
    is_audio = False
except pyvideomeg.UnknownVersionError:
    print('The file %s has unknown version' % sys.argv[1])
    sys.exit(1)
except:
    try:
        af = pyvideomeg.AudioData(sys.argv[1])
        is_audio = True
    except pyvideomeg.UnknownVersionError:
        print('The file %s has unknown version' % sys.argv[1])
        sys.exit(1)
    except:
        print('The file %s seems to be neither video nor audio file' %
              sys.argv[1])
        sys.exit(1)

if is_audio:
    nsamples = len(af.raw_audio) / af.nchan / 2
    wc_srate = (nsamples -
                (af.buf_sz / 2 / af.nchan)) * 1000. / (af.ts[-1] - af.ts[0])

    print('\n\n\n')
Пример #3
0
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
"""

import struct
import sys
from numpy import *

import pyvideomeg

assert (len(sys.argv) == 4)

aud_file = pyvideomeg.AudioData(sys.argv[1])
new_buf_sz = int(sys.argv[2])
old_buf_sz = aud_file.buf_sz / (aud_file.nchan * 2)
old_buf_cnt = len(aud_file.ts)
new_buf_cnt = (old_buf_sz * old_buf_cnt) // new_buf_sz

print('Old file: %i buffers of the size %i' % (old_buf_cnt, old_buf_sz))
print('New file: %i buffers of the size %i, last %i samples discarded' %
      (new_buf_cnt, new_buf_sz, (old_buf_sz * old_buf_cnt) % new_buf_sz))

# Fix timestamps according to the new buffer size
t_old = arange(0, old_buf_cnt) * old_buf_sz + (old_buf_sz - 1)
t_new = arange(0, new_buf_cnt) * new_buf_sz + (new_buf_sz - 1)
ts_new = interp(t_new, t_old, aud_file.ts).round()

# Write out the result
Пример #4
0
raw = mne.io.Raw(MEG_FNAME, allow_maxshield=True)

# load the timing channel
picks_timing = mne.pick_types(raw.info, meg=False, include=[TIMING_CH])
dt_timing = raw[picks_timing, :][0].squeeze()

# load the MEG channel
picks_meg = mne.pick_types(raw.info, meg=False, include=[MEG_CH])
meg = raw[picks_meg, :][0].squeeze()

# compute the timestamps for the MEG channel
meg_ts = pyvideomeg.comp_tstamps(dt_timing, raw.info['sfreq'])

vid_file_1 = pyvideomeg.VideoData(VIDEO_FNAME_1)
vid_file_2 = pyvideomeg.VideoData(VIDEO_FNAME_2)
aud_file = pyvideomeg.AudioData(AUDIO_FNAME)

audio, audio_ts = aud_file.format_audio()
audio = audio[0, :].squeeze()  # use only the first audio channel

#--------------------------------------------------------------------------
# Make the pics
#
plt.ioff()  # don't pop up the figure windows

ts_scale = np.diff(vid_file_1.ts).max() * (WIND_WIDTH + 0.1)
meg_scale = np.percentile(np.abs(meg), SCALE_PRCTILE_MEG) * 1.1
aud_scale = np.percentile(np.abs(audio), SCALE_PRCTILE_AUDIO) * 1.1

for i in range(1 + WIND_WIDTH, len(vid_file_1.ts) - (1 + WIND_WIDTH)):
    res = PIL.Image.new('RGB', (FRAME_SZ[0] * 3,