Example #1
0
    def movie_info_res(cmdlist, _):
        if len(cmdlist) <= 0:
            modify_state(media_db, MediaHelp.STATE_AUDIO_FINISH)
            return
        jsonbean = json.loads(''.join(cmdlist))
        if 'streams' not in jsonbean.keys():
            modify_state(media_db, MediaHelp.STATE_SRC_ERROR)
            return
        streamlist = jsonbean['streams']
        format = jsonbean['format']
        media_db.md5 = yutils.get_md5(media_db.abs_path)
        media_db.duration = int(float(format['duration']))
        # cur_file_info['duration'] =
        media_db.size = int(format['size'])
        if len(streamlist) <= 0:
            modify_state(media_db, MediaHelp.STATE_AUDIO_FINISH)
            return
        audio_streams = []
        decode_map = ''
        for stream_item in streamlist:
            if stream_item['codec_type'] == 'audio':
                logger.info(str(stream_item))
                audio_streams.append(stream_item)
            else:
                if stream_item['codec_type'] == 'video':
                    # 如果是视频.保存视频信息
                    media_db.codec_type = stream_item['codec_name']
                    media_db.codec_long_name = stream_item['codec_long_name']
                    media_db.width = int(stream_item['width'])
                    media_db.height = int(stream_item['height'])
                    try:
                        media_db.r_frame_rate = round(eval(stream_item['r_frame_rate']))
                        media_db.avg_frame_rate = round(eval(stream_item['avg_frame_rate']))
                    except ZeroDivisionError:
                        media_db.r_frame_rate = 0
                        media_db.avg_frame_rate = 0

                decode_map += ' -map 0:' + str(stream_item['index'])

        # 有多个语种
        digout = False
        if len(audio_streams) > 1:
            for audio_stream in audio_streams:
                if 'tags' in audio_stream and 'title' in audio_stream['tags'] \
                        and ('国语' == audio_stream['tags']['title'] or '中语' == audio_stream['tags']['title']):
                    decode_map += ' -map 0:' + str(audio_stream['index'])
                    digout = True
                    break
        else:
            logger.info('该视频音轨只有一个,不需要转换:' + media_db.abs_path)
            modify_state(media_db, MediaHelp.STATE_AUDIO_FINISH)
            return

        if not digout:
            for audio_stream in audio_streams:
                decode_map += ' -map 0:' + str(audio_stream['index'])
            #     out_content += str(index) + ':' + str(audio_stream) + '\n'
            #     index += 1
            # select_audio = len(audio_streams)
            # while len(audio_streams) <= select_audio or select_audio < 0:
            #     select_audio = int(input(out_content + '选择音轨:'))

        # desc_file = file +
        mulit_audio_path = TmpUtil.src() / movie_config.base_info.mulit_audio_dir
        desc_mulit_path = ypath.decompose_path(media_db.abs_path, str(media_src_root), str(mulit_audio_path))
        out_file = desc_mulit_path + '.chi' + ypath.file_exten(media_db.abs_path)
        ypath.create_dirs(desc_mulit_path)
        if os.path.exists(out_file):
            os.remove(out_file)
        logger.info(out_file)

        copy_cmd = ffmpeg_tools + ' -i \"' + media_db.abs_path + '\"' + decode_map + '  -vcodec copy -acodec copy \"' + out_file + '\"'
        yutils.process_cmd(copy_cmd, done_call=rm_on_audio_copy, param=(media_db.abs_path, out_file, desc_mulit_path))
Example #2
0
            if middle_path in right_map:
                pass  # print('' + source_path + "  src:" + right_map[source_path])
            else:
                thum_path = thum + middle_path[len(middle):]
                if os.path.exists(middle_path):
                    os.remove(middle_path)
                if os.path.exists(thum_path):
                    os.remove(thum_path)
                print('删除文件:', middle_path, thum_path)
    ypath.del_none_dir(middle)
    ypath.del_none_dir(thum)
    print('[delete_not_exist] end')


if __name__ == '__main__':
    src = TmpUtil.src()
    src = ypath.join(src, pic_cfg.dir_root)
    desc = TmpUtil.desc()

    desc = ypath.join(desc, pic_cfg.dir_root)

    gif_space = TmpUtil.input_note(GIF_SPACE, '请指定gif的占位符的图片位置:\n')

    logger.info('初始化成功src:', src, ',desc:', desc, 'gif_space:', gif_space)

    middle = ypath.join(desc, pic_cfg.middle)
    thum = ypath.join(desc, pic_cfg.thum)
    other_file.clear()

    # 去重
    ypath.delrepeat_file(src)
Example #3
0
from MryangService import ServiceHelper
from Mryang_App.models import Media, Dir
from Mryang_App.DBHelper import MediaHelp
from frames import ypath, TmpUtil, yutils, Globals, logger
from frames.xml import XMLBase
from django.db import transaction

FFMPEG_KEY = 'FFMPEG_KEY'
FFPROBE_KEY = 'FFPROBE_KEY'

movie_config = XMLBase.list_cfg_infos('media_info')  # XMLMedia.get_infos()

ffmpeg_tools = str(TmpUtil.input_note(FFMPEG_KEY, '输入对应的ffmpeg文件位置(参照link_gitProj_files.txt下载对应的文件):\n'))
ffprobe_tools = str(TmpUtil.input_note(FFPROBE_KEY, '输入对应的ffprobe文件位置(参照link_gitProj_files.txt下载对应的文件):\n'))
# 视频源路径
media_src_root = TmpUtil.src() / movie_config.dir_root

# 视频转码目标路径
convert_root = TmpUtil.desc() / movie_config.dir_root
# 转码结束后的切片路径
m3u8_ts_root = TmpUtil.desc() / movie_config.m3u8_info.ts_dir

src_dbs = []

cur_file_info = {}

# 获取同步状态
sync_control = False


def cur_state():