|
30 | 30 | PARAM_AUDIO = config_manager.config.get_list("M3U8_CONVERSION", "param_audio") |
31 | 31 | PARAM_FINAL = config_manager.config.get_list("M3U8_CONVERSION", "param_final") |
32 | 32 | SUBTITLE_DISPOSITION = config_manager.config.get_bool("M3U8_CONVERSION", "subtitle_disposition") |
| 33 | +SUBTITLE_DISPOSITION_LANGUAGE = config_manager.config.get("M3U8_CONVERSION", "subtitle_disposition_language") |
33 | 34 |
|
34 | 35 |
|
35 | 36 | def add_encoding_params(ffmpeg_cmd: List[str]): |
@@ -200,9 +201,21 @@ def join_subtitle(video_path: str, subtitles_list: List[Dict[str, str]], out_pat |
200 | 201 | # For subtitles, we always use copy for video/audio |
201 | 202 | ffmpeg_cmd.extend(['-c:v', 'copy', '-c:a', 'copy', '-c:s', subtitle_codec]) |
202 | 203 |
|
203 | | - # Set disposition for first subtitle if enabled |
| 204 | + # Set disposition for subtitle matching the configured language |
204 | 205 | if SUBTITLE_DISPOSITION and len(subtitles_list) > 0: |
205 | | - ffmpeg_cmd.extend(['-disposition:s:0', 'default+forced']) |
| 206 | + disposition_idx = None |
| 207 | + for idx, subtitle in enumerate(subtitles_list): |
| 208 | + if subtitle.get('language', '').lower() == SUBTITLE_DISPOSITION_LANGUAGE.lower(): |
| 209 | + disposition_idx = idx |
| 210 | + break |
| 211 | + |
| 212 | + # If matching subtitle found, set disposition, otherwise use first subtitle |
| 213 | + if disposition_idx is not None: |
| 214 | + console.log(f"[cyan]Setting subtitle disposition for language: [red]{SUBTITLE_DISPOSITION_LANGUAGE}") |
| 215 | + ffmpeg_cmd.extend([f'-disposition:s:{disposition_idx}', 'default+forced']) |
| 216 | + else: |
| 217 | + console.log(f"[cyan]Using first subtitle for disposition.") |
| 218 | + ffmpeg_cmd.extend(['-disposition:s:0', 'default+forced']) |
206 | 219 |
|
207 | 220 | # Overwrite |
208 | 221 | ffmpeg_cmd += [out_path, "-y"] |
|
0 commit comments