Skip to content

Commit

Permalink
accept encode stage filters
Browse files Browse the repository at this point in the history
  • Loading branch information
dfaker committed Feb 4, 2024
1 parent 114df09 commit 8fcbbb2
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 8 deletions.
24 changes: 23 additions & 1 deletion src/encoders/gifEncoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
import logging
import subprocess as sp

from ..ffmpegInfoParser import getVideoInfo

from math import sqrt

from ..encodingUtils import getFreeNameForFileAndLog
from ..encodingUtils import logffmpegEncodeProgress
from ..encodingUtils import isRquestCancelled
Expand Down Expand Up @@ -62,7 +66,25 @@ def encoderFunction(width,passNumber,passReason,passPhase=0,requestId=None,width
encoderStatusCallback(None,None,lastEncodedSize=finalSize)
return finalSize, psnr, returnCode

initialWidth = options.get('maximumWidth',1280)
initialWidth = options.get('maximumWidth',1280)

print('initialWidth',initialWidth)
print('inputsList',inputsList)
try:
if len(inputsList) == 2:
vi = getVideoInfo(inputsList[1])

if options.get('forceGifFPS',True):
vi.fps = 18

area = sizeLimitMax/(vi.duration*vi.fps)
print('area',area)
tw = int(sqrt(area*(vi.width/vi.height)))
th = int(sqrt(area*(vi.height/vi.width)))
initialWidth = int(max(tw,th)*1.2)
print('TARGET WIDTH',initialWidth)
except Exception as e:
print('TARGET WIDTH Exception',e)

encoderFunction.supportsCRQMode=False
optimiser = encodeTargetingSize_linear
Expand Down
4 changes: 2 additions & 2 deletions src/encoders/mp4AV1Encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ def encoderFunction(br,passNumber,passReason,passPhase=0, requestId=None,widthRe


if widthReduction>0.0:
encodefiltercommand = filtercommand+',[outv]scale=iw*(1-{widthReduction}):ih*(1-{widthReduction}):flags=bicubic[outvfinal]'.format(widthReduction=widthReduction)
encodefiltercommand = filtercommand+',{encodeStageFilter},[outv]scale=iw*(1-{widthReduction}):ih*(1-{widthReduction}):flags=bicubic[outvfinal]'.format(widthReduction=widthReduction,encodeStageFilter=encodeStageFilter)
else:
encodefiltercommand = filtercommand+',[outv]null[outvfinal]'.format(widthReduction=widthReduction)
encodefiltercommand = filtercommand+',[outv]null,{encodeStageFilter}[outvfinal]'.format(encodeStageFilter=encodeStageFilter)

if options.get('audioChannels') == 'No audio':
encodefiltercommand+=',[outa]anullsink'
Expand Down
4 changes: 2 additions & 2 deletions src/encoders/mp4x264Encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ def encoderFunction(br,passNumber,passReason,passPhase=0,requestId=None,widthRed
ffmpegcommand+=inputsList

if widthReduction>0.0:
encodefiltercommand = filtercommand+',[outv]scale=iw*(1-{widthReduction}):ih*(1-{widthReduction}):flags=bicubic[outvfinal]'.format(widthReduction=widthReduction)
encodefiltercommand = filtercommand+',{encodeStageFilter},[outv]scale=iw*(1-{widthReduction}):ih*(1-{widthReduction}):flags=bicubic[outvfinal]'.format(widthReduction=widthReduction,encodeStageFilter=encodeStageFilter)
else:
encodefiltercommand = filtercommand+',[outv]null[outvfinal]'.format(widthReduction=widthReduction)
encodefiltercommand = filtercommand+',[outv]null,{encodeStageFilter}[outvfinal]'.format(encodeStageFilter=encodeStageFilter)

if options.get('audioChannels') == 'No audio':
encodefiltercommand+=',[outa]anullsink'
Expand Down
7 changes: 4 additions & 3 deletions src/encoders/mp4x264NvencEncoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ def encoderFunction(br,passNumber,passReason,passPhase=0,requestId=None,widthRed
ffmpegcommand+=inputsList

if widthReduction>0.0:
encodefiltercommand = filtercommand+',[outv]scale=iw*(1-{widthReduction}):ih*(1-{widthReduction}):flags=bicubic[outvfinal]'.format(widthReduction=widthReduction)
encodefiltercommand = filtercommand+',{encodeStageFilter},[outv]scale=iw*(1-{widthReduction}):ih*(1-{widthReduction}):flags=bicubic[outvfinal]'.format(widthReduction=widthReduction,encodeStageFilter=encodeStageFilter)
else:
encodefiltercommand = filtercommand+',[outv]null[outvfinal]'.format(widthReduction=widthReduction)
encodefiltercommand = filtercommand+',[outv]null,{encodeStageFilter}[outvfinal]'.format(encodeStageFilter=encodeStageFilter)


if options.get('audioChannels') == 'No audio':
encodefiltercommand+=',[outa]anullsink'
Expand Down Expand Up @@ -131,7 +132,7 @@ def encoderFunction(br,passNumber,passReason,passPhase=0,requestId=None,widthRed
logging.debug("Ffmpeg command: {}".format(' '.join(ffmpegcommand)))
print("Ffmpeg command: {}".format(' '.join(ffmpegcommand)))

encoderStatusCallback('Encoding final '+videoFileName,(totalEncodedSeconds)/totalExpectedEncodedSeconds)
encoderStatusCallback('Encoding final '+videoFileName,(totalEncodedSeconds)/totalExpectedEncodedSeconds,pix_fmt='')
proc = sp.Popen(ffmpegcommand,stderr=sp.PIPE,stdin=sp.DEVNULL,stdout=sp.DEVNULL)

encoderStatusCallback(None,None, lastEncodedBR=br, lastEncodedSize=None, lastBuff=bufsize, lastWR=widthReduction)
Expand Down

0 comments on commit 8fcbbb2

Please sign in to comment.