- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想使用字幕 API。它需要视频文件的第一个和最后一个 64kb 的 md5 哈希值。我知道如何做 md5 部分只是想知道我将如何实现获取 128kb 的数据。
这是Java中我无法在Delphi中实现的问题的解决方案。 How to read first and last 64kb of a video file in Java?
到目前为止我的 Delphi 代码:
function TSubdbApi.GetHashFromFile(const AFilename: string): string;
var
Md5: TIdHashMessageDigest5;
Filestream: TFileStream;
Buffer: TByteArray;
begin
Md5 := TIdHashMessageDigest5.Create;
Filestream := TFileStream.Create(AFilename, fmOpenRead, fmShareDenyWrite);
try
if Filestream.Size > 0 then begin
Filestream.Read(Buffer, 1024 * 64);
Filestream.Seek(64, soFromEnd);
Filestream.Read(Buffer, 1024 * 64);
Result := Md5.HashStreamAsHex(Filestream);
end;
finally
Md5.Free;
Filestream.Free;
end;
end;
我没有得到官方 API 所说的准确的 md5 哈希值。 API url here 。我使用的是Delphi XE8。
最佳答案
hash function
该 API 使用的描述如下:
Our hash is composed by taking the first and the last 64kb of the video file, putting all together and generating a md5 of the resulting data (128kb).
我可以看到您的代码中存在一些问题。您正在散列文件流,而不是您的 Buffer 数组。只不过您通过随后从文件流读取来覆盖该数组。并且您试图仅查找 64 个字节,并且超出了流的末尾(您需要使用负值从流的末尾查找)。尝试这样的事情:
type
ESubDBException = class(Exception);
function TSubdbApi.GetHashFromFile(const AFileName: string): string;
const
KiloByte = 1024;
DataSize = 64 * KiloByte;
var
Digest: TIdHashMessageDigest5;
FileStream: TFileStream;
HashStream: TMemoryStream;
begin
FileStream := TFileStream.Create(AFileName, fmOpenRead, fmShareDenyWrite);
try
if FileStream.Size < DataSize then
raise ESubDBException.Create('File is smaller than the minimum required for ' +
'calculating API hash.');
HashStream := TMemoryStream.Create;
try
HashStream.CopyFrom(FileStream, DataSize);
FileStream.Seek(-DataSize, soEnd);
HashStream.CopyFrom(FileStream, DataSize);
Digest := TIdHashMessageDigest5.Create;
try
HashStream.Position := 0;
Result := Digest.HashStreamAsHex(HashStream);
finally
Digest.Free;
end;
finally
HashStream.Free;
end;
finally
FileStream.Free;
end;
end;
关于delphi - 如何在Delphi中读取视频文件的第一个和最后一个64kb?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30225155/
我将文件读入字符串,更改第一行,然后将此字符串写入新文件。我通过以下代码(稍微缩短了一点)来做到这一点: while(jspIterator.hasNext()){
adb shell dumsys meminfo返回的内存是kB还是KB? 哪里: kB = 1000 bytes KB = 1024 bytes 最佳答案 它是 KB(1024 字节)或 ki
我能够解析 xml 文件,并且我想下载 xml 给出的 url 的文件。我有以下代码: try{ /* Create a URL we want to load some xm
这个问题在这里已经有了答案: Android, Compressing an image (2 个答案) 关闭 10 个月前。 我正在 android 中开发一个应用程序,它将捕获照片并存储在 sq
我将文件保存在我的 MySQL 数据库中的 LONGBLOB 列上,当我在我的 IDE 中执行选择时,我注意到一些 base64 文件内容有消息 206.2 kB (204.8 kB loaded)放
使用 Indy 的 TIdTCPServer 组件,一个包被分两部分接收,但客户端发送了一个 64 KB 的包。 如何在服务器 OnExecute 事件中接收完整的包? 现在我放了一个原型(proto
我正在编写一个正则表达式,它可以捕获一个值及其后面的任何 mb、kb、gb、字节正则表达式是: (?\p{N}+)(?:\s*)(?[mb|kb|gb|b|bytes]) 但是当给定输入“40
我刚刚创建了 range(1,100000) 的 python 列表. 使用 SparkContext 完成以下步骤: a = sc.parallelize([i for i in range(1,
我的要求是将相机捕获的图像上传到服务器,但它应该小于 500 KB。如果大于 500 KB,则需要减小到小于 500 KB (但稍微接近) 为此,我使用以下代码 - @Override pub
我有以两种不同方式加载和保存图像的代码-第一种使用openCV,第二种使用PIL。 import cv2 from PIL import Image img = cv2.imread("/home/m
我有一个 android 视频播放器,它显示 SD 卡上的所有视频名称和文件大小,但大小以字节显示,我无法将它转换为 KB、MB、GB 等。我尝试除以 int值增加 1024 但它不起作用。它打印出错
任何人都可以向我解释一下摘要报告中如何测量吞吐量、Kb/秒和平均字节数吗? 我得到了以下登录操作的总结报告。 Label : Login Action(sampler) Sample# : 1 ave
我需要将上传图片的大小调整为最大 100 kB。可能吗? 例如:尺寸为 1200x600 的 image1.jpg 有 280kB,我需要将其调整为 <100kB。 最佳答案 ImageMagick
我需要将上传图片的大小调整为最大 100 kB。可能吗? 例如:尺寸为 1200x600 的 image1.jpg 有 280kB,我需要将其调整为 <100kB。 最佳答案 ImageMagick
我有例如: Document doc = Jsoup.connect("http://example.com/").get(); String title = doc.title(); Documen
我正忙于Android通话录音机,当我调用电话时录音机显示它正在录音,在我挂断电话后,它保存文件,但保存的文件是0 KB 有没有人遇到同样的问题,请帮我解决一下。 这是我的录制代码 recorder
我正在以 KB 为单位将文件存储在数据库中。我尝试将文件信息返回的文件长度转换为 KB,如下所示。 FileInfo FileVol = new FileInfo(DownloadPath); int
在我的应用程序中,显示照片中的所有视频。选择视频后,将使用 avplayer 播放该视频。但是当我尝试获取所选视频文件的大小(kb)时,它显示错误。当我尝试复制视频文件时出现同样的错误。 我已获取这些
我正在尝试在 firebase 存储中上传图像,我希望图像不应大于 50 kb 我正在尝试获取位图的大小,以便我可以知道位图的大小是否超过 50 kb这图片不会显示在画廊中 我已经尝试了许多人建议的代
在我的 android 应用程序中,它收集了一些数据和照片扔手机。 之后它将所有这些东西插入到一个对象中,然后将这个对象发送到服务器。 在将此对象发送到服务器之前,我想向用户显示数据的大小以及将此数据
我是一名优秀的程序员,十分优秀!