# Path: comm.py
# def echo(*args):
#     sys.stdout.write(" ".join(map(str, args)) + "\n")
#     sys.stdout.flush()


import os
import sys
import shutil
from time import sleep
from subprocess import Popen, PIPE, CalledProcessError
from comm import echo
               "-y", "-c", "copy", "%s.%s" % (name, ext)])
    p.wait()


tss = ('ts', 'x-mpeg-ts', 'mp2t', 'MP2T')


def find_tool():
    p = Popen(['which', 'ffmpeg'])
    p.wait()
    if p.returncode == 0:
        return "ffmpeg"

    p = Popen(['which', 'avconv'])
    p.wait()
    if p.returncode == 0:
        return "avconv"
    return ""


def merge(name, ext, cnt, clean=False, ists=False):
    # ext = 'x-mpeg-ts'
    # avconv -i 12.mp4 -c copy -f mpegts -bsf h264_mp4toannexb - > aa.ts
    oex = ext
    if ext in tss:
        ists = True
        oex = "mp4"
    outfn = "%s.%s" % (name, oex)
    mrgfn = "%s.mrg.%s" % (name, oex)
    if os.path.exists(outfn):

# Path: comm.py
# def echo(*args):
#     sys.stdout.write(" ".join(map(str, args)) + "\n")
#     sys.stdout.flush()


# Path: merge.py
import os
import sys
import shutil
from time import sleep
from subprocess import Popen, PIPE, CalledProcessError
from comm import echo

               "-y", "-c", "copy", "%s.%s" % (name, ext)])
    p.wait()


tss = ('ts', 'x-mpeg-ts', 'mp2t', 'MP2T')


def find_tool():
    p = Popen(['which', 'ffmpeg'])
    p.wait()
    if p.returncode == 0:
        return "ffmpeg"

    p = Popen(['which', 'avconv'])
    p.wait()
    if p.returncode == 0:
        return "avconv"
    return ""


def merge(name, ext, cnt, clean=False, ists=False):
    # ext = 'x-mpeg-ts'
    # avconv -i 12.mp4 -c copy -f mpegts -bsf h264_mp4toannexb - > aa.ts
    oex = ext
    if ext in tss:
        ists = True
        oex = "mp4"
    outfn = "%s.%s" % (name, oex)
    mrgfn = "%s.mrg.%s" % (name, oex)
    if os.path.exists(outfn):

        echo(outfn, "exists")