如何使用ffmpeg提取小视频块? [英] How to extract small video chunk with ffmpeg?

查看:63
本文介绍了如何使用ffmpeg提取小视频块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个脚本来根据字幕时间将视频分割成多个小文件.每个块都说明了如何签署一个单词 LSF(法国手语).

I'm writing a script to split a video in multiple small files based on subtitles timing. Each chunk illustrated how to sign a word LSF (French Sign Language).

然而,有些文件在提取后是空白的,当转换为 webm 时,它们是 0kb.

However, some file are blank once extracted and when converted to webm they are 0kb.

我从 .ass 文件中提取时间以获得这种文件

I extract the timing from a .ass file to get this kind of file

0:00:01.01 0:00:04.07
0:00:04.09 0:00:07.00
0:00:07.00 0:00:10.36
0:00:10.36 0:00:13.28

第一列是start_time,第二列是end_time

extract_word_chunk() {
  ffmpeg \
    -i "$INPUT_FILE" \
    -ss "$start" \
    -to "$end" \
    -vcodec copy \
    -acodec copy \
    -loglevel error \
    "$chunk" < /dev/null
}

转换为 webm

convert_to_webm() {
  ffmpeg \
    -y \
    -i "$chunk" \
    -acodec libvorbis \
    -codec:v libvpx \
    -b:v 192k \
    -b:a 96k \
    -minrate 128k \
    -maxrate 256k \
    -bufsize 192k \
    -quality good \
    -cpu-used 2 \
    -deadline best \
    -loglevel error \
  "$chunk.webm" < /dev/null
}

输出

# extract_word_chunk
ffmpeg \
  -i 'assets/raw/partie 1: Apprendre 300 mots du quotidien en LSF.jauvert laura.mkv' \
  -ss 0:00:01.01 \
  -to 0:00:04.07 \
  -vcodec copy \
  -acodec copy \
  -loglevel error \
  assets/raw/0:00:01.01.mkv

# convert_to_webm
ffmpeg -y \
  -i assets/raw/0:00:01.01.mkv \
  -acodec libvorbis \
  -codec:v libvpx \
  -b:v 192k \
  -b:a 96k \
  -minrate 128k \
  -maxrate 256k \
  -bufsize 192k \
  -quality good \
  -cpu-used 2 \
  -deadline best \
  -loglevel error \
  assets/raw/0:00:01.01.mkv.webm

错误

[buffer @ 0x16d8be0] Unable to parse option value "-1" as pixel format
    Last message repeated 1 times
[buffer @ 0x16d8be0] Error setting option pix_fmt to value -1.
[graph 0 input from stream 0:0 @ 0x16e6fc0] Error applying options to the filter.

问题

只有一些块是空白的.

Question

Only some chunk are blank/empty.

如何防止我的视频空白?

How do I prevent my video to be blank/empty?

推荐答案

一键搞定

ffmpeg -y \
  -i 'assets/raw/partie 1: Apprendre 300 mots du quotidien en LSF.jauvert laura.mkv' \
  -ss 0:00:01.01 \
  -to 0:00:04.07 \
  -acodec libvorbis \
  -codec:v libvpx \
  -b:v 192k \
  -b:a 96k \
  -minrate 128k \
  -maxrate 256k \
  -bufsize 192k \
  -quality good \
  -cpu-used 2 \
  -deadline best \
  -loglevel error \
  assets/raw/0:00:01.01.mkv.webm

<小时>

当你使用copy模式,并且解码seek(-s后-i)ffmpeg只在关键帧处剪切,所以有时在指定的时间范围内可能没有任何关键帧,因此那些输出mkvs是空的.您可以通过一步提取和编码来避免这种情况.


When you use copy mode, and decode seek (-ss after -i) ffmpeg only cuts at keyframes, so sometimes there may not be any keyframes in the time range specified, hence those output mkvs are empty. You can avoid this by extracting and encoding in one step.

这篇关于如何使用ffmpeg提取小视频块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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