您可以使用ffmpeg将blackdetect过滤器的结果放入文本文件中吗? [英] Can you put the result of a blackdetect filter in a textfile using ffmpeg?

查看:124
本文介绍了您可以使用ffmpeg将blackdetect过滤器的结果放入文本文件中吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在测试ffmpeg中的"blackdetect"过滤器.我想有一段视频是黑色的,可以通过脚本(例如动作脚本或javascript)读取.我试过了:

I'm testing out the "blackdetect" filter in ffmpeg. I want to have the times when the video is black to be read by a script (like actionscript or javascript). I tried:

ffmpeg -i video1.mp4 -vf "blackdetect=d=2:pix_th=0.00" -an -f null -

在ffmpeg日志中,我得到了一个不错的结果:

And I get a nice result in the ffmpeg log:

ffmpeg version N-55644-g68b63a3 Copyright (c) 2000-2013 the FFmpeg developers
  built on Aug 19 2013 20:32:00 with gcc 4.7.3 (GCC)
  configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-av
isynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enab
le-iconv --enable-libass --enable-libbluray --enable-libcaca --enable-libfreetyp
e --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --ena
ble-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-l
ibopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libsp
eex --enable-libtheora --enable-libtwolame --enable-libvo-aacenc --enable-libvo-
amrwbenc --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxavs --
enable-libxvid --enable-zlib
  libavutil      52. 42.100 / 52. 42.100
  libavcodec     55. 28.100 / 55. 28.100
  libavformat    55. 13.103 / 55. 13.103
  libavdevice    55.  3.100 / 55.  3.100
  libavfilter     3. 82.100 /  3. 82.100
  libswscale      2.  5.100 /  2.  5.100
  libswresample   0. 17.103 /  0. 17.103
  libpostproc    52.  3.100 / 52.  3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'video1.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    creation_time   : 1970-01-01 00:00:00
    encoder         : Lavf53.13.0
  Duration: 00:02:01.54, start: 0.000000, bitrate: 275 kb/s
    Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 768x432 [
SAR 1:1 DAR 16:9], 211 kb/s, 25 fps, 25 tbr, 25 tbn, 50 tbc
    Metadata:
      creation_time   : 1970-01-01 00:00:00
      handler_name    : VideoHandler
    Stream #0:1(eng): Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 59
 kb/s
    Metadata:
      creation_time   : 1970-01-01 00:00:00
      handler_name    : SoundHandler
Output #0, null, to 'pipe:':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf55.13.103
    Stream #0:0(eng): Video: rawvideo (I420 / 0x30323449), yuv420p, 768x432 [SAR
 1:1 DAR 16:9], q=2-31, 200 kb/s, 90k tbn, 25 tbc
    Metadata:
      creation_time   : 1970-01-01 00:00:00
      handler_name    : VideoHandler
Stream mapping:
  Stream #0:0 -> #0:0 (h264 -> rawvideo)
Press [q] to stop, [?] for help
[null @ 00000000003279a0] Encoder did not produce proper pts, making some up.
[blackdetect @ 0000000004d5e800] black_start:0 black_end:17.08 black_duration:17
.08
[blackdetect @ 0000000004d5e800] black_start:62.32 black_end:121.48 black_durati
on:59.16
frame= 3038 fps=2317 q=0.0 Lsize=N/A time=00:02:01.52 bitrate=N/A
video:285kB audio:0kB subtitle:0 global headers:0kB muxing overhead -100.007543%

我对这部分特别感兴趣:

And I'm particularly interested in this part:

[blackdetect @ 0000000004e2e340] black_start:0 black_end:17.08 black_duration:17.08
[blackdetect @ 0000000004e2e340] black_start:62.32 black_end:121.48 black_duration:59.16

所以我的问题:

  1. 有没有办法只将blackdetect过滤器的输出放到.txt文件中?
  2. 如果可能的话,有没有一种方法可以在具有多个视频输入的语句中执行此操作?就像在这个例子中一样


示例:


example:

ffmpeg -f concat -i mylist.txt -c copy concat.mp4

mylist.txt是视频列表:

Where mylist.txt is a list of videos:

file 'video1.mp4'
file 'video2.mp4'
file 'video3.mp4'
file 'video4.mp4'


我基本上想要的是一个或多个文本文件,其中包含有关此列表中每个视频中黑框的信息,供其他程序使用


Basically what I want to have is one or more text files containing information about the black frames in every video in this list to be used by another program

推荐答案

有没有办法只将blackdetect过滤器的输出放到.txt文件中?

Is there a way to only take the blackdetect filter output and put it in a .txt file?

默认情况下,ffmpeg记录到stderr.您可以输出到stdout,然后使用grep隔离 blackdetect 行:

By default ffmpeg logs to stderr. You can output to stdout and then use grep to isolate the blackdetect lines:

$ ffmpeg -i video1.mp4 -vf "blackdetect=d=2:pix_th=0.00" -an -f null - 2>&1 | grep blackdetect > output.txt

结果:

$ cat output.txt 
[blackdetect @ 0x1d2b980] black_start:5.16 black_end:10.24 black_duration:5.08 

如果要附加到output.txt而不是为每个实例覆盖,请使用>>而不是>,例如:blackdetect >> output.txt.

If you want to append to output.txt instead of overwriting for each instance then use >> instead of >, as in: blackdetect >> output.txt.

是否可以在具有多个视频输入的语句中执行此操作?

Is there a way to do this in a statement with multiple video inputs?

您可以将blackdetect concat多路分解器结合使用,但是您的问题所示请注意,black_startblack_end时间将是累积时间,而不是独立于每个输入,因为您正在串联所有输入.

You can use blackdetect with the concat demuxer as shown in your question, but be aware that the black_start and black_end times will be cumulative, and not independent to each input, because you are concatenating all inputs.

或者,如果您希望每个输入都通过blackdetect独立运行,则可以使用bash"for循环":

Alternatively you can use a bash "for loop" if you want each input to be independently run through blackdetect:

for f in *.mp4; do ffmpeg -i "$f" -vf "blackdetect=d=2:pix_th=0.00" -an -f null - 2>&1 | grep blackdetect > "$f".txt; done

这可能会创建空的txt文件.

This may create empty txt files.

这篇关于您可以使用ffmpeg将blackdetect过滤器的结果放入文本文件中吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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