@@ -238,8 +238,8 @@ def main(argv=sys.argv[1:]):
238238 help = 'Number of encoding threads. Default: unset, autodetect' )
239239 parser .add_argument ('--wait' , action = 'store_true' ,
240240 help = 'Wait after each encoding (don\' t clean up the temporary directory right away' )
241- parser .add_argument ('--no-mkv-chapters ' , action = 'store_false' , default = True , dest = 'mkv_chapters ' ,
242- help = "Don't try to encode the chapters and description into the mkv file. This requires mkvnixtools to be installed" )
241+ parser .add_argument ('--no-mkv-props ' , action = 'store_false' , default = True , dest = 'mkv_props ' ,
242+ help = "Don't try to encode extra properties into the mkv file. This requires mkvnixtools to be installed" )
243243 parser .add_argument ('--list' , action = 'store_true' ,
244244 help = "Don't do anything, just list all outputs that would be processed (and nothing else)" )
245245
@@ -471,6 +471,13 @@ def main(argv=sys.argv[1:]):
471471 options_ffmpeg_segment = [ ]
472472 segment_type = 'video'
473473
474+ output = args .output / segment ['output' ]
475+
476+ # Subtitles
477+ if args .srt :
478+ srt_output = os .path .splitext (output )[0 ] + '.srt'
479+ open (srt_output , 'w' ).write (srt .compose (subtitles ))
480+
474481 # Create the playlist of inputs
475482 playlist = Path (tmpdir ) / 'playlist.txt'
476483 with open (playlist , 'w' ) as playlist_f :
@@ -479,7 +486,6 @@ def main(argv=sys.argv[1:]):
479486 LOG .debug ("Playlist:" )
480487 LOG .debug (open (playlist ).read ())
481488 # Re-encode
482- output = args .output / segment ['output' ]
483489 ensure_filedir_exists (output )
484490 if output in all_inputs :
485491 raise RuntimeError ("Output is the same as an input file, aborting." )
@@ -497,6 +503,17 @@ def main(argv=sys.argv[1:]):
497503 if not args .check :
498504 subprocess .check_call (cmd )
499505
506+ # Embed subtitles in mkv if they are there
507+ if srt and args .mkv_props :
508+ cmd = ['mkvmerge' , tmpdir_out , srt_output ,
509+ '-o' , tmpdir_out + '.2.mkv' ,
510+ ]
511+ print (cmd )
512+ if not args .check :
513+ subprocess .check_call (cmd )
514+ shutil .move (tmpdir_out + '.2.mkv' , tmpdir_out )
515+
516+
500517 # Create the video properties/chapters/etc (needs to be done before
501518 # making the final mkv because it gets encoded into the mkv file).
502519
@@ -547,7 +564,7 @@ def main(argv=sys.argv[1:]):
547564 * (['--attachment-name' , 'description' , '--add-attachment' , video_description_file ] if video_description else []),
548565 ]
549566 print (cmd )
550- if not args .check and args .mkv_chapters :
567+ if not args .check and args .mkv_props :
551568 subprocess .check_call (cmd )
552569
553570
@@ -560,12 +577,6 @@ def main(argv=sys.argv[1:]):
560577 with atomic_write (output ) as tmp_output :
561578 shutil .move (tmpdir_out , tmp_output )
562579
563- # Subtitles
564- if args .srt :
565- srt_output = os .path .splitext (output )[0 ] + '.srt'
566- open (srt_output , 'w' ).write (srt .compose (subtitles ))
567-
568-
569580 # Print out covered segments (for verification purposes)
570581 for seg_n , time in covers :
571582 new_time = map_time (seg_n , segment_list , time )
0 commit comments