Skip to content

Commit

Permalink
fix: resolve video stutter and add timestamp output formatting (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
jveldboom authored Jun 23, 2023
1 parent ff0b86b commit dead6cc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ docker run --rm -it -v $(pwd):/data video-swear-jar \
- [ ] Add unit tests
- [ ] Clean up files after process is complete
- [ ] Allow users to pass in a custom swear-words.json file (replace or add)
- [ ] Reduce container image size -- ideally less than 1GB
- [ ] Reduce linux/amd64 container image size -- ideally less than 1GB

## Notes
### Alternatives
Expand Down
18 changes: 15 additions & 3 deletions src/video.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ const createCutFile = ({ transcript, paths }) => {
let inpoint = 0

for (const segment of transcript) {
const start = segment.start
const end = segment.end
const start = Math.floor(segment.start)
const end = Math.ceil(segment.end)

ffmpegCuts.push(`file '${paths.cutVideo}'`)
ffmpegCuts.push(`inpoint ${inpoint}`)
ffmpegCuts.push(`outpoint ${start}`)

inpoint = end
if (paths.cutWords) cutWords.push(`${start}-${inpoint}\t${segment.text.trim()}`)
if (paths.cutWords) cutWords.push(`${formatTime(start)} - ${formatTime(inpoint)}\t${segment.text.trim()}`)
}

// write ending inpoint to bring in remaining video
Expand All @@ -74,6 +74,18 @@ const createCutFile = ({ transcript, paths }) => {
if (paths.cutWords) fs.writeFileSync(paths.cutWords, cutWords.join('\n'))
}

const formatTime = (seconds) => {
const hours = Math.floor(seconds / 3600)
const minutes = Math.floor((seconds % 3600) / 60)
const remainingSeconds = seconds % 60

const formattedHours = String(hours).padStart(2, '0')
const formattedMinutes = String(minutes).padStart(2, '0')
const formattedSeconds = String(remainingSeconds).padStart(2, '0')

return `${formattedHours}:${formattedMinutes}:${formattedSeconds}`
}

module.exports = {
transcribe,
cut,
Expand Down

0 comments on commit dead6cc

Please sign in to comment.