1

Я генерирую выходной файл с именем "silence.txt" с помощью ffmpeg. Когда я пытаюсь извлечь строки, содержащие слово "silencedetect", я получаю странную выдержку.

Вот мой оригинальный файл "silence.txt":

ffmpeg version 2.6.3 Copyright (c) 2000-2015 the FFmpeg developers
  built with Apple LLVM version 6.0 (clang-600.0.56) (based on LLVM 3.5svn)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/2.6.3 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-libx264 --enable-libmp3lame --enable-libvo-aacenc --enable-libxvid --enable-libfreetype --enable-libtheora --enable-libvorbis --enable-libvpx --enable-librtmp --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libass --enable-ffplay --enable-libspeex --enable-libschroedinger --enable-libfdk-aac --enable-libopus --enable-frei0r --enable-libopenjpeg --disable-decoder=jpeg2000 --extra-cflags='-I/usr/local/Cellar/openjpeg/1.5.1_1/include/openjpeg-1.5 ' --enable-nonfree --enable-vda
  libavutil      54. 20.100 / 54. 20.100
  libavcodec     56. 26.100 / 56. 26.100
  libavformat    56. 25.101 / 56. 25.101
  libavdevice    56.  4.100 / 56.  4.100
  libavfilter     5. 11.102 /  5. 11.102
  libavresample   2.  1.  0 /  2.  1.  0
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  1.100 /  1.  1.100
  libpostproc    53.  3.100 / 53.  3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'test4.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 0
    compatible_brands: mp41avc1
    creation_time   : 2015-06-20 22:41:18
    playback_requirements: QuickTime 6.0 or greater
    playback_requirements-eng: QuickTime 6.0 or greater
    encoder         : vlc 2.2.1 stream output
    encoder-eng     : vlc 2.2.1 stream output
  Duration: 00:05:25.93, start: 0.000000, bitrate: 1761 kb/s
    Stream #0:0(fra): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s (default)
    Metadata:
      creation_time   : 2015-06-20 22:41:18
      handler_name    : SoundHandler
    Stream #0:1(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 720x576 [SAR 64:45 DAR 16:9], 1625 kb/s, 24.96 fps, 25 tbr, 1000k tbn, 50 tbc (default)
    Metadata:
      creation_time   : 2015-06-20 22:41:18
      handler_name    : VideoHandler
Output #0, null, to 'pipe:':
  Metadata:
    major_brand     : isom
    minor_version   : 0
    compatible_brands: mp41avc1
    encoder         : Lavf56.25.101
    playback_requirements: QuickTime 6.0 or greater
    playback_requirements-eng: QuickTime 6.0 or greater
    Stream #0:0(eng): Video: rawvideo (I420 / 0x30323449), yuv420p, 720x576 [SAR 64:45 DAR 16:9], q=2-31, 200 kb/s, 25 fps, 25 tbn, 25 tbc (default)
    Metadata:
      creation_time   : 2015-06-20 22:41:18
      handler_name    : VideoHandler
      encoder         : Lavc56.26.100 rawvideo
    Stream #0:1(fra): Audio: pcm_s16le, 48000 Hz, stereo, s16, 1536 kb/s (default)
    Metadata:
      creation_time   : 2015-06-20 22:41:18
      handler_name    : SoundHandler
      encoder         : Lavc56.26.100 pcm_s16le
Stream mapping:
  Stream #0:1 -> #0:0 (h264 (native) -> rawvideo (native))
  Stream #0:0 -> #0:1 (aac (native) -> pcm_s16le (native))
Press [q] to stop, [?] for help
[null @ 0x7feb4b810600] Application provided invalid, non monotonically increasing dts to muxer in stream 1: 993 >= 993
[null @ 0x7feb4b810600] Application provided invalid, non monotonically increasing dts to muxer in stream 1: 5602 >= 5602
frame=  139 fps=0.0 q=0.0 size=N/A time=00:00:07.03 bitrate=N/A    
frame=  316 fps=311 q=0.0 size=N/A time=00:00:14.11 bitrate=N/A    
[null @ 0x7feb4b810600] Application provided invalid, non monotonically increasing dts to muxer in stream 1: 734723 >= 734723
[silencedetect @ 0x7feb4b40d9e0] silence_start: 15.056
[silencedetect @ 0x7feb4b40d9e0] silence_end: 15.6482 | silence_duration: 0.592229
frame=  488 fps=321 q=0.0 size=N/A time=00:00:21.04 bitrate=N/A    
frame=  631 fps=312 q=0.0 size=N/A time=00:00:26.75 bitrate=N/A    
[null @ 0x7feb4b810600] Application provided invalid, non monotonically increasing dts to muxer in stream 1: 1476678 >= 1476678
[silencedetect @ 0x7feb4b40d9e0] silence_start: 30.5347
[silencedetect @ 0x7feb4b40d9e0] silence_end: 31.0626 | silence_duration: 0.527958
frame=  839 fps=333 q=0.0 size=N/A time=00:00:34.08 bitrate=N/A    
frame=  975 fps=322 q=0.0 size=N/A time=00:00:39.52 bitrate=N/A    
frame= 1150 fps=325 q=0.0 size=N/A time=00:00:46.52 bitrate=N/A    
[silencedetect @ 0x7feb4b40d9e0] silence_start: 54.051
[silencedetect @ 0x7feb4b40d9e0] silence_end: 54.5362 | silence_duration: 0.485292
frame= 1366 fps=339 q=0.0 size=N/A time=00:00:55.16 bitrate=N/A    
frame= 1505 fps=332 q=0.0 size=N/A time=00:01:00.72 bitrate=N/A    
frame= 1645 fps=327 q=0.0 size=N/A time=00:01:06.32 bitrate=N/A    
frame= 1780 fps=321 q=0.0 size=N/A time=00:01:11.72 bitrate=N/A    
frame= 1957 fps=324 q=0.0 size=N/A time=00:01:18.80 bitrate=N/A    
[null @ 0x7feb4b810600] Application provided invalid, non monotonically increasing dts to muxer in stream 1: 4067886 >= 4067886
[silencedetect @ 0x7feb4b40d9e0] silence_start: 84.4542
[silencedetect @ 0x7feb4b40d9e0] silence_end: 85.4725 | silence_duration: 1.01831
frame= 2150 fps=329 q=0.0 size=N/A time=00:01:26.52 bitrate=N/A    
frame= 2289 fps=325 q=0.0 size=N/A time=00:01:32.08 bitrate=N/A    
frame= 2460 fps=326 q=0.0 size=N/A time=00:01:38.92 bitrate=N/A    
frame= 2584 fps=321 q=0.0 size=N/A time=00:01:43.88 bitrate=N/A    
[silencedetect @ 0x7feb4b40d9e0] silence_start: 104.986
[null @ 0x7feb4b810600] Application provided invalid, non monotonically increasing dts to muxer in stream 1: 5058544 >= 5058544
[silencedetect @ 0x7feb4b40d9e0] silence_end: 105.482 | silence_duration: 0.495979
frame= 2763 fps=323 q=0.0 size=N/A time=00:01:51.04 bitrate=N/A    
[silencedetect @ 0x7feb4b40d9e0] silence_start: 115.327
[null @ 0x7feb4b810600] Application provided invalid, non monotonically increasing dts to muxer in stream 1: 5557968 >= 5557968
[silencedetect @ 0x7feb4b40d9e0] silence_end: 115.983 | silence_duration: 0.656042
frame= 2939 fps=324 q=0.0 size=N/A time=00:01:58.08 bitrate=N/A    
frame= 3101 fps=324 q=0.0 size=N/A time=00:02:04.56 bitrate=N/A    
frame= 3264 fps=324 q=0.0 size=N/A time=00:02:11.08 bitrate=N/A    
frame= 3474 fps=329 q=0.0 size=N/A time=00:02:19.48 bitrate=N/A    
[silencedetect @ 0x7feb4b40d9e0] silence_start: 138.695
[null @ 0x7feb4b810600] Application provided invalid, non monotonically increasing dts to muxer in stream 1: 6679615 >= 6679615
[silencedetect @ 0x7feb4b40d9e0] silence_end: 139.415 | silence_duration: 0.719875
frame= 3636 fps=328 q=0.0 size=N/A time=00:02:25.96 bitrate=N/A    
[null @ 0x7feb4b810600] Application provided invalid, non monotonically increasing dts to muxer in stream 1: 7178004 >= 7178004
[silencedetect @ 0x7feb4b40d9e0] silence_start: 149.206
[silencedetect @ 0x7feb4b40d9e0] silence_end: 149.883 | silence_duration: 0.677187
frame= 3811 fps=329 q=0.0 size=N/A time=00:02:32.96 bitrate=N/A    
frame= 3968 fps=329 q=0.0 size=N/A time=00:02:39.24 bitrate=N/A    
frame= 4132 fps=329 q=0.0 size=N/A time=00:02:45.80 bitrate=N/A    
frame= 4296 fps=329 q=0.0 size=N/A time=00:02:52.36 bitrate=N/A    
frame= 4492 fps=331 q=0.0 size=N/A time=00:03:00.28 bitrate=N/A    
[silencedetect @ 0x7feb4b40d9e0] silence_start: 179.842
[null @ 0x7feb4b810600] Application provided invalid, non monotonically increasing dts to muxer in stream 1: 8652662 >= 8652662
[silencedetect @ 0x7feb4b40d9e0] silence_end: 180.44 | silence_duration: 0.597313
frame= 4655 fps=331 q=0.0 size=N/A time=00:03:06.80 bitrate=N/A    
frame= 4821 fps=331 q=0.0 size=N/A time=00:03:13.44 bitrate=N/A    
frame= 4985 fps=330 q=0.0 size=N/A time=00:03:20.00 bitrate=N/A    
[silencedetect @ 0x7feb4b40d9e0] silence_start: 205.278
[silencedetect @ 0x7feb4b40d9e0] silence_end: 205.806 | silence_duration: 0.527937
frame= 5167 fps=332 q=0.0 size=N/A time=00:03:27.28 bitrate=N/A    
[silencedetect @ 0x7feb4b40d9e0] silence_start: 206.216
[silencedetect @ 0x7feb4b40d9e0] silence_end: 206.659 | silence_duration: 0.442667
frame= 5339 fps=332 q=0.0 size=N/A time=00:03:34.16 bitrate=N/A    
[silencedetect @ 0x7feb4b40d9e0] silence_start: 215.789
[silencedetect @ 0x7feb4b40d9e0] silence_end: 216.274 | silence_duration: 0.485271
frame= 5539 fps=334 q=0.0 size=N/A time=00:03:42.16 bitrate=N/A    
frame= 5708 fps=334 q=0.0 size=N/A time=00:03:48.92 bitrate=N/A    
frame= 5870 fps=334 q=0.0 size=N/A time=00:03:55.40 bitrate=N/A    
frame= 6051 fps=334 q=0.0 size=N/A time=00:04:02.64 bitrate=N/A    
[null @ 0x7feb4b810600] Application provided invalid, non monotonically increasing dts to muxer in stream 1: 11837448 >= 11837448
[silencedetect @ 0x7feb4b40d9e0] silence_start: 246.309
[silencedetect @ 0x7feb4b40d9e0] silence_end: 246.742 | silence_duration: 0.432
frame= 6232 fps=335 q=0.0 size=N/A time=00:04:09.88 bitrate=N/A    
frame= 6385 fps=334 q=0.0 size=N/A time=00:04:16.00 bitrate=N/A    
frame= 6540 fps=334 q=0.0 size=N/A time=00:04:22.20 bitrate=N/A    
[silencedetect @ 0x7feb4b40d9e0] silence_start: 266.596
[silencedetect @ 0x7feb4b40d9e0] silence_end: 267.209 | silence_duration: 0.613229
frame= 6740 fps=335 q=0.0 size=N/A time=00:04:30.20 bitrate=N/A    
frame= 6908 fps=335 q=0.0 size=N/A time=00:04:36.92 bitrate=N/A    
frame= 7082 fps=336 q=0.0 size=N/A time=00:04:43.88 bitrate=N/A    
frame= 7243 fps=335 q=0.0 size=N/A time=00:04:50.32 bitrate=N/A    
frame= 7431 fps=336 q=0.0 size=N/A time=00:04:57.84 bitrate=N/A    
[null @ 0x7feb4b810600] Application provided invalid, non monotonically increasing dts to muxer in stream 1: 14273127 >= 14273127
[silencedetect @ 0x7feb4b40d9e0] silence_start: 297.191
[silencedetect @ 0x7feb4b40d9e0] silence_end: 297.677 | silence_duration: 0.485292
frame= 7600 fps=336 q=0.0 size=N/A time=00:05:04.60 bitrate=N/A    
frame= 7775 fps=336 q=0.0 size=N/A time=00:05:11.60 bitrate=N/A    
[null @ 0x7feb4b810600] Application provided invalid, non monotonically increasing dts to muxer in stream 1: 15255582 >= 15255582
[silencedetect @ 0x7feb4b40d9e0] silence_start: 317.553
[silencedetect @ 0x7feb4b40d9e0] silence_end: 318.144 | silence_duration: 0.591896
frame= 7980 fps=338 q=0.0 size=N/A time=00:05:19.80 bitrate=N/A    
frame= 8135 fps=338 q=0.0 Lsize=N/A time=00:05:26.08 bitrate=N/A    
video:763kB audio:61036kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown

Я использовал следующую команду grep ...

grep silencedetect silence.txt > extract.txt

... чтобы получить этот файл "extract.txt":

[silencedetect @ 0x7feb4b40d9e0] silence_start: 15.056
[silencedetect @ 0x7feb4b40d9e0] silence_end: 15.6482 | silence_duration: 0.592229
[silencedetect @ 0x7feb4b40d9e0] silence_start: 30.5347
[silencedetect @ 0x7feb4b40d9e0] silence_end: 31.0626 | silence_duration: 0.527958
frame=  839 fps=333 q=0.0 size=N/A time=00:00:34.08 bitrate=N/A    
frame=  975 fps=322 q=0.0 size=N/A time=00:00:39.52 bitrate=N/A    
frame= 1150 fps=325 q=0.0 size=N/A time=00:00:46.52 bitrate=N/A    
[silencedetect @ 0x7feb4b40d9e0] silence_start: 54.051
[silencedetect @ 0x7feb4b40d9e0] silence_end: 54.5362 | silence_duration: 0.485292
[silencedetect @ 0x7feb4b40d9e0] silence_start: 84.4542
[silencedetect @ 0x7feb4b40d9e0] silence_end: 85.4725 | silence_duration: 1.01831
frame= 2150 fps=329 q=0.0 size=N/A time=00:01:26.52 bitrate=N/A    
frame= 2289 fps=325 q=0.0 size=N/A time=00:01:32.08 bitrate=N/A    
frame= 2460 fps=326 q=0.0 size=N/A time=00:01:38.92 bitrate=N/A    
frame= 2584 fps=321 q=0.0 size=N/A time=00:01:43.88 bitrate=N/A    
[silencedetect @ 0x7feb4b40d9e0] silence_start: 104.986
[silencedetect @ 0x7feb4b40d9e0] silence_end: 105.482 | silence_duration: 0.495979
frame= 2763 fps=323 q=0.0 size=N/A time=00:01:51.04 bitrate=N/A    
[silencedetect @ 0x7feb4b40d9e0] silence_start: 115.327
[silencedetect @ 0x7feb4b40d9e0] silence_end: 115.983 | silence_duration: 0.656042
frame= 2939 fps=324 q=0.0 size=N/A time=00:01:58.08 bitrate=N/A    
frame= 3101 fps=324 q=0.0 size=N/A time=00:02:04.56 bitrate=N/A    
frame= 3264 fps=324 q=0.0 size=N/A time=00:02:11.08 bitrate=N/A    
frame= 3474 fps=329 q=0.0 size=N/A time=00:02:19.48 bitrate=N/A    
[silencedetect @ 0x7feb4b40d9e0] silence_start: 138.695
[silencedetect @ 0x7feb4b40d9e0] silence_end: 139.415 | silence_duration: 0.719875
[silencedetect @ 0x7feb4b40d9e0] silence_start: 149.206
[silencedetect @ 0x7feb4b40d9e0] silence_end: 149.883 | silence_duration: 0.677187
frame= 3811 fps=329 q=0.0 size=N/A time=00:02:32.96 bitrate=N/A    
frame= 3968 fps=329 q=0.0 size=N/A time=00:02:39.24 bitrate=N/A    
frame= 4132 fps=329 q=0.0 size=N/A time=00:02:45.80 bitrate=N/A    
frame= 4296 fps=329 q=0.0 size=N/A time=00:02:52.36 bitrate=N/A    
frame= 4492 fps=331 q=0.0 size=N/A time=00:03:00.28 bitrate=N/A    
[silencedetect @ 0x7feb4b40d9e0] silence_start: 179.842
[silencedetect @ 0x7feb4b40d9e0] silence_end: 180.44 | silence_duration: 0.597313
frame= 4655 fps=331 q=0.0 size=N/A time=00:03:06.80 bitrate=N/A    
frame= 4821 fps=331 q=0.0 size=N/A time=00:03:13.44 bitrate=N/A    
frame= 4985 fps=330 q=0.0 size=N/A time=00:03:20.00 bitrate=N/A    
[silencedetect @ 0x7feb4b40d9e0] silence_start: 205.278
[silencedetect @ 0x7feb4b40d9e0] silence_end: 205.806 | silence_duration: 0.527937
frame= 5167 fps=332 q=0.0 size=N/A time=00:03:27.28 bitrate=N/A    
[silencedetect @ 0x7feb4b40d9e0] silence_start: 206.216
[silencedetect @ 0x7feb4b40d9e0] silence_end: 206.659 | silence_duration: 0.442667
frame= 5339 fps=332 q=0.0 size=N/A time=00:03:34.16 bitrate=N/A    
[silencedetect @ 0x7feb4b40d9e0] silence_start: 215.789
[silencedetect @ 0x7feb4b40d9e0] silence_end: 216.274 | silence_duration: 0.485271
[silencedetect @ 0x7feb4b40d9e0] silence_start: 246.309
[silencedetect @ 0x7feb4b40d9e0] silence_end: 246.742 | silence_duration: 0.432
frame= 6232 fps=335 q=0.0 size=N/A time=00:04:09.88 bitrate=N/A    
frame= 6385 fps=334 q=0.0 size=N/A time=00:04:16.00 bitrate=N/A    
frame= 6540 fps=334 q=0.0 size=N/A time=00:04:22.20 bitrate=N/A    
[silencedetect @ 0x7feb4b40d9e0] silence_start: 266.596
[silencedetect @ 0x7feb4b40d9e0] silence_end: 267.209 | silence_duration: 0.613229
[silencedetect @ 0x7feb4b40d9e0] silence_start: 297.191
[silencedetect @ 0x7feb4b40d9e0] silence_end: 297.677 | silence_duration: 0.485292
[silencedetect @ 0x7feb4b40d9e0] silence_start: 317.553
[silencedetect @ 0x7feb4b40d9e0] silence_end: 318.144 | silence_duration: 0.591896

Проблема в том, что он дает мне больше, чем запрашиваемую строку, например:"frame = 4655 fps = 331 q = 0.0 size = N/A time = 00:03:06.80 bitrate = N/A" и т.д.

Итак, мой вопрос, как получить строки, которые я хочу, используя команду grep? Далее, если вы можете помочь мне больше, идея состоит в том, чтобы получить все значения silence_start и silence_end для запуска другой команды с ffmpeg и разделения видео на несколько сегментов.

3 ответа3

0

Я попробовал это на своем Mac, и это, кажется, работает как ожидалось. Я подозреваю, что команда grep вы используете, может быть изменена либо с помощью псевдонима, либо с помощью другой команды, которая стоит первой на пути. Попробуй это:

/usr/bin/grep silence.txt  # On Mac
/bin/grep silence.txt      # On Linux

и посмотреть, если вы получите желаемый результат.

0

Я бы попробовал

grep silencedetect silence.txt | cat -n -v

или же

grep silencedetect silence.txt | less -N -S

или же

grep silencedetect silence.txt | hexdump -C

Потому что то, что кажется посторонним

  • Просто будьте завернуты в конец согласованных линий.
  • Строки, содержащие контрольные символы, которые скрывают совпадение (например, CR).

Для второй части вашего вопроса

egrep 'silencedetect.*silence_(start|end)' silence.txt

или эквивалент в awk или perl чтобы вы могли фиксировать время и вводить команды ffmpeg.

0

Если вы передадите свой файл через

cat -vet

Вы можете увидеть любые специальные символы. В этом случае у вас есть возврат каретки (показывается как ^M на выходе), который разделяет строки вместо новой строки. Например:

...  bitrate=N/A    ^M[silencedetect ...

Вы можете перевести их на новые строки и использовать awk для извлечения времени, например:

tr '\r' '\n' < silence4.txt |
awk '
/silence_start/{ start = $5 }
/silence_end/ { end = $5; printf "%s to %s\n",start,end }'

Всё ещё ищете ответ? Посмотрите другие вопросы с метками .