python - FFMPEG 检测视频中的彩条和色调

标签 python ffmpeg windows-10

我正在尝试检测视频是否有任何有效内容,或者只是标准的广播条和音调。到目前为止,我已经看过这个问题:https://superuser.com/questions/1036449/detect-color-bars-ffmpeg/1036478#1036478
它从第一帧生成条形和色调,然后将其与流的其余部分进行比较,但在我的情况下,我需要在一个文件夹中运行 ffmpeg 命令,该文件夹中只有一个文件已被我的 python 脚本找到。

是否可以使用 ffmpeg 的 blend=difference 来检查短条和音调剪辑是否是我的一个视频文件的子剪辑?我正在以与您可以检查字符串是否在字符串中的相同方式来考虑这一点,或者是否有更好的方法来检查我没有想到的条形?

谢谢!

最佳答案

我找到了一种方法让我的脚本用 python 和 ffmpeg 做我想做的事情:

有关此 ffmpeg 命令如何工作的信息:
https://unix.stackexchange.com/questions/101558/compare-video-and-image-percentage-of-differences
http://ffmpeg.org/ffmpeg-filters.html#Video-Filters

-------------------------------------------------- ------ 开始代码 ------------------------------ -------------

selection = "'gt(scene\,0.1)'"         # The decimal here is the threshold for determining video quality (0 -> 1)

proc5 = Popen('C:/ffmpeg/bin/ffmpeg.exe -i "'+ src +'" -vf "select='+ selection +'" -vsync 0 -f image2 -y //fn101cdmzst01.foxneo.com/signiant/foxsports/soundmouse/FileManagerInfo/Thumbnails/thumbnails-%02d.jpg 2>&1', stdout=PIPE, shell=True)  # This is the ffmpeg command.  The specifics of how it works are explained below

res, err = proc5.communicate()         # Read proc5's (the ffmpeg command) stdout to res and stderr to err

proc5.wait()                           # Wait for ffmpeg to finish processing the whole video file

res = str(res.decode('ascii'))         # Decode the ascii output from stdout and convert to a string

print(res)

if r"Output file is empty" in res:     # If the ascii output from stdout has the string "Output file is empty", remove it.  Otherwise, perform name changes and file move for soundmouse

-------------------------------------------------- --------- 结束代码 ---------------------------------------- ----------------
FFMPEG COMMAND: 'C:/ffmpeg/bin/ffmpeg.exe -i "'+ src +'" -vf "select='+ selection +'" -vsync 0 -f image2 -y //fn101cdmzst01.foxneo.com/signiant/foxsports/soundmouse/FileManagerInfo/Thumbnails/thumbnails-%02d.jpg 2>&1'

实际的 ffmpeg 命令根据其执行的各种操作高亮显示。
C:/ffmpeg/bin/ffmpeg.exe          # make an absolute path call to ffmpeg.exe

-i "'+ src +'"                    # set the absolute path to the source file as the input

-vf "select='+ selection +'"      # use a video filter to select frames with large change before and after (based on the decimal threshold that is set) and compare it with the following portion of the command

-vsync 0 -f image2 -y //fn101cdmzst01.foxneo.com/signiant/foxsports/soundmouse/FileManagerInfo/Thumbnails/thumbnails-%02d.jpg  # compare the selected frame with the previous one stored in the Thumbnails folder and then overwrite the comparison thumbnail with the selected frame for the next comparison

2>&1'                             # redirect stderr to stdout so that we can read it with Python's proc5.communicate() function

关于python - FFMPEG 检测视频中的彩条和色调,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40314566/

相关文章:

python - OpenGL 纹理 - 一些 jpg 正在以一种奇怪的方式扭曲

python - 无法访问带有漂亮汤的推文 ID

FFMPEG 通过网络流传输一系列图片

python - 使用 ffmpeg-python 库捕获网络摄像头

windows - Win 10 : Desktop. ini 信息提示/工具提示文本格式 - 换行符

python - 过滤给定范围内的坐标

Python:比较 2 个不同大小的元组列表

heroku - 如何在 heroku 上使用音乐不和谐机器人播放声音

python - 如何通过 selenium p 隐藏 chromedriver 登录控制台

python - 命令提示符中的彩色文本在 "cls"之后但不在 "cls"之前