Skip to content

Commit

Permalink
Support audio_format=caf for AnkiMobile (#120)
Browse files Browse the repository at this point in the history
* Support `audio_format=caf` for AnkiMobile

* update subs2srs.conf

* add a note about caf
---------

Co-authored-by: Ren Tatsumoto <[email protected]>
  • Loading branch information
abdnh and tatsumoto-ren authored Feb 2, 2024
1 parent f1b6541 commit c28d793
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 2 deletions.
5 changes: 4 additions & 1 deletion .github/RELEASE/subs2srs.conf
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,12 @@ animated_snapshot_quality=5
##

# Audio format.
# Do not switch to `mp3` unless your computer doesn't support `opus`.
# Opus is the recommended format.
# It may be required to use a different format when Opus is not supported.
# This is the case on certain computers or devices which are running proprietary operating systems.
audio_format=opus
#audio_format=mp3
#audio_format=caf

# Sane values are 16k-32k for opus, 64k-128k for mp3.
audio_bitrate=24k
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,13 @@ set `audio_format` to `mp3` and/or `snapshot_format` to `jpg`.
Otherwise, I recommend sticking with `opus` and `webp`,
as they greatly reduce the size of the generated files.

If you still use AnkiMobile (the [proprietary](https://www.gnu.org/proprietary/) Anki app),
set `audio_format` to [caf](https://en.wikipedia.org/wiki/Core_Audio_Format) for compatibility.
The resulting files will use `Opus` as the coding format and Apple's Core Audio
format as the container format, but will still have the `.ogg` extension to make
it easier to open in media players because the `.caf` extension is not commonly
recognized.

If no matter what mpvacious fails to create audio clips and/or snapshots,
change `use_ffmpeg` to `yes`.
By using ffmpeg instead of the encoder built in mpv you can work around most encoder issues.
Expand Down
4 changes: 3 additions & 1 deletion cfg_mgr.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ local default_profile_filename = 'subs2srs'
local profiles_filename = 'subs2srs_profiles'

local function set_audio_format()
if self.config.audio_format == 'opus' then
if self.config.audio_format == 'opus' or self.config.audio_format == 'caf' then
-- https://opus-codec.org/
-- https://en.wikipedia.org/wiki/Core_Audio_Format
self.config.audio_codec = 'libopus'
self.config.audio_extension = '.ogg'
else
Expand Down
2 changes: 2 additions & 0 deletions encoder.lua
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ ffmpeg.make_audio_args = function(source_path, output_path, start_timestamp, end
'-map', string.format("0:%s", tostring(audio_track_id)),
'-ac', '1',
'-codec:a', self.config.audio_codec,
'-f', self.config.audio_format,
'-vbr', 'on',
'-compression_level', '10',
'-application', 'voip',
Expand Down Expand Up @@ -244,6 +245,7 @@ mpv.make_audio_args = function(source_path, output_path, start_timestamp, end_ti
'--oacopts-add=application=voip',
'--oacopts-add=compression_level=10',
table.concat { '--oac=', self.config.audio_codec },
table.concat { '--of=', self.config.audio_format },
table.concat { '--start=', toms(start_timestamp), },
table.concat { '--end=', toms(end_timestamp), },
table.concat { '--aid=', audio_track_id },
Expand Down
1 change: 1 addition & 0 deletions utils/forvo.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ local function reencode(source_path, dest_path)
'--oacopts-add=compression_level=10',
'--af-append=silenceremove=1:0:-50dB',
table.concat { '--oac=', self.config.audio_codec },
table.concat { '--of=', self.config.audio_format },
table.concat { '--oacopts-add=b=', self.config.audio_bitrate },
table.concat { '-o=', dest_path }
}
Expand Down

0 comments on commit c28d793

Please sign in to comment.