我正在尝试检测视频是否有任何有效内容,或者只是标准的广播条和音调。到目前为止,我已经看过这个问题: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/