当前位置: 首页 > news >正文

长春视频剪辑培训机构公司百度官网优化

长春视频剪辑培训机构,公司百度官网优化,南宁做网站开发的公司,医保微信小程序是什么这些函数是用于处理视频文件的Python代码片段,它们依赖于ffmpeg和ffprobe工具,这些工具是FFmpeg项目的一部分,用于处理视频和音频数据。下面是每个函数的用途和用法的总结: 1. ffmpeg_installed() 函数: - 用途&am…

这些函数是用于处理视频文件的Python代码片段,它们依赖于`ffmpeg`和`ffprobe`工具,这些工具是`FFmpeg`项目的一部分,用于处理视频和音频数据。下面是每个函数的用途和用法的总结:

1. `ffmpeg_installed()` 函数:
   - 用途:检查系统是否安装了`ffmpeg`工具。
   - 用法:调用此函数无需参数,它会返回一个布尔值,指示`ffmpeg`是否可用。

2. `video_is_playable(video_filepath: str)` 函数:
   - 用途:确定视频文件是否可以在浏览器中播放。
   - 用法:传入视频文件的路径作为字符串,函数会检查视频的容器格式和编解码器是否符合浏览器的播放标准(如`.mp4`容器使用`h264`编解码器,`.webm`容器使用`vp9`编解码器等)。如果视频符合标准,则返回`True`,否则返回`False`。

3. `convert_video_to_playable_mp4(video_path: str)` 函数:
   - 用途:将视频转换为浏览器可以播放的MP4格式。
   - 用法:传入视频文件的路径作为字符串,函数会尝试将视频转换为MP4格式。如果转换过程中出现错误,则返回原始视频路径。

4. `get_video_length(video_path: str | Path)` 函数:
   - 用途:获取视频文件的时长。
   - 用法:传入视频文件的路径,函数会使用`ffprobe`工具来获取视频的时长,并以秒为单位返回一个浮点数。

这些函数的实现依赖于外部命令行工具`ffmpeg`和`ffprobe`,因此在使用这些函数之前,需要确保这些工具已经正确安装在系统上。此外,代码中还包含了一些错误处理机制,以确保在处理视频文件时能够优雅地处理异常情况。例如,如果`ffmpeg`或`ffprobe`命令失败,或者视频文件的格式不符合预期,函数会返回原始视频路径或抛出异常。
IS_WASM = sys.platform == "emscripten"

def ffmpeg_installed() -> bool:
    if wasm_utils.IS_WASM:
        # TODO: Support ffmpeg in WASM
        return False

    return shutil.which("ffmpeg") is not None


def video_is_playable(video_filepath: str) -> bool:
    """Determines if a video is playable in the browser.

    A video is playable if it has a playable container and codec.
        .mp4 -> h264
        .webm -> vp9
        .ogg -> theora
    """
    from ffmpy import FFprobe, FFRuntimeError

    try:
        container = Path(video_filepath).suffix.lower()
        probe = FFprobe(
            global_options="-show_format -show_streams -select_streams v -print_format json",
            inputs={video_filepath: None},
        )
        output = probe.run(stderr=subprocess.PIPE, stdout=subprocess.PIPE)
        output = json.loads(output[0])
        video_codec = output["streams"][0]["codec_name"]
        return (container, video_codec) in [
            (".mp4", "h264"),
            (".ogg", "theora"),
            (".webm", "vp9"),
        ]
    # If anything goes wrong, assume the video can be played to not convert downstream
    except (FFRuntimeError, IndexError, KeyError):
        return True


def convert_video_to_playable_mp4(video_path: str) -> str:
    """Convert the video to mp4. If something goes wrong return the original video."""
    from ffmpy import FFmpeg, FFRuntimeError

    try:
        with tempfile.NamedTemporaryFile(delete=False) as tmp_file:
            output_path = Path(video_path).with_suffix(".mp4")
            shutil.copy2(video_path, tmp_file.name)
            # ffmpeg will automatically use h264 codec (playable in browser) when converting to mp4
            ff = FFmpeg(
                inputs={str(tmp_file.name): None},
                outputs={str(output_path): None},
                global_options="-y -loglevel quiet",
            )
            ff.run()
    except FFRuntimeError as e:
        print(f"Error converting video to browser-playable format {str(e)}")
        output_path = video_path
    finally:
        # Remove temp file
        os.remove(tmp_file.name)  # type: ignore
    return str(output_path)


def get_video_length(video_path: str | Path):
    if wasm_utils.IS_WASM:
        raise wasm_utils.WasmUnsupportedError(
            "Video duration is not supported in the Wasm mode."
        )
    duration = subprocess.check_output(
        [
            "ffprobe",
            "-i",
            str(video_path),
            "-show_entries",
            "format=duration",
            "-v",
            "quiet",
            "-of",
            "csv={}".format("p=0"),
        ]
    )
    duration_str = duration.decode("utf-8").strip()
    duration_float = float(duration_str)

    return duration_float

http://www.ds6.com.cn/news/19729.html

相关文章:

  • 张家口网站建设哪家服务好网站建设企业
  • 微信分销网站开发搜索引擎入口大全
  • 小说网站搭建教程开鲁网站seo站长工具
  • wordpress自由定制导航郑州seo使用教程
  • 山西推广网站建设2021百度新算法优化
  • 微信网站开发 新闻windows7优化大师官方下载
  • 有个能写文章做任务的网站深圳网站seo优化
  • 移动网站虚拟主机石家庄最新消息
  • 网站后台软件可以自己做吗百度seo如何优化
  • 杭州自适应网站建设电商平台开发
  • 备案 手机网站seo教程搜索引擎优化
  • 扬州哪里做网站域名反查
  • 中国建设银行网站多少seo营销服务
  • 自己可以做网站空间吗四川最好的网络优化公司
  • 揭阳专业的网站建设价格网站建设需要多少钱?
  • 宿迁怎样建设网站搜索引擎优化指的是什么
  • 阿里云wordpress很慢seo搜论坛
  • 义乌外贸网站建设来啦国家免费技能培训官网
  • ASP网站开发步骤与过程优化营商环境个人心得体会
  • wordpress插件影响网站网络新闻发布平台
  • 承德做网站安卓aso
  • 专业网站制作公司排行西安网站建设网络推广
  • 随州网站seo诊断关键词包括哪些内容
  • 网页版微信登录入口手机seo关键词排名优化价格
  • 做网站 域名如何要回软文素材
  • seo外包公司优化厦门seo网络推广
  • 怎么把做的网页放入网站12月10日新闻
  • 响应式网站框架网页设计学生作业模板
  • 专题网站怎么做百度快照推广有效果吗
  • 用照片做视频的网站东莞seo技术