Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

export must be in mono not in stéréo. #102

Open
zeeshanmazhar opened this issue Feb 17, 2022 · 2 comments
Open

export must be in mono not in stéréo. #102

zeeshanmazhar opened this issue Feb 17, 2022 · 2 comments

Comments

@zeeshanmazhar
Copy link

zeeshanmazhar commented Feb 17, 2022

Hello,

I am exporting the AAF using WAV files, but it is exporting in stereo, i want it in mono, below is my code.

import aaf2
import subprocess
import json
import sys

#for line in sys.stdin:
#data = json.dumps(json.loads(line))

data = json.load(sys.stdin)

# print(data)

file_name = data["file_name"]
audio_tracks_dir = data['audio_tracks_dir']
audio_tracks = data['audio_tracks']
edit_rate = float(data['edit_rate'])
timecode_fps = int(round(edit_rate))

def probe(path):

    cmd = ['ffprobe','-of','json','-show_format','-show_streams',path]
    cmd_string = subprocess.list2cmdline(cmd)

    print(cmd_string)

    p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    stdout,stderr = p.communicate()
    if p.returncode != 0:
        raise subprocess.CalledProcessError(p.returncode, cmd_string, stderr)

    return json.loads(stdout)


tracks = []

for track in audio_tracks:
    audio_path = audio_tracks_dir + "/" + track['path']
#    audio_info = probe(audio_path)
#    time_reference = int(audio_info['format']['tags']['time_reference'])
#    sample_rate = int(audio_info['streams'][0]['sample_rate'])
    tracks.append({
        'path': audio_path,
        'name': track['path'],
        'timecode': int(track['timecode'])
    })

sorted_audio_tracks = sorted(
    tracks,
    key=lambda x: x['timecode'], reverse=False
)

print("creating aaf file...")
with aaf2.open("public/aaf-files/" + file_name + ".aaf", 'w') as f:

    print("\ncreating CompositionMob...")
    comp_mob = f.create.CompositionMob()
    comp_mob.usage = "Usage_TopLevel"
    comp_mob.name = file_name
    f.content.mobs.append(comp_mob)

    print("creating start Timecode in CompositionMob...")
    start_timecode = 0
    start_tc_slot = comp_mob.create_timeline_slot(edit_rate)
    start_tc = f.create.Timecode(timecode_fps, False)
    start_tc_slot.segment = start_tc

    for index, track in enumerate(sorted_audio_tracks):

        print("\ncreating Sequence...")
        sequence = f.create.Sequence(media_kind='sound')

        print("creating TimelineSlot in CompositionMob...")
        timeline_slot = comp_mob.create_timeline_slot(edit_rate)
        timeline_slot.name = track['name']
        print("appending Sequence to TimelineSlot...")
        timeline_slot.segment = sequence

        print("creating MasterMob...")
        master_mob = f.create.MasterMob()
        master_mob.name = track['name']
        f.content.mobs.append(master_mob)

#        TODO use bwf timeReference after it will be fixed

#        print("audio track info -> time_reference:", track['time_reference'], " sample_rate:", track['sample_rate'])
#        track_start_tc = int(round(track['time_reference'] / track['sample_rate'] * timecode_fps))

        track_start_tc = track['timecode']
        print("audio track start timecode:", track_start_tc)

        if index == 0:
            start_timecode = track_start_tc
            print("updating start Timecode value:", start_timecode)
            start_tc.start = start_timecode

        print("creating Timecode SourceMob...")
        tc_mob = f.create.SourceMob()
        tc_slot = tc_mob.create_timeline_slot(edit_rate)
        tc = f.create.Timecode(timecode_fps, False)
        tc.start = 0
        tc.length = 0
        tc_slot.segment = tc
        print("creating SourceClip to connect Timecode SourceMob and CompositionMob...")
        tm_clip = tc_mob.create_source_clip(slot_id=1, start=0, length=track_start_tc-start_timecode)

        print("creating Tape SourceMob...")
        tape_mob = f.create.SourceMob()
        tape_name = 'tape'+track['name']
        tape_mob.create_tape_slots(tape_name, edit_rate, timecode_fps, media_kind='sound')
        f.content.mobs.append(tape_mob)
        print("creating Tape SourceClip with timecode:", track_start_tc)
        tape_clip = tape_mob.create_source_clip(slot_id=1, start=track_start_tc)

        print("adding audio Essence with Tape to MasterMob: ", track['path'])
        slot = master_mob.import_audio_essence(track['path'], edit_rate, tape_clip)

        print("creating SourceClip to connect MasterMob and CompositionMob...")
        es_clip = master_mob.create_source_clip(slot_id=1)

        print("appending Timecode SourceClip to CompositionMob...")
        sequence.components.append(tm_clip)

        print("appending Essence SourceClip to CompositionMob...")
        sequence.components.append(es_clip)
@zeeshanmazhar
Copy link
Author

@markreidvfx can you please help me on this.

@markreidvfx
Copy link
Owner

import_audio_essence reads the number of audio channels from the wav file, verify that your wav file is mono. You probably need to downmix it mono first, that can be done with ffmpeg.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants