forked from e621ng/e621ng
Updated encode settings
Save space, save time, make it clear it's a sample
This commit is contained in:
parent
0e95efa541
commit
c35d272d1e
@ -9,25 +9,24 @@ class PostVideoConversionJob
|
||||
sm = Danbooru.config.storage_manager
|
||||
samples.each do |name, named_samples|
|
||||
next if name == :original
|
||||
webm_path = sm.file_path(md5, 'webm', :scaled, scale_factor: name.to_s)
|
||||
webm_path = sm.file_path(md5, 'webm', :scaled, post.is_deleted?, scale_factor: name.to_s)
|
||||
logger.info("FILE PATH: #{webm_path.inspect}")
|
||||
sm.store(named_samples[0], webm_path)
|
||||
named_samples[0].close!
|
||||
mp4_path = sm.file_path("#{md5}", 'mp4', :scaled, scale_factor: name.to_s)
|
||||
mp4_path = sm.file_path("#{md5}", 'mp4', :scaled, post.is_deleted?, scale_factor: name.to_s)
|
||||
logger.info("FILE PATH MP4: #{mp4_path.inspect}")
|
||||
sm.store(named_samples[1], mp4_path)
|
||||
named_samples[1].close!
|
||||
end
|
||||
sm.store(samples[:original][1], sm.file_path(md5, 'mp4', :original))
|
||||
sm.store(samples[:original][1], sm.file_path(md5, 'mp4', :original, post.is_deleted?))
|
||||
samples[:original].each do |sample|
|
||||
sample.close!
|
||||
end
|
||||
end
|
||||
|
||||
def generate_video_samples(post)
|
||||
target_dims = {'480': [640, 480], '720': [1280, 720]}
|
||||
outputs = {}
|
||||
target_dims.each do |size, dims|
|
||||
Danbooru.config.video_rescales.each do |size, dims|
|
||||
next if post.image_width <= dims[0] && post.image_height <= dims[1]
|
||||
outputs[size] = generate_scaled_video(post.file_path, [post.image_width, post.image_height], dims)
|
||||
end
|
||||
@ -59,23 +58,31 @@ class PostVideoConversionJob
|
||||
"-auto-alt-ref",
|
||||
"0",
|
||||
'-qmin',
|
||||
'15',
|
||||
'20',
|
||||
'-qmax',
|
||||
'35',
|
||||
'42',
|
||||
"-crf",
|
||||
"30",
|
||||
"35",
|
||||
'-b:v',
|
||||
'3M',
|
||||
"-vf",
|
||||
target_size,
|
||||
"-threads",
|
||||
"4",
|
||||
'-row-mt',
|
||||
'1',
|
||||
"-max_muxing_queue_size",
|
||||
"4096",
|
||||
"-slices",
|
||||
"8",
|
||||
'-c:a',
|
||||
'libvorbis',
|
||||
'libopus',
|
||||
'-b:a',
|
||||
'96k',
|
||||
'-map_metadata',
|
||||
'-1',
|
||||
'-metadata',
|
||||
'title="e621.net_preview_quality_conversion,_visit_site_for_full_quality_download"',
|
||||
webm_file.path
|
||||
]
|
||||
mp4_args = [
|
||||
@ -86,9 +93,9 @@ class PostVideoConversionJob
|
||||
"-profile:v",
|
||||
"main",
|
||||
"-preset",
|
||||
"medium",
|
||||
"fast",
|
||||
"-crf",
|
||||
"22",
|
||||
"27",
|
||||
"-b:v",
|
||||
"3M",
|
||||
"-vf",
|
||||
@ -98,7 +105,13 @@ class PostVideoConversionJob
|
||||
"-max_muxing_queue_size",
|
||||
"4096",
|
||||
'-c:a',
|
||||
'copy',
|
||||
'aac',
|
||||
'-b:a',
|
||||
'128k',
|
||||
'-map_metadata',
|
||||
'-1',
|
||||
'-metadata',
|
||||
'title="e621.net_preview_quality_conversion,_visit_site_for_full_quality_download"',
|
||||
'-movflags',
|
||||
'+faststart',
|
||||
mp4_file.path
|
||||
@ -132,7 +145,10 @@ class PostVideoConversionJob
|
||||
post = Post.find(id)
|
||||
samples = generate_video_samples(post)
|
||||
move_videos(post, samples)
|
||||
post.update_attribute(:has_scaled_video_samples, true)
|
||||
post.reload
|
||||
known_samples = post.generated_samples || []
|
||||
known_samples += samples.keys.map(&:to_s)
|
||||
post.update_column(:generated_samples, known_samples.uniq)
|
||||
end
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
return
|
||||
|
@ -73,21 +73,21 @@ class StorageManager
|
||||
"?auth=#{hmac}&expires=#{time}&uid=#{user_id}"
|
||||
end
|
||||
|
||||
def file_url(post, type)
|
||||
def file_url_ext(post, type, ext, scale: nil)
|
||||
subdir = subdir_for(post.md5)
|
||||
file = file_name(post.md5, post.file_ext, type)
|
||||
file = file_name(post.md5, ext, type, scale_factor: scale)
|
||||
base = post.protect_file? ? "#{base_path}/#{protected_prefix}" : base_path
|
||||
|
||||
return "#{root_url}/images/download-preview.png" if type == :preview && !post.has_preview?
|
||||
path = if type == :preview
|
||||
"#{base}/preview/#{subdir}#{file}"
|
||||
elsif type == :crop
|
||||
"#{base}/crop/#{subdir}#{file}"
|
||||
elsif type == :large && post.has_large?
|
||||
"#{base}/sample/#{subdir}#{file}"
|
||||
else
|
||||
"#{base}/#{subdir}#{post.md5}.#{post.file_ext}"
|
||||
end
|
||||
"#{base}/preview/#{subdir}#{file}"
|
||||
elsif type == :crop
|
||||
"#{base}/crop/#{subdir}#{file}"
|
||||
elsif type == :large && post.has_large?
|
||||
"#{base}/sample/#{subdir}#{file}"
|
||||
else
|
||||
"#{base}/#{subdir}#{post.md5}.#{post.file_ext}"
|
||||
end
|
||||
if post.protect_file?
|
||||
"#{base_url}#{path}#{protected_params(path, post)}"
|
||||
else
|
||||
@ -95,6 +95,10 @@ class StorageManager
|
||||
end
|
||||
end
|
||||
|
||||
def file_url(post, type)
|
||||
file_url_ext(post, type, post.file_ext)
|
||||
end
|
||||
|
||||
def root_url
|
||||
origin = Addressable::URI.parse(base_url).origin
|
||||
origin = "" if origin == "null" # base_url was relative
|
||||
|
@ -33,6 +33,17 @@ class StorageManager::Local < StorageManager
|
||||
new_path = file_path(post, post.file_ext, type, true)
|
||||
move_file(path, new_path)
|
||||
end
|
||||
return unless post.is_video?
|
||||
Danbooru.config.video_rescales.each do |k,v|
|
||||
['mp4','webm'].each do |ext|
|
||||
path = file_path(post, ext, :scaled, false, scale_factor: k.to_s)
|
||||
new_path = file_path(post, ext, :scaled, true, scale_factor: k.to_s)
|
||||
move_file(path, new_path)
|
||||
end
|
||||
end
|
||||
path = file_path(post, 'mp4', :original, false)
|
||||
new_path = file_path(post, 'mp4', :original, true)
|
||||
move_file(path, new_path)
|
||||
end
|
||||
|
||||
def move_file_undelete(post)
|
||||
@ -41,6 +52,17 @@ class StorageManager::Local < StorageManager
|
||||
new_path = file_path(post, post.file_ext, type, false)
|
||||
move_file(path, new_path)
|
||||
end
|
||||
return unless post.is_video?
|
||||
Danbooru.config.video_rescales.each do |k,v|
|
||||
['mp4','webm'].each do |ext|
|
||||
path = file_path(post, ext, :scaled, true, scale_factor: k.to_s)
|
||||
new_path = file_path(post, ext, :scaled, false, scale_factor: k.to_s)
|
||||
move_file(path, new_path)
|
||||
end
|
||||
end
|
||||
path = file_path(post, 'mp4', :original, true)
|
||||
new_path = file_path(post, 'mp4', :original, false)
|
||||
move_file(path, new_path)
|
||||
end
|
||||
|
||||
private
|
||||
|
@ -135,6 +135,14 @@ class Post < ApplicationRecord
|
||||
storage_manager.file_url(self, :original)
|
||||
end
|
||||
|
||||
def file_url_ext(ext)
|
||||
storage_manager.file_url_ext(self, :original, ext)
|
||||
end
|
||||
|
||||
def scaled_url_ext(scale, ext)
|
||||
storage_manager.file_url_ext(self, :scaled, ext, scale: scale)
|
||||
end
|
||||
|
||||
def large_file_url
|
||||
storage_manager.file_url(self, :large)
|
||||
end
|
||||
@ -238,6 +246,10 @@ class Post < ApplicationRecord
|
||||
def has_ugoira_webm?
|
||||
true
|
||||
end
|
||||
|
||||
def has_sample_size?(scale)
|
||||
(generated_samples || []).include?(scale)
|
||||
end
|
||||
end
|
||||
|
||||
module ImageMethods
|
||||
@ -2022,7 +2034,6 @@ class Post < ApplicationRecord
|
||||
has_cropped
|
||||
hide_from_anonymous
|
||||
hide_from_search_engines
|
||||
has_scaled_video_samples
|
||||
)
|
||||
has_bit_flags BOOLEAN_ATTRIBUTES
|
||||
|
||||
|
@ -1,7 +1,12 @@
|
||||
<% if post.is_ugoira? %>
|
||||
<%= content_tag(:video, nil, :id => "image", class: post.display_class_for(CurrentUser.user), :"data-original-width" => post.image_width, :"data-original-height" => post.image_height, :loop => "true", :controls => "controls", :src => post.tagged_large_file_url) %>
|
||||
<% else %>
|
||||
<%= content_tag(:video, nil, :id => "image", class: post.display_class_for(CurrentUser.user), :"data-original-width" => post.image_width, :"data-original-height" => post.image_height, :loop => "true", :controls => "controls", poster: post.large_file_url, :src => post.tagged_file_url) %>
|
||||
<%= content_tag(:video, nil, id: 'image', class: post.display_class_for(CurrentUser.user), :"data-original-width" => post.image_width, :"data-original-height" => post.image_height, "data-rescales": post.generated_samples ,:loop => "true", :controls => "controls", poster: post.is_ugoira? ? nil : post.large_file_url) do %>
|
||||
<% if post.is_ugoira? %>
|
||||
<%= content_tag(:source, nil, src: post.large_file_url, type: 'video/webm') %>
|
||||
<% else %>
|
||||
<%= content_tag(:source, nil, src: post.file_url_ext('webm'), type: 'video/webm') %>
|
||||
<% if post.has_sample_size?('original') %>
|
||||
<%= content_tag(:source, nil, src: post.file_url_ext('mp4'), type: 'video/mp4') %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<%= javascript_tag nonce: true do -%>
|
||||
|
@ -991,6 +991,14 @@ fart'
|
||||
def metrika_enabled?
|
||||
false
|
||||
end
|
||||
|
||||
def video_rescales
|
||||
{'480p': [640, 480], '720p': [1280, 720]}
|
||||
end
|
||||
|
||||
def image_rescales
|
||||
[]
|
||||
end
|
||||
end
|
||||
|
||||
class EnvironmentConfiguration
|
||||
|
@ -1563,16 +1563,61 @@ CREATE TABLE public.post_replacements (
|
||||
image_width integer,
|
||||
image_height integer,
|
||||
md5 character varying,
|
||||
image_height_was integer,
|
||||
image_width_was integer,
|
||||
md5_was character varying,
|
||||
file_size_was integer,
|
||||
file_ext_was character varying,
|
||||
replacement_url text,
|
||||
original_url text
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- Name: post_replacements2; Type: TABLE; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE TABLE public.post_replacements2 (
|
||||
id bigint NOT NULL,
|
||||
created_at timestamp(6) without time zone NOT NULL,
|
||||
updated_at timestamp(6) without time zone NOT NULL,
|
||||
post_id integer NOT NULL,
|
||||
creator_id integer NOT NULL,
|
||||
creator_ip_addr inet NOT NULL,
|
||||
approver_id integer,
|
||||
file_ext character varying NOT NULL,
|
||||
file_size integer NOT NULL,
|
||||
image_height integer NOT NULL,
|
||||
image_width integer NOT NULL,
|
||||
md5 character varying NOT NULL,
|
||||
source character varying,
|
||||
file_name character varying,
|
||||
storage_id character varying NOT NULL,
|
||||
status character varying DEFAULT 'pending'::character varying NOT NULL,
|
||||
reason character varying NOT NULL,
|
||||
protected boolean DEFAULT false
|
||||
protected boolean DEFAULT false NOT NULL
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- Name: post_replacements2_id_seq; Type: SEQUENCE; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE SEQUENCE public.post_replacements2_id_seq
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
--
|
||||
-- Name: post_replacements2_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER SEQUENCE public.post_replacements2_id_seq OWNED BY public.post_replacements2.id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: post_replacements_id_seq; Type: SEQUENCE; Schema: public; Owner: -
|
||||
--
|
||||
@ -1844,7 +1889,8 @@ CREATE TABLE public.posts (
|
||||
comment_count integer DEFAULT 0 NOT NULL,
|
||||
change_seq bigint NOT NULL,
|
||||
tag_count_lore integer DEFAULT 0 NOT NULL,
|
||||
bg_color character varying
|
||||
bg_color character varying,
|
||||
generated_samples character varying[]
|
||||
);
|
||||
|
||||
|
||||
@ -2863,6 +2909,13 @@ ALTER TABLE ONLY public.post_image_hashes ALTER COLUMN id SET DEFAULT nextval('p
|
||||
ALTER TABLE ONLY public.post_replacements ALTER COLUMN id SET DEFAULT nextval('public.post_replacements_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- Name: post_replacements2 id; Type: DEFAULT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.post_replacements2 ALTER COLUMN id SET DEFAULT nextval('public.post_replacements2_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- Name: post_report_reasons id; Type: DEFAULT; Schema: public; Owner: -
|
||||
--
|
||||
@ -3351,6 +3404,14 @@ ALTER TABLE ONLY public.post_image_hashes
|
||||
ADD CONSTRAINT post_image_hashes_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: post_replacements2 post_replacements2_pkey; Type: CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.post_replacements2
|
||||
ADD CONSTRAINT post_replacements2_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: post_replacements post_replacements_pkey; Type: CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
@ -4204,6 +4265,20 @@ CREATE INDEX index_post_flags_on_reason_tsvector ON public.post_flags USING gin
|
||||
CREATE UNIQUE INDEX index_post_image_hashes_on_post_id ON public.post_image_hashes USING btree (post_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_post_replacements2_on_creator_id; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE INDEX index_post_replacements2_on_creator_id ON public.post_replacements2 USING btree (creator_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_post_replacements2_on_post_id; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE INDEX index_post_replacements2_on_post_id ON public.post_replacements2 USING btree (post_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_post_replacements_on_creator_id; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
@ -5004,7 +5079,8 @@ INSERT INTO "schema_migrations" (version) VALUES
|
||||
('20191231162515'),
|
||||
('20200113022639'),
|
||||
('20200420032714'),
|
||||
('20200510005635'),
|
||||
('20200713053034');
|
||||
('20200713053034'),
|
||||
('20200806101238'),
|
||||
('20200910015420');
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user