コード例 #1
0
def read_thum():
    Dir.objects.filter(type=yutils.M_FTYPE_PIC).delete()
    desc = ypath.join(TmpUtil.desc(), pic_cfg.dir_root)

    dict = ypath.path_result(desc, pic_cfg.thum, add_root=False)
    dir_dict = {}
    file_dict = {}
    for key in dict:
        if dict[key][ypath.KEYS.IS_DIR]:
            dir_dict[key] = dict[key]
        else:
            file_dict[key] = dict[key]

    dir_list = sorted(dir_dict.items(), key=lambda d: d[1][ypath.KEYS.LEVEL])
    file_list = sorted(file_dict.items(), key=lambda d: d[1][ypath.KEYS.LEVEL])

    file_db_list = insert_db(dir_list, file_list)
    Dir.objects.bulk_create(file_db_list)
コード例 #2
0
def create_thum(media_db):
    if MediaHelp.is_err(media_db.state):
        return
    media_tum_root = TmpUtil.desc() / movie_config.img_info.img_root
    # convert_root
    # if media_db.state >= MediaHelp.STATE_VIDEO_THUM:
    #     logger.info('该文件已经转缩略图过了:' + media_db.abs_path)
    #     return
    target_img_dir = ypath.decompose_path(media_db.desc_path, str(convert_root), media_tum_root)
    target_img_dir = ypath.del_exten(target_img_dir)
    ypath.create_dirs(target_img_dir)
    desc = ypath.join(target_img_dir, movie_config.img_info.img)
    desc_thum = ypath.join(target_img_dir, movie_config.img_info.thum)
    if os.path.exists(desc) and os.path.exists(desc_thum):
        logger.info('该视频不需要做缩略图裁切,因为已有:%s' % desc)
        return
    # 裁切缩略图的比例
    thum_percent = int(movie_config.base_info.thum_w) / int(movie_config.base_info.thum_h)

    max_thum_time = int(movie_config.base_info.max_thum_time)
    min_thum_time = int(movie_config.base_info.min_thum_time)

    ypath.create_dirs(desc)

    r_time = random.randint(min_thum_time if media_db.duration > min_thum_time else 0,
                            max_thum_time if media_db.duration > max_thum_time else media_db.duration)
    cmd = ffmpeg_tools + ' -i \"' + media_db.desc_path + '\" -y  -vframes 1 -ss  00:00:' + str(
        r_time) + ' -f image2  \"' + desc + '\"'
    yutils.process_cmd(cmd)
    if not os.path.exists(desc):
        return
    img = Image.open(desc)
    w, h = img.size
    crop_img = img.crop(yutils.crop_size(w, h, thum_percent))
    crop_img.save(desc_thum)
    pass
コード例 #3
0
            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)
    # 去掉middle中的图.
    delete_not_exist()
コード例 #4
0
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():
    db = cur_file_info.get('db')
    cur_state_info = {}