将视频转换为帧,然后返回视频而无需更改python中的帧 [英] Covert video to frames, then back to video without altering the frames in python

查看:73
本文介绍了将视频转换为帧,然后返回视频而无需更改python中的帧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用python编写脚本,该脚本将视频(让该视频为 X )转换为帧( X'),然后再转换为同一视频( Y ).现在,当我将视频 Y 分解回帧( Y')时,图像不等于 X'帧,即它们具有不同的哈希值.我希望它们是相同的,并且如果预期的行为不相同,该如何使它们相同?

I am writing a script in python that converts a video (let this video be X) into frames (X′) and then back into the same video (Y). Now, when I break video Y back into frames (Y′) the images are not equal to X′ frames i.e. they have different hashes. I would expect them to be the same, and if being not the same is the expected behaviour, how can I make them the same?

有没有路可走

`视频, X ->帧 X',->视频 Y ,->帧 Y',->视频 Z ,->帧, Z'

`video, X --> frames, X′, --> video, Y, --> frames, Y′, --> video, Z, --> frames, Z′

等,而不会更改其先前状态的输出,例如视频 X Y Z 和帧 X' Y' Z'在各自的集合中彼此相同?

and so on without changing the output from its previous state such the videos X, Y, Z and frames X′, Y′, Z′ are same to each other in their respective sets?

我尝试了多种视频编解码器(mp4,avi,mkv)和图像格式(tif,jpeg,png).据我了解,有损压缩编解码器也不应该通过无损工作,例如tif也不会产生一致的输出.

I have tried multiple video codecs (mp4, avi, mkv) and image formats (tif, jpeg, png). To my understanding, lossy compression codecs should not work by lossless such as tif are not producing consistent output either.

我已经关注了这些帧到视频等其他教程,但无济于事.任何帮助将不胜感激.

I have followed these video-to-frame and frame-to-video among other tutorials but to no avail. Any help would greatly be appreciated.

推荐答案

这是由于发电损失,也可能色彩空间转换和

This is due to generation loss and possibly also colorspace conversion and chroma-subsampling. You must use a lossless workflow that also supports your colorspace (or "pixel format").

示例:

  1. 输出无损图像格式:

  1. Output a lossless image format:

ffmpeg -i input.mp4 x_%02d.tiff

使用 ffmpeg -h encoder = tiff 查看受支持的像素格式列表.

See a list of supported pixel formats with ffmpeg -h encoder=tiff.

使用 framehash多路复用器获取帧散列:

Obtain frame hashes using the framehash muxer:

ffmpeg -v error -i x_%02d.tiff -f framehash -hash md5 -
#stream#, dts,        pts, duration,     size, hash
0,          0,          0,        1,   230400, 56a4401ee8f46ef4205508ab06926bdc
0,          1,          1,        1,   230400, 3ff51f5bef6dbf619fd0469bd29f63ec
0,          2,          2,        1,   230400, ef51487b9905ecb4638c9901251a1dde

  • 使用无损编码器对视频进行编码:

  • Encode video using a lossless encoder:

    ffmpeg -framerate 25 -i x_%02d.tiff -c:v ffv1 video_y.mkv
    

  • 输出无损图像格式:

  • Output a lossless image format:

    ffmpeg -i video_y.mkv y_%02d.tiff
    

  • 获得框架散列:

  • Obtain frame hashes:

    ffmpeg -v error -i y_%02d.tiff -f framehash -hash md5 -
    #stream#, dts,        pts, duration,     size, hash
    0,          0,          0,        1,   230400, 56a4401ee8f46ef4205508ab06926bdc
    0,          1,          1,        1,   230400, 3ff51f5bef6dbf619fd0469bd29f63ec
    0,          2,          2,        1,   230400, ef51487b9905ecb4638c9901251a1dde
    

  • 哈希匹配.

    这篇关于将视频转换为帧,然后返回视频而无需更改python中的帧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆