Exemplo n.º 1
0
def run_init():
    development_id = TmpUtil.get(DEVELOPMENT_TYPE_KEY, -1)
    while development_id not in development_type:
        development_id = int(input('请指定开发场景%s:\n' % str(development_type)))
    TmpUtil.set(DEVELOPMENT_TYPE_KEY, development_id, False)
    if development_id == HOME_MINI:
        global USE_LOCAL_DB
        USE_LOCAL_DB = False
Exemplo n.º 2
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)
Exemplo n.º 3
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
Exemplo n.º 4
0
import sys

import time

from frames import TmpUtil
# 强大debug:pysnooper


def logname():
    return time.strftime('%Y-%m-%d %H_%M_%S', time.localtime()) + '.log'


logger = logging.getLogger()
logger.setLevel(logging.INFO)
file_handler = logging.FileHandler(TmpUtil.log_path(logname()))
console_handler = logging.StreamHandler()
file_formatter = logging.Formatter(
    '[%(asctime)s][%(filename)s:%(lineno)d]%(levelname)s: %(message)s')
file_handler.setFormatter(file_formatter)
# console_formatter = logging.Formatter(
#     '[%(asctime)s][%(filename)s:%(lineno)d]%(levelname)s: %(message)s')
console_handler.setFormatter(file_formatter)
logger.addHandler(file_handler)
logger.addHandler(console_handler)


def error(*args):
    log(logging.ERROR, *args)

Exemplo n.º 5
0
from MryangService import ServiceHelper
from MryangService.mpath import MediaPath
from MryangService.utils import EmailUtil
from Mryang_App.DBHelper import MediaHelp

# 这里需要制作一下 删除src没有的所有文件文件夹. 是否需要抽出成一个公共函数?
from Mryang_App.models import Media, MPath, Dir
from frames import yutils, ypath, logger, Globals, TmpUtil
from frames.xml import XMLBase

FFMPEG_KEY = 'FFMPEG_KEY'
FFPROBE_KEY = 'FFPROBE_KEY'
movie_config = XMLBase.list_cfg_infos('media_info')  # XMLMedia.get_infos()
src_root = movie_config.dir_root
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'))
mulit_audio_dir = movie_config.base_info.mulit_audio_dir

lock = threading.Lock()


def src_dbs():
    return MediaPath.pdc().src_list


def media_root(dir_root):
    return ypath.join(dir_root, src_root)
Exemplo n.º 6
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)
Exemplo n.º 7
0
def dev_space():
    development_id = TmpUtil.get(DEVELOPMENT_TYPE_KEY, -1)
    return development_id
Exemplo n.º 8
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))
Exemplo n.º 9
0
import shutil
import threading
from PIL import Image
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