Skip to content

Commit

Permalink
Add subtitle offset workarounds
Browse files Browse the repository at this point in the history
  • Loading branch information
dfaker authored Aug 30, 2021
1 parent e6edd63 commit 004a70a
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 9 deletions.
29 changes: 27 additions & 2 deletions src/ffmpegService.py
Original file line number Diff line number Diff line change
Expand Up @@ -595,14 +595,37 @@ def encodeConcat(tempPathname,outputPathName,runNumber,requestId,mode,seqClips,o
if filterexp=='':
filterexp='null'

basename = os.path.basename(clipfilename)
basename = ''.join([x for x in basename if x in string.digits+string.ascii_letters+' -_'])[:10]

if 'subtitles=filename=' in filterexp:

m = hashlib.md5()
m.update(filterexp.encode('utf8'))
filterHash = m.hexdigest()[:10]

subfilename = filterexp.split('subtitles=filename=')[1].split(':force_style=')[0]
subfilenameStrip = subfilename.replace("'",'')
subOutname = os.path.join( tempPathname,'{}_{}_{}_{}_{}_{}.srt'.format(i,basename,start,end,filterHash,runNumber) )

subcmd = ['ffmpeg','-y','-ss' , str(start), '-itsoffset', str(0-start), '-i', subfilenameStrip.replace('\\:',':'), '-c', 'copy', subOutname]
print(' '.join(subcmd))
subProc = sp.Popen(subcmd)
subProc.communicate()

cleanSubPath = os.path.abspath(subOutname).replace('\\','/').replace(':','\\:')
filterexp = filterexp.replace(subfilenameStrip,cleanSubPath)

print(subfilenameStrip)
print(subOutname)
print(filterexp)

#scale=1280:720:force_original_aspect_ratio=increase,crop=1280:720

filterexp+=",scale='if(gte(iw,ih),max(0,min({maxDim},iw)),-2):if(gte(iw,ih),-2,max(0,min({maxDim},ih)))':flags=bicubic".format(maxDim=options.get('maximumWidth',1280))
filterexp += ',pad=ceil(iw/2)*2:ceil(ih/2)*2'

key = (rid,clipfilename,start,end,filterexp,filterexpEnc)

basename = os.path.basename(clipfilename)

try:
os.path.exists(tempPathname) or os.mkdir(tempPathname)
Expand All @@ -613,6 +636,8 @@ def encodeConcat(tempPathname,outputPathName,runNumber,requestId,mode,seqClips,o
m.update(filterexp.encode('utf8'))
filterHash = m.hexdigest()[:10]

key = (rid,clipfilename,start,end,filterexp,filterexpEnc)
basename = os.path.basename(clipfilename)
basename = ''.join([x for x in basename if x in string.digits+string.ascii_letters+' -_'])[:10]

outname = '{}_{}_{}_{}_{}_{}.mp4'.format(i,basename,start,end,filterHash,runNumber)
Expand Down
55 changes: 48 additions & 7 deletions src/filterSpec.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,17 @@
"filter": "convolution='-2 -1 0 -1 1 1 0 1 2:-2 -1 0 -1 1 1 0 1 2:-2 -1 0 -1 1 1 0 1 2:-2 -1 0 -1 1 1 0 1 2'",

},

{
"name": "scaleDown",
"filter": "scale=w=iw*{factor}2:h=ih*{factor}:sws_flags=area",
"params": [
{"n": "factor", "d": 1.0, "type": "float", "range": [0, 1], "inc": 0.005}
]
},



{
"name": "lagfun",
"filter": "lagfun",
Expand Down Expand Up @@ -390,19 +401,49 @@

{
"name": "subtitles",
"filter": "subtitles",
"filter": "subtitles=filename='{filename}':force_style='Fontname={fontname},PrimaryColour={colour}'",
"params": [
{"n": "filename", "d": "subtitles.srt", "type": "string"},
{
"n": "force_style",
"d": "Fontname=DejaVu Serif,PrimaryColour=&HCCFF0000",
"type": "string",
},
{"n": "filename", "d": "subtitles.srt", "type": "file"},
{"n": "fontname", "d": "font.otf", "type": "file"},
{"n": "colour", "d": "&H0059EADB", "type": "string"}


],
},

{"name": "normalize", "filter": "normalize"},



{
"name": "fade",
"filter": "fade",
"params": [
{
"n": "type",
"d": "in",
"type": "cycle",
"cycle": ["in", "out"],
},

{"n": "duration", "d": 1, "type": "float", "range": [0, None], "inc": 0.1},
{"n": "start_time", "d": 1, "type": "float", "range": [0, None], "inc": 0.1},


{
"n": "color",
"d": "Black",
"type": "cycle",
"cycle": colours,
}

],
},





{
"name": "minterpolate",
"filter": "minterpolate",
Expand Down

0 comments on commit 004a70a

Please sign in to comment.