Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Kdenlive
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
259
Issues
259
List
Boards
Labels
Service Desk
Milestones
Merge Requests
14
Merge Requests
14
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Multimedia
Kdenlive
Commits
2119cd1d
Commit
2119cd1d
authored
Nov 03, 2020
by
Sashmita Raghav
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Correct subtitle filter name and enable writing to SRT files
parent
01f501bb
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
10 deletions
+31
-10
src/bin/model/subtitlemodel.cpp
src/bin/model/subtitlemodel.cpp
+31
-10
No files found.
src/bin/model/subtitlemodel.cpp
View file @
2119cd1d
...
...
@@ -18,7 +18,7 @@ SubtitleModel::SubtitleModel(Mlt::Tractor *tractor, QObject *parent)
{
qDebug
()
<<
"subtitle constructor"
;
m_subtitleFilter
=
nullptr
;
m_subtitleFilter
.
reset
(
new
Mlt
::
Filter
(
pCore
->
getCurrentProfile
()
->
profile
(),
"av
.filename
"
));
m_subtitleFilter
.
reset
(
new
Mlt
::
Filter
(
pCore
->
getCurrentProfile
()
->
profile
(),
"av
filter.subtitles
"
));
qDebug
()
<<
"Filter!"
;
if
(
tractor
!=
nullptr
)
{
qDebug
()
<<
"Tractor!"
;
...
...
@@ -411,23 +411,27 @@ QString SubtitleModel::toJson()
void
SubtitleModel
::
jsontoSubtitle
(
const
QString
&
data
)
{
QString
outFile
=
"path_to_
subtitle_fi
le.ass"
;
QString
outFile
=
"path_to_
temp_Subtit
le.ass"
;
if
(
!
outFile
.
contains
(
".ass"
))
return
;
// this function currrently writes in ass file format only
qDebug
()
<<
"srt file import"
;
// if imported file isn't .ass, it is .srt format
QFile
outF
(
outFile
);
qDebug
()
<<
"Import from JSON"
;
QWriteLocker
locker
(
&
m_lock
);
auto
json
=
QJsonDocument
::
fromJson
(
data
.
toUtf8
());
if
(
!
json
.
isArray
())
{
qDebug
()
<<
"Error : Json file should be an array"
;
return
;
}
int
line
=
0
;
auto
list
=
json
.
array
();
if
(
outF
.
open
(
QIODevice
::
WriteOnly
))
{
QTextStream
out
(
&
outF
);
out
<<
scriptInfoSection
<<
endl
;
out
<<
styleSection
<<
endl
;
out
<<
eventSection
;
if
(
outFile
.
contains
(
".ass"
))
{
out
<<
scriptInfoSection
<<
endl
;
out
<<
styleSection
<<
endl
;
out
<<
eventSection
;
}
for
(
const
auto
&
entry
:
list
)
{
if
(
!
entry
.
isObject
())
{
qDebug
()
<<
"Warning : Skipping invalid subtitle data"
;
...
...
@@ -439,7 +443,7 @@ void SubtitleModel::jsontoSubtitle(const QString &data)
continue
;
}
double
startPos
=
entryObj
[
QLatin1String
(
"startPos"
)].
toDouble
();
//convert seconds to FORMAT= h
:mm:ss.SS
//convert seconds to FORMAT= h
h:mm:ss.SS (in .ass) and hh:mm:ss,SSS (in .srt)
int
millisec
=
startPos
*
1000
;
int
seconds
=
millisec
/
1000
;
millisec
%=
1000
;
...
...
@@ -453,6 +457,11 @@ void SubtitleModel::jsontoSubtitle(const QString &data)
.
arg
(
minutes
,
2
,
10
,
QChar
(
'0'
))
.
arg
(
seconds
,
2
,
10
,
QChar
(
'0'
))
.
arg
(
milli_2
,
2
,
10
,
QChar
(
'0'
));
QString
startTimeStringSRT
=
QString
(
"%1:%2:%3,%4"
)
.
arg
(
hours
,
1
,
10
,
QChar
(
'0'
))
.
arg
(
minutes
,
2
,
10
,
QChar
(
'0'
))
.
arg
(
seconds
,
2
,
10
,
QChar
(
'0'
))
.
arg
(
millisec
,
3
,
10
,
QChar
(
'0'
));
QString
dialogue
=
entryObj
[
QLatin1String
(
"dialogue"
)].
toString
();
double
endPos
=
entryObj
[
QLatin1String
(
"endPos"
)].
toDouble
();
millisec
=
endPos
*
1000
;
...
...
@@ -463,14 +472,26 @@ void SubtitleModel::jsontoSubtitle(const QString &data)
hours
=
minutes
/
60
;
minutes
%=
60
;
milli_2
=
millisec
/
10
;
// to limit ms to 2 digits
milli_2
=
millisec
/
10
;
// to limit ms to 2 digits
(for .ass)
QString
endTimeString
=
QString
(
"%1:%2:%3.%4"
)
.
arg
(
hours
,
1
,
10
,
QChar
(
'0'
))
.
arg
(
minutes
,
2
,
10
,
QChar
(
'0'
))
.
arg
(
seconds
,
2
,
10
,
QChar
(
'0'
))
.
arg
(
milli_2
,
2
,
10
,
QChar
(
'0'
));
//Format: Layer, Start, End, Style, Actor, MarginL, MarginR, MarginV, Effect, Text
out
<<
"Dialogue: 0,"
<<
startTimeString
<<
","
<<
endTimeString
<<
","
<<
styleName
<<
",,0000,0000,0000,,"
<<
dialogue
<<
endl
;
QString
endTimeStringSRT
=
QString
(
"%1:%2:%3,%4"
)
.
arg
(
hours
,
1
,
10
,
QChar
(
'0'
))
.
arg
(
minutes
,
2
,
10
,
QChar
(
'0'
))
.
arg
(
seconds
,
2
,
10
,
QChar
(
'0'
))
.
arg
(
millisec
,
3
,
10
,
QChar
(
'0'
));
line
++
;
if
(
outFile
.
contains
(
".ass"
))
{
//Format: Layer, Start, End, Style, Actor, MarginL, MarginR, MarginV, Effect, Text
out
<<
"Dialogue: 0,"
<<
startTimeString
<<
","
<<
endTimeString
<<
","
<<
styleName
<<
",,0000,0000,0000,,"
<<
dialogue
<<
endl
;
}
if
(
outFile
.
contains
(
".srt"
))
out
<<
line
<<
"
\n
"
<<
startTimeStringSRT
<<
" --> "
<<
endTimeStringSRT
<<
"
\n
"
<<
dialogue
<<
"
\n
"
<<
endl
;
//qDebug() << "ADDING SUBTITLE to FILE AT START POS: " << startPos <<" END POS: "<<endPos;//<< ", FPS: " << pCore->getCurrentFps();
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment