mirror of
https://github.com/k4yt3x/video2x.git
synced 2026-02-16 02:10:35 +08:00
2.6.0 complete redesign of configuration file, with lots of enhancements
This commit is contained in:
@@ -4,11 +4,12 @@
|
||||
Name: FFMPEG Class
|
||||
Author: K4YT3X
|
||||
Date Created: Feb 24, 2018
|
||||
Last Modified: March 4, 2019
|
||||
Last Modified: March 9, 2019
|
||||
|
||||
Description: This class handles all FFMPEG related
|
||||
operations.
|
||||
"""
|
||||
from avalon_framework import Avalon
|
||||
import json
|
||||
import subprocess
|
||||
|
||||
@@ -21,11 +22,22 @@ class Ffmpeg:
|
||||
and inserting audio tracks to videos.
|
||||
"""
|
||||
|
||||
def __init__(self, ffmpeg_path, ffmpeg_arguments, hardware_acc=False):
|
||||
self.ffmpeg_path = ffmpeg_path
|
||||
self.ffmpeg_binary = '\"{}ffmpeg.exe\"'.format(ffmpeg_path)
|
||||
self.hardware_acc = hardware_acc
|
||||
self.ffmpeg_arguments = ffmpeg_arguments
|
||||
def __init__(self, ffmpeg_settings):
|
||||
self.ffmpeg_settings = ffmpeg_settings
|
||||
self._parse_settings()
|
||||
|
||||
def _parse_settings(self):
|
||||
""" Parse ffmpeg settings
|
||||
"""
|
||||
self.ffmpeg_path = self.ffmpeg_settings['ffmpeg_path']
|
||||
# Add a forward slash to directory if not present
|
||||
# otherwise there will be a format error
|
||||
if self.ffmpeg_path[-1] != '/' and self.ffmpeg_path[-1] != '\\':
|
||||
self.ffmpeg_path = '{}/'.format(self.ffmpeg_path)
|
||||
|
||||
self.ffmpeg_binary = '\"{}ffmpeg.exe\"'.format(self.ffmpeg_path)
|
||||
self.ffmpeg_hwaccel = self.ffmpeg_settings['ffmpeg_hwaccel']
|
||||
self.extra_arguments = self.ffmpeg_settings['extra_arguments']
|
||||
|
||||
def get_video_info(self, input_video):
|
||||
""" Gets input video information
|
||||
@@ -39,7 +51,9 @@ class Ffmpeg:
|
||||
Returns:
|
||||
dictionary -- JSON text of input video information
|
||||
"""
|
||||
json_str = subprocess.check_output('\"{}ffprobe.exe\" -v quiet -print_format json -show_format -show_streams \"{}\"'.format(self.ffmpeg_path, input_video))
|
||||
execute = '\"{}ffprobe.exe\" -v quiet -print_format json -show_format -show_streams \"{}\"'.format(self.ffmpeg_path, input_video)
|
||||
Avalon.debug_info('Executing: {}'.format(execute))
|
||||
json_str = subprocess.check_output(execute)
|
||||
return json.loads(json_str.decode('utf-8'))
|
||||
|
||||
def extract_frames(self, input_video, extracted_frames):
|
||||
@@ -53,8 +67,8 @@ class Ffmpeg:
|
||||
extracted_frames {string} -- video output folder
|
||||
"""
|
||||
execute = '{} -i \"{}\" \"{}\"\\extracted_%0d.png -y {}'.format(
|
||||
self.ffmpeg_binary, input_video, extracted_frames, ' '.join(self.ffmpeg_arguments))
|
||||
print('Executing: {}'.format(execute))
|
||||
self.ffmpeg_binary, input_video, extracted_frames, ' '.join(self.extra_arguments))
|
||||
Avalon.debug_info('Executing: {}'.format(execute))
|
||||
subprocess.run(execute, shell=True, check=True)
|
||||
|
||||
def convert_video(self, framerate, resolution, upscaled_frames):
|
||||
@@ -69,8 +83,8 @@ class Ffmpeg:
|
||||
upscaled_frames {string} -- source images folder
|
||||
"""
|
||||
execute = '{} -r {} -f image2 -s {} -i \"{}\"\\extracted_%d.png -vcodec libx264 -crf 25 -pix_fmt yuv420p \"{}\"\\no_audio.mp4 -y {}'.format(
|
||||
self.ffmpeg_binary, framerate, resolution, upscaled_frames, upscaled_frames, ' '.join(self.ffmpeg_arguments))
|
||||
print('Executing: {}'.format(execute))
|
||||
self.ffmpeg_binary, framerate, resolution, upscaled_frames, upscaled_frames, ' '.join(self.extra_arguments))
|
||||
Avalon.debug_info('Executing: {}'.format(execute))
|
||||
subprocess.run(execute, shell=True, check=True)
|
||||
|
||||
def migrate_audio_tracks_subtitles(self, input_video, output_video, upscaled_frames):
|
||||
@@ -82,8 +96,8 @@ class Ffmpeg:
|
||||
upscaled_frames {string} -- directory containing upscaled frames
|
||||
"""
|
||||
execute = '{} -i \"{}\"\\no_audio.mp4 -i \"{}\" -map 0:v:0? -map 1? -c copy -map -1:v? \"{}\" -y {}'.format(
|
||||
self.ffmpeg_binary, upscaled_frames, input_video, output_video, ' '.join(self.ffmpeg_arguments))
|
||||
self.ffmpeg_binary, upscaled_frames, input_video, output_video, ' '.join(self.extra_arguments))
|
||||
# execute = '{} -i \"{}\"\\no_audio.mp4 -i \"{}\" -c:a copy -c:v copy -c:s copy -map 0:v? -map 1:a? -map 1:s? \"{}\" -y {}'.format(
|
||||
# self.ffmpeg_binary, upscaled_frames, input_video, output_video, ' '.join(self.ffmpeg_arguments))
|
||||
print('Executing: {}'.format(execute))
|
||||
Avalon.debug_info('Executing: {}'.format(execute))
|
||||
subprocess.run(execute, shell=True, check=True)
|
||||
|
||||
Reference in New Issue
Block a user