本來這個blog是記錄開發輸入法的點滴的,後來越來越雜,現在什麼都記錄了。

2009年2月6日 星期五

Howto convert TV recorded program (trp format) with subtitle to mkv format?

  1. Install the following free software
    • K-lite codec pack,
    • Virtual Dub
    • VobSub
    • Project-X
    • TSRemux
    • mkvtoolnix
    • AviSynth
    • ffmpeg (WinFF)
    • Son2VSub
       
  2. Assume the video files are recorded and are in
    • D:\temp\~DATA\DATA00.trp
    • D:\temp\~DATA\DATA01.trp
    • D:\temp\~DATA\DATA02.trp


  3. Join the 3 trp files into one.
    • In START menu, Run, type cmd.
    • Type the following:
      • d:
      • cd d:\temp\~DATA
      • type DATA00.trp DATA01.trp DATA02.trp > final.trp
        Microsoft Windows [? 6.0.6001]
        Copyright (c) 2006 Microsoft Corporation. All rights reserved.

        C:\Users\ylam>d:

        D:\>d:

        D:\>cd d:\temp

        d:\temp>cd ~DATA

        d:\temp\~DATA>type DATA00.trp DATA01.trp DATA02.trp > final.trp

        DATA00.trp

        DATA01.trp

        DATA02.trp

        d:\temp\~DATA>

  4. Extract subtitle information:
    • Open Project-X http://sourceforge.net/projects/project-x
    • In menu Presettings -> subtitle tab:
      • Simulate DVB subpictures IRD color model, choose NRX
      • tick "additional export as VobSub (idx+sub)



         
      • Choose to export only subtitle

         
      • Add final.trp, choose Quick start

         
      • You should be able to see many files generated.
        Keep only final.sup.sub, final.sub.idx and remove other files generated
         
  5. Use TSRemux to convert the final.trp to final.ts.
    Choose only 1 video and 1 audio stream.
    Note: for audio stream, the one with smaller number is the original language.

     
  6. Adjust the subtitle color:
    • Open the program SubResync in VobSub.
    • Drag final.sup.idx into SubResync.
    • Quickly browse the subtitle, you will find some of them are not very clear:

      To fix this problem:
      • Save the subtitle in DVDMaestro format in a separate directory, say "son".
      • In son\final.sup.son, modify it from:
        Directory .
        Subtitle final.sup
        Display_Area (0 2 719 575)
        Contrast (15 15 15 0)

        SP_NUMBER START END FILE_NAME
        Color (1 14 0 15)
        Contrast (15 15 0 15)

        0001 00:01:00:20 00:01:02:13 final.sup_0001.bmp
        Color (1 2 0 8)
        Contrast (11 15 0 15)

        0002 00:01:09:11 00:01:13:23 final.sup_0002.bmp
        Color (15 2 0 13)
        Contrast (8 15 0 15)

        0003 00:01:14:01 00:01:17:11 final.sup_0003.bmp
        to

        Subtitle    final.sup
        Display_Area  (0 2 719 575)
        Contrast   (15 15 0 15)
        Color       (1 2 0 3)

        SP_NUMBER START    END        FILE_NAME
        0001  00:02:44:13  00:02:46:06   final.sup_0001.bmp
        0002  00:02:46:10  00:02:49:03   final.sup_0002.bmp
        0003  00:02:59:21  00:03:01:05   final.sup_0003.bmp


        Note that color with index 0 is a transparent color.
         
      • Start the Son2VSub program.
        Open the son\final.sup.son directory.
        Change the output from 720x480 to 720x576

         
      • In the output file son\final.idx file, change from

        # The original palette of the DVD in PGC#1
        palette: 000060, 2b2b2b, 2c2c2c, 353535, 535353, 414141, 626262, 7c7c7c, a9a9a9, c8c8c8, 8f8f8f, ebebeb, b8b8b8, dbdbdb, 9c9c9c, 2b2b2b


        to

        # The original palette of the DVD in PGC#1
        palette:
        000000, 000000, 000000, ffffff, 535353, 414141, 626262, 7c7c7c, a9a9a9, c8c8c8, 8f8f8f, ebebeb, b8b8b8, dbdbdb, 9c9c9c, 2b2b2b
         
      • The subtitle now looks better:


         

  7. Adjust the subtitle time:
    • Find the first subtitle in final.sup.idx
    • Play D:\temp\~DATA\final.ts in Media Player Classic (in K-lite Codec pack).
      Play until the first subtitle is heard. Write down the time of the first subtitle.
    • In SubResync, right click the subtitle chosen 2 times, until seeing the red triangle
    • Enter the correct time of the subtitle chosen. Save as final.idx
    • Reopen final.ts in Media Player Classic. The subtitle time should be correct now.
       
  8. Find the cropping details for movie, in Virtual Dub.
    • In D:\temp\~DATA\, create a file called final.avs (using notepad) with the following content:

      DirectShowSource("final.ts")
      LoadPlugin("c:\Program Files\K-Lite Codec Pack\Filters\vsfilter.dll")
      VobSub("final.idx")
       
    • Drag "final.avs" into Virtual Dub.
    • In Virtual Dub, "Video" Menu, choose "Filter".
    • Add "Null Transformation"
    • Choose "Cropping...".
    • Determine the cropping details (i.e. Write down X1, X2, Y1, Y2. Note they must be even number):
         
       
  9. Using ffmpeg to convert final.ts to XVID encoded (MPEG4) AVI file final.avi:
    • Start a command prompt.
    • type the following:
      • d:
      • cd d:\temp\~DATA
      • "C:\Program Files\WinFF\ffmpeg.exe" -i final.ts -vcodec xvid -vtag XVID -deinterlace -croptop 76 -cropbottom 76 -cropleft 4 -cropright 4 -s 640x360 -qmin 4 -qmax 4 -bufsize 4096 -mbd 2 -bf 2 -flags +4mv+trell -aic 2 -cmp 2 -subcmp 2 -g 300 -acodec mp3 -ar 44100 -ab 128k -ac 2 final.avi
    • Note:
      • replace the value for croptop, cropbottom, cropleft, cropright with the values found in Y1, Y2, X1 and X2 found in Step (8).
      • for the best quality video, set qmin, qmax to 1. (the smaller value the better video quality)
      • -g 300 means for every 300 fames (12seconds), there is a I frame. Set to a smaller value if you need to editing.
      • the above example uses 44100kbps, 128kpbs 2-channels mp3 audio. you can modify as your wish
         
  10. Merge final.avi, final.idx into final.mkv
    • Start mkvtoolnix\mmg.exe, add final.avi, final.idx. Press "Start muxing".