Skip to content

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

Open
@zeeshanmazhar

Description

@zeeshanmazhar

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions