def _create_and_upload_ru_mono_video(orig_mp4_filename, ts_title_filename,
                                     ts_rest_filename):
    concat_str = _get_concat_args(ts_title_filename, ts_rest_filename)
    ru_mono_titled_mp4_filename = meta.get_work_filename(
        orig_mp4_filename, ' ru_mono titled.mkv')
    cmd = [
        'D:\\video\\GoswamiMj-videos\\ffmpeg-hi8-heaac.exe', '-y', '-i',
        concat_str
    ]
    cmd += ffmpeg.ss_args(orig_mp4_filename)
    cmd += ['-i', meta.get_work_filename(orig_mp4_filename, ' ru_mixdown.wav')]
    cmd += ['-c:v', 'copy']
    cmd += ['-c:a', 'libfdk_aac']
    cmd += ['-ac', '1']  # mono
    cmd += ffmpeg.to_args(orig_mp4_filename)
    cmd += ['-shortest']
    cmd += [ru_mono_titled_mp4_filename]
    os.chdir('D:\\video\GoswamiMj-videos')
    subprocess.run(cmd, check=True)
    os.chdir('C:\\Users\\ashutosh\\Dropbox\\Reference\S\scripts')

    title = meta.get_youtube_title_ru_mono(orig_mp4_filename)
    description = meta.get_youtube_description_ru_mono(orig_mp4_filename)
    youtube_id = my_youtube.upload(ru_mono_titled_mp4_filename,
                                   title=title,
                                   description=description,
                                   lang='ru')
    meta.update_yaml(orig_mp4_filename, 'youtube_id_rus_mono', youtube_id)
Exemple #2
0
def _create_and_upload_ru_mono_video(orig_mp4_filename):
    ru_mono_m4a_filename = meta.get_work_filename(orig_mp4_filename,
                                                  ' ru_mono.m4a')
    cmd = [
        'D:\\video\\GoswamiMj-videos\\ffmpeg-hi8-heaac.exe', '-y', '-i',
        meta.get_work_filename(orig_mp4_filename,
                               ' ru_mixdown.wav'), '-c:a', 'libfdk_aac', '-ac',
        '1', '-b:a', '128k', '-metadata:s:a:0', 'language=rus'
    ]
    cmd += ffmpeg.meta_args_ru_mono(orig_mp4_filename)
    cmd += [ru_mono_m4a_filename]
    subprocess.run(cmd, check=True)

    ru_mono_video_filename = meta.get_work_filename(orig_mp4_filename,
                                                    ' ru_mono.mkv')
    cmd = [
        'ffmpeg', '-y', '-i', orig_mp4_filename, '-i', ru_mono_m4a_filename,
        '-map', '0:v', '-map', '1:a', '-c', 'copy'
    ]
    cmd += ffmpeg.meta_args_ru_mono(orig_mp4_filename)
    cmd += ffmpeg.ss_args(orig_mp4_filename)
    cmd += ffmpeg.to_args(orig_mp4_filename)
    cmd += [ru_mono_video_filename]
    subprocess.run(cmd, check=True)

    title = meta.get_youtube_title_ru_mono(orig_mp4_filename)
    description = meta.get_youtube_description_ru_mono(orig_mp4_filename)
    youtube_id = my_youtube.upload(ru_mono_video_filename,
                                   title=title,
                                   description=description,
                                   lang='ru')
    meta.update_yaml(orig_mp4_filename, 'youtube_id_rus_mono', youtube_id)
def _create_mp3_ru_stereo(filename):
    cmd = [
        'ffmpeg', '-y', '-i',
        (meta.get_work_filename(filename, ' ru_mixdown.wav')), '-codec:a',
        'mp3', '-b:a', '128k'
    ]
    cmd += ffmpeg.ss_args(filename)
    cmd += ffmpeg.to_args(filename)
    cmd += ffmpeg.meta_args_ru_stereo(filename)
    cmd += [meta.get_work_filename(filename, ' ru_stereo.mp3')]
    subprocess.run(cmd, check=True)
Exemple #4
0
def main():
    filename = sys.argv[1]
    # make_title_mp4(filename, meta.get_lang(filename))
    # make_rest_mp4(filename, meta.get_lang(filename))
    # get_keyframes_timestamps(filename)
    lang = meta.get_lang(filename)
    cut_video_filename = meta.get_work_filename(filename,
                                                ' {} titled.mp4'.format(lang))
    make_mp4_with_title(filename, lang, cut_video_filename)
    cut_video_filename_ru = meta.get_work_filename(
        filename, ' {} titled.mp4'.format('ru'))
    make_mp4_with_title(filename, 'ru', cut_video_filename_ru)
def orig_titled(orig_mp4_filename):
    """Prepare all files in original language: m4a, mp4, mp3"""
    lang = meta.get_lang(orig_mp4_filename)

    # first we cut m4a and mp4 version sequentially because these are
    # IO-bound tasks on the single drive, so running them in parallel
    # doesn't make much sense.
    _cut_orig_m4a(orig_mp4_filename, lang, line=0)
    cut_video_filename = meta.get_work_filename(orig_mp4_filename, ' ' + lang + ' titled.mkv')
    _cut_orig_mp4_titled(orig_mp4_filename, cut_video_filename, lang, line=1)

    # And now we run two long-running tasks (uploading to youtube
    # and encoding mp3) in parallel

    p_upload_orig_mp4 = multiprocessing.Process(
        target=_upload_orig_mp4,
        kwargs={'orig_mp4_filename': orig_mp4_filename, 'cut_video_filename': cut_video_filename, 'lang': lang, 'line': 2})
    p_upload_orig_mp4.start()

    p_encode_orig_mp3 = multiprocessing.Process(
        target=_encode_orig_mp3,
        kwargs={'orig_mp4_filename': orig_mp4_filename, 'lang': lang, 'line': 3})
    p_encode_orig_mp3.start()

    p_upload_orig_mp4.join()
    p_encode_orig_mp3.join()
def _cut_orig_m4a(orig_mp4_filename, lang, line):
    cmd = ['ffmpeg', '-y',
           '-i', orig_mp4_filename]
    cmd += ffmpeg.meta_args(orig_mp4_filename, lang)
    cmd += ffmpeg.ss_args(orig_mp4_filename)
    cmd += ffmpeg.to_args(orig_mp4_filename)
    cmd += ['-c:a', 'copy', '-vn',
            meta.get_work_filename(orig_mp4_filename, ' ' + lang + '.m4a')]
    _run_ffmpeg_at_line(cmd, line, 'm4a')
def _encode_orig_mp3(orig_mp4_filename, lang, line):
    cmd = ['ffmpeg', '-y',
           '-i', orig_mp4_filename,
           '-ac', '1',
           '-codec:a', 'mp3', '-b:a', '96k']
    cmd += ffmpeg.ss_args(orig_mp4_filename)
    cmd += ffmpeg.to_args(orig_mp4_filename)
    cmd += ffmpeg.meta_args(orig_mp4_filename, lang)
    cmd += [meta.get_work_filename(orig_mp4_filename, ' ' + lang + '.mp3')]
    _run_ffmpeg_at_line(cmd, line, 'mp3')
Exemple #8
0
def make_rest_ts(orig_mp4_filename, lang, title_end_time):
    ts_rest_filename = meta.get_work_filename(
        orig_mp4_filename, ' {lang}_rest.ts'.format(lang=lang))
    cmd = [
        'ffmpeg', '-y', '-i', orig_mp4_filename, '-c', 'copy', '-bsf:v',
        'h264_mp4toannexb'
    ]
    cmd += ['-ss', str(title_end_time)]
    cmd += ffmpeg.to_args(orig_mp4_filename)
    cmd += [ts_rest_filename]
    print(cmd)
    subprocess.run(cmd)
    return ts_rest_filename
Exemple #9
0
def make_title_ts(orig_mp4_filename, lang, seconds):
    png_filename = make_png(orig_mp4_filename, lang)
    ts_title_filename = meta.get_work_filename(
        orig_mp4_filename, ' {lang}_title.ts'.format(lang=lang))

    filter_complex = ''
    filter_complex += ';[1:v]fade=out:st=9:d=1:alpha=1[title]'
    filter_complex += ';[0:v][title]overlay,format=yuv420p'
    filter_complex = filter_complex[1:]
    cmd = ['ffmpeg', '-y']
    cmd += ffmpeg.ss_args(orig_mp4_filename)
    cmd += [
        '-i', orig_mp4_filename, '-loop', '1', '-i', png_filename,
        '-filter_complex', filter_complex, '-bsf:v', 'h264_mp4toannexb', '-t',
        str(seconds)
    ]
    cmd += get_ffmpeg_encoding_options_from_video_file(orig_mp4_filename)
    cmd += [ts_title_filename]
    print(cmd)
    subprocess.run(cmd)
    return ts_title_filename
Exemple #10
0
def make_png(orig_mp4_filename, lang):
    png_filename = meta.get_work_filename(orig_mp4_filename,
                                          ' ' + lang + '_title.png')

    [width, height] = get_video_size(orig_mp4_filename)
    scale = float(height) / 720

    authors = meta.get_artist(orig_mp4_filename, lang, 100)
    author_srt = meta.get_work_filename(orig_mp4_filename,
                                        ' ' + lang + '_author.srt')
    with open(author_srt, 'w', encoding='utf8') as f:
        f.write('1\n00:00:00,000 --> 09:59:59,990\n' + authors)
    author_srt_escaped = author_srt.replace('\\', '/')
    author_srt_escaped = author_srt_escaped.replace(':', '\\\\:')
    f_author = (
        'subtitles=filename={srt}' +
        ':force_style=\'FontName=Charis SIL,Fontsize={fontsize},' +
        'Alignment=10,PlayResX={width},PlayResY={height},PrimaryColour=&Hffffff\''
    ).format(srt=author_srt_escaped,
             fontsize=int(60 * scale),
             width=width,
             height=height)
    f_shift_down = (
        'crop={width}:{height}-{shift}:0:0,pad={width}:{height}:0:{shift}:[email protected]'
    ).format(shift=int(200 * scale), width=width, height=height)

    title = meta.get_title(orig_mp4_filename, lang)
    title_srt = meta.get_work_filename(orig_mp4_filename,
                                       ' ' + lang + '_title.srt')
    with open(title_srt, 'w', encoding='utf8') as f:
        f.write('1\n00:00:00,000 --> 09:59:59,990\n' + title)
    title_srt_escaped = title_srt.replace('\\', '/')
    title_srt_escaped = title_srt_escaped.replace(':', '\\\\:')
    f_title = (
        'subtitles=filename={srt}' +
        ':force_style=\'FontName=Charis SIL,Fontsize={fontsize},' +
        'Alignment=10,PlayResX={width},PlayResY={height},PrimaryColour=&Hffffff\''
    ).format(srt=title_srt_escaped,
             fontsize=int(108 * scale),
             width=width,
             height=height)
    f_shift_up = (
        'crop={width}:{height}-{shift}:0:{shift},pad={width}:{height}:0:0:[email protected]'
    ).format(shift=int(80 * scale), width=width, height=height)

    f_transparent = 'geq=r=r(X\,Y):a=if(r(X\,Y)\,r(X\,Y)\,16)'
    filter_complex = ''
    filter_complex += ',' + f_author
    filter_complex += ',' + f_shift_down
    filter_complex += ',' + f_title
    filter_complex += ',' + f_shift_up
    filter_complex += ',' + f_transparent
    filter_complex = filter_complex[1:]
    cmd = [
        'ffmpeg', '-f', 'lavfi', '-i',
        'color=c=black:s={width}x{height}:d=10,format=rgba'.format(
            width=width, height=height), '-filter_complex', filter_complex,
        '-frames:v', '1', '-y', png_filename
    ]
    os.environ[
        'FONTCONFIG_FILE'] = 'C:\\Users\\ashutosh\\Dropbox\\Reference\\S\\scripts\\fonts\\fonts.conf'
    subprocess.run(cmd)
    os.remove(author_srt)
    os.remove(title_srt)
    return png_filename
Exemple #11
0
def demux_file(orig_mp4_filename: str) -> None:
    cmd = [
        'ffmpeg', '-y', '-i', orig_mp4_filename, '-c:a', 'copy', '-vn',
        meta.get_work_filename(orig_mp4_filename, '.m4a')
    ]
    subprocess.run(cmd, check=True)