当前位置: 首页> 文旅> 艺术 > 苏州中心有什么好玩的_建设网站的公司兴田德润可以吗_可以直接打开网站的网页_天天seo站长工具

苏州中心有什么好玩的_建设网站的公司兴田德润可以吗_可以直接打开网站的网页_天天seo站长工具

时间:2025/7/13 14:10:12来源:https://blog.csdn.net/weilaozongge/article/details/147245725 浏览次数:0次
苏州中心有什么好玩的_建设网站的公司兴田德润可以吗_可以直接打开网站的网页_天天seo站长工具

下面这个脚本会使用 ffmpegffprobe 检查两个视频文件在以下方面是否“实质相同”:


✅ 检查内容:

  1. 分辨率(宽高)
  2. 帧率
  3. 视频总帧数
  4. 音频轨道数量和采样率
  5. 视频时长
  6. 视频帧哈希(可选) — 对比前 N 帧的图像感知哈希,判断是否完全一致(更精确)

🧰 脚本需求:

确保已安装:

sudo apt install ffmpeg
pip install imagehash Pillow

🐍 Python 脚本如下:

import subprocess
import json
import imagehash
from PIL import Image
import osdef ffprobe_info(path):cmd = ['ffprobe', '-v', 'error', '-show_entries','format=duration', '-show_streams','-of', 'json', path]output = subprocess.check_output(cmd)return json.loads(output)def extract_frame(path, frame_num, output_path):cmd = ['ffmpeg', '-y', '-i', path,'-vf', f'select=eq(n\,{frame_num})','-vframes', '1', output_path]subprocess.run(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)def compare_hashes(file1, file2, frames_to_check=5):for i in range(frames_to_check):extract_frame(file1, i * 10, 'frame1.jpg')extract_frame(file2, i * 10, 'frame2.jpg')try:h1 = imagehash.average_hash(Image.open('frame1.jpg'))h2 = imagehash.average_hash(Image.open('frame2.jpg'))if h1 != h2:print(f"[❌] Frame {i*10} differs: {h1} vs {h2}")return Falseexcept Exception as e:print(f"[⚠️] Error comparing frame {i*10}: {e}")return Falseprint("[✅] Frame hashes match.")return Truedef compare_videos(src, dst):info1 = ffprobe_info(src)info2 = ffprobe_info(dst)def get_val(info, stream_type, key):for stream in info['streams']:if stream['codec_type'] == stream_type:return stream.get(key)return Nonecomparisons = [('Resolution', f"{get_val(info1, 'video', 'width')}x{get_val(info1, 'video', 'height')}",f"{get_val(info2, 'video', 'width')}x{get_val(info2, 'video', 'height')}"),('Frame rate', get_val(info1, 'video', 'r_frame_rate'),get_val(info2, 'video', 'r_frame_rate')),('Audio rate', get_val(info1, 'audio', 'sample_rate'),get_val(info2, 'audio', 'sample_rate')),('Duration (s)', round(float(info1['format']['duration']), 2),round(float(info2['format']['duration']), 2)),]all_match = Truefor name, val1, val2 in comparisons:match = "✅" if val1 == val2 else "❌"print(f"[{match}] {name}: {val1} vs {val2}")if val1 != val2:all_match = Falseprint("\n🔍 Checking frame visual hashes (first few frames)...")if not compare_hashes(src, dst):all_match = Falseif all_match:print("\n🎉 视频文件在核心内容上完全一致")else:print("\n⚠️ 视频存在差异")# 清理临时文件os.remove('frame1.jpg') if os.path.exists('frame1.jpg') else Noneos.remove('frame2.jpg') if os.path.exists('frame2.jpg') else None# 使用示例
compare_videos("yanhuorenjia_12_src.mp4", "yanhuorenjia_12_dst.mp4")

💡 说明:

  • 它会提取每个视频的前 5 帧(间隔取)做图像哈希对比,适合检查是否重新编码或压缩。
  • 如果帧、音频、时长、分辨率都一样且图像一致,那可以认为视频实质相同。
  • 支持大视频,速度也不错。
关键字:苏州中心有什么好玩的_建设网站的公司兴田德润可以吗_可以直接打开网站的网页_天天seo站长工具

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: