我已经借助以下脚本将短视频转换为gif:
#!/bin/sh
palette="/tmp/palette.png"
filters="fps=15,scale=320:-1:flags=lanczos"
ffmpeg -v warning -i $1 -vf "$filters,palettegen" -y $palette
ffmpeg -v warning -i $1 -i $palette -lavfi "$filters [x]; [x][1:v] paletteuse" -y $2
Run Code Online (Sandbox Code Playgroud)
但是,当我转换图像序列时,我收到错误消息:"过滤器paletteuse具有未连接的输出"
#!/bin/sh
palette="/tmp/palette.png"
filters="fps=25"
ffmpeg -v warning -f image2 -i %04d.jpg -vf "$filters,palettegen" -y $palette
ffmpeg -v warning -f image2 -i %04d.jpg -i $palette -lavfi "$filters [x]; [x][1:v] paletteuse" -y $2
Run Code Online (Sandbox Code Playgroud)
如何使palettegen和paletteuse也适用于图像序列?
我需要用Ruby正则表达式消化一些bbcode.
我必须match使用命令分隔元素并使用正则表达式/pattern/m来删除换行符.
例如,我在字符串中的bbcode是:
s="[b]Title[/b] \n Article text \n [b]references[/b]"
Run Code Online (Sandbox Code Playgroud)
然后我match用来分隔文本的部分,特别是包含在[b]和之间的Title和References部分[/b]:
t=s.match(/\[b\](.*)\[\/b\]/m)
Run Code Online (Sandbox Code Playgroud)
我使用(..)语法来捕获正则表达式中的字符串,我\用来逃避特殊[和]字符./m是摆脱字符串中的换行符.
然后t[1]包含:
"Title[/b] \n Artucle text \n [b]references"
Run Code Online (Sandbox Code Playgroud)
而不是"Title".因为比赛并没有在第一次出现时停止[/b].t[2]由于同样的原因,它是nil而不是"References".
如何分隔通常的bbcode标签之间的文本部分?
当我通过FFMpeg对视频进行编码时,我想在第一个视频帧之前放置一个jpg图像,因为当我将视频嵌入带有"video"html5标签的网页时,它会将第一张图片显示为初始图像.或者,我想将图像编码为1帧视频并将其连接到我的编码视频.我不想使用"video"html5元素的"poster"属性.
我有一个简单的脚本来处理来自 STDIN 的行。有时会出现异常 - 一些 UTF-8 转换错误 - 我想检查变量,导致错误的原因。我在文件中使用以下语法(我们称之为filter.rb),但我从未收到 Pry 提示:
#!/usr/bin/ruby
require "pry"
n=0
while line=STDIN.gets do
begin
n=n+1
raise "an exception" if n==2
rescue => e
binding.pry
end
end
Run Code Online (Sandbox Code Playgroud)
当我发出:
cat data.txt|ruby filter.rb
Run Code Online (Sandbox Code Playgroud)
我在屏幕上看到:
5: while line= STDIN.gets do
6: begin
7: n=n+1
8: raise "an exception" if n==2
9: rescue => e
=> 10: binding.pry
11: end
12: end
Run Code Online (Sandbox Code Playgroud)
但事实上我得到的只是 bash 提示符,而不是 Pry 命令提示符。
间隔由它们的边界给出为数组[a,b]和[x,y].我想计算它们之间的交叉长度.根据这个页面:http://world.std.com/~swmcd/steven/tech/interval.html
我可以告诉它是0如果
(not (a < y && x < b))
Run Code Online (Sandbox Code Playgroud)
成立.
例如,间隔[1.2,4.3]和[2.1,5.5]交叉点长度为4.3-2.1 = 2.2
我想得到一个优雅的代码,它删除了无关紧要的结束零,例如:
29.970 => 29.97
29.97 => 29.97
25.00 => 25
25.0 => 25
Run Code Online (Sandbox Code Playgroud)
我试过:
argument.to_r.to_f.to_s
Run Code Online (Sandbox Code Playgroud)
但并非在所有情况下都有效,例如在 25.00 给出 25.0
我有类似的哈希表(但更大的哈希表):
h={
"Wilhelm_Conrad_Röntgen": "http://www.example.com/w2xtt4w/001_1901.jpg",
"Hendrik_Lorentz": "http://www.example.com/apbfksz/004_1902.jpg",
"Pieter_Zeeman": "http://www.example.com/d2cpwj3/007_1902.jpg",
"Antoine_Henri_Becquerel": "http://www.example.com/g8sueyg/010_1903.jpg",
"Maria_Sk?odowska-Curie": "http://www.example.com/gfcgur8/013_1903.jpg",
"Lord_Rayleigh": "http://www.example.com/dcjiwq8/016_1904.jpg",
"Joseph_John_Thomson": "http://www.example.com/4a66bc9/019_1906.jpg",
"Gabriel_Lippmann": "http://www.example.com/xjefgoa/022_1908.jpg",
"Guglielmo_Marconi": "http://www.example.com/x359w62/025_1909.jpg",
"Karl_Ferdinand_Braun": "http://www.example.com/1edm469/028_1909.jpg",
"Johannes_Diderik_van_der_Waals": "http://www.example.com/31hpue7/031_1910.jpg",
"Wilhelm_Wien": "http://www.example.com/yel9iff/034_1911.jpg",
"Nils_Gustaf_Dalén": "http://www.example.com/iezss59/037_1912.jpg",
"Heike_Kamerlingh-Onnes": "http://www.example.com/8zl4uj2/040_1913.jpg",
"Max_von_Laue": "http://www.example.com/ta3w6rn/043_1914.jpg",
"William_Henry_Bragg": "http://www.example.com/u43qn5h/046_1915.jpg",
"William_Lawrence_Bragg": "http://www.example.com/n7gkk6e/049_1915.jpg",
"Charles_Glover_Barkla": "http://www.example.com/2kxxroc/052_1917.jpg",
"Max_Planck": "http://www.example.com/eyw7tm6/055_1918.jpg",
"Johannes_Stark": "http://www.example.com/gcjcv2p/058_1919.jpg",
"Charles_Édouard_Guillaume": "http://www.example.com/nox3s6o/061_1920.jpg",
"Niels_Bohr": "http://www.example.com/mo9ga29/064_1922.jpg",
"Robert_Andrews_Millikan": "http://www.example.com/kxq71if/067_1923.jpg",
"Manne_Siegbahn": "http://www.example.com/2uwhw9y/070_1924.jpg",
"James_Franck": "http://www.example.com/iwdavip/073_1925.jpg",
"Gustav_Hertz": "http://www.example.com/73mbso2/076_1925.jpg",
"Jean_Baptiste_Perrin": "http://www.example.com/rgugmas/079_1926.jpg",
"Arthur_Holly_Compton": "http://www.example.com/vy7is1v/082_1927.jpg",
"Owen_Willans_Richardson": "http://www.example.com/3jz5ve8/085_1928.jpg",
"Louis_Victor_Pierre_Raymond": "http://www.example.com/srvj8d5/088_1929.jpg",
"John_M_Kosterlitz": "http://www.example.com/7op2wb1/091_1929.jpg",
"Chandrasekhara_Venkata_Raman": "http://www.example.com/1vqqwua/094_1930.jpg"
}
Run Code Online (Sandbox Code Playgroud)
我想以有效的方式为每个键找到最短的前缀,前缀在给定键中是唯一的.换句话说:在哈希表中仍然可以识别每行具有较短的前缀.对于此哈希表,最短的前缀仍然使行可识别:
h={
"Wilhelm_C": "http://www.example.com/w2xtt4w/001_1901.jpg",
"Hen": "http://www.example.com/apbfksz/004_1902.jpg",
"P": "http://www.example.com/d2cpwj3/007_1902.jpg",
"An": "http://www.example.com/g8sueyg/010_1903.jpg",
"Mar": "http://www.example.com/gfcgur8/013_1903.jpg",
"Lor": …Run Code Online (Sandbox Code Playgroud) Ruby max_by 方法查找数组中的最大元素。有时最大元素具有多重性,在这种情况下 max_by 只选择其中之一,看起来是任意的。当我需要所有这些时,我当前使用这种方法来查找数组数组中的最大值:
sorted=ary.sort_by{|a,b| b}.reverse
max_score=sorted.first[1]
t=sorted.take_while{|z| z[1]==max_score}
Run Code Online (Sandbox Code Playgroud)
但是我如何使用“maxes_by”方法对 Array 类进行猴子修补,该方法接受一个块,类似于 max_by,并返回最大值的数组?
我写了一个非常大的ruby模块,它在大约3-4秒内加载.大多数时候我只需要一个功能.为了加快速度,是否可以从模块加载/只需要特定的功能?
我有一个包含标签的数组,通常是简单的英文单词,大约3-6个元素.我必须从文本文件中选择包含任何顺序的所有标记的行(大写或小写不计,不区分大小写).我怎样才能在Ruby中实现这一目标?我应该使用正则表达式还是任何不同的方法?
例如,我知道如何逻辑或正则表达式模式/ tag1 | tag2 | tag3 /是否有可能以任何方式逻辑AND它们?/ tag1&tag2&tag3 /?
ruby ×8
arrays ×3
bash ×2
ffmpeg ×2
regex ×2
animated-gif ×1
bbcode ×1
decimal ×1
filter ×1
function ×1
hashtable ×1
image ×1
intersection ×1
intervals ×1
jpeg ×1
key ×1
load ×1
match ×1
maxima ×1
module ×1
pipe ×1
poster ×1
precision ×1
prefix ×1
pry ×1
require ×1
sequence ×1
sorting ×1
stdin ×1
string ×1
text ×1
unique ×1
video ×1
xml ×1