Jump to content

Remove Subtitles and Alternate Audio


Dizzy49

Recommended Posts

Dizzy49

I have quite a few videos, and about half of them have additional audio tracks, and probably 3/4 of them have subtitles.  I am looking for a tool/script that can process them in bulk and can handle my folder structures.

 

Folder Structure for Movies:

 

Root Movie Folder

|__Movie Title (Folder)

    |__Video Files

 

Folder Stucture for TV Shows:

|__Root TV Folder

    |__TV Series Title (Folder)

         |__Season X (Folder)

              |__Video Files

 

I think just running the tool/script in the root folder recursively and having it process every video it finds should work.

 

 

PROCESSING

 

If Only 1 Audio Track and No Subtitles = Skip Video File [ Important so that it doesn't process files it doesn't need to ]

 

If More than 1 Audio Track = Look for English Track(s), remove all others

   * If unable to locate English track(s), do not remove any [ Important in case audio tracks are not labeled properly ]

   * If English track(s) exist, remove all Subtitles [ Theory: If English track exists, I shouldn't need any subtitles ]

   * If English track(s) Do NOT exist, look for an only keep English subtitles and remove the rest

         - If unable to determine if English subtitles exist, do not remove any subtitles

 

CONCERNS

Subtitles will be lost for foreign parts of an English video.  They SHOULD be hardcoded in the video track, but aren't always.

Needs to be able to handle older videos, as well as newer ones using x265/HEVC

Concerned that messing with the audio and remuxxing will screw up audio sync for the videos.

 

 

WISH LIST

Ability to keep only the best audio track.  Many videos have multiple English audio, ie DTS 5.1, and Dobly Stereo, I even have one with like 5 English tracks.  A 7.1, 3x 5.1 tracks (DTS, DTS-MA, DD), and a stereo track.  My receiver can handle any audio stream, so I only need the best.

Ability to keep a certain track, or only tracks up to a certain level.  For instance, if the FireTV can only play Stereo, DD, and DTS I don't want anything higher than that, but if it's just hooked up to a TV that only has stero speakers, I'd just want the stereo track.

Track videos where it couldn't determine audio and/or subtitles and log/email/present them at the end

Track before and after file sizes to determine how much space was saved throughout process

 

 

 

Link to comment
Share on other sites

naeonline

ffmpeg is what you are looking for.  ffprobe comes with it.  There are versions for whichever platform you are on (linux/mac/windows...).  Scripting can be done with whichever you are familiar with to pull filenames from your folder structure for processing, then pass those filenames to ffprobe for the layout of what is in your media (eg stream 0 is h264 video, stream 1 is ac3 5.1ch audio, stream 3 is vob subtitles).  You'll have to parse the ffprobe output into a structure and then choose the desired streams to keep and call ffmpeg to copy those ones to the new file.

 

ffprobe.exe -i "VideoFileNameAndPath.mkv" -hide_banner
EXAMPLE OUTPUT:
Input #0, matroska,webm, from 'VideoFileNameAndPath.mkv':
  Metadata:
    encoder         : libmakemkv v1.10.4 (1.3.3/1.4.4) win(x64-release)
  Duration: 01:09:09.98, start: 0.000000, bitrate: 28123 kb/s
    Chapter #0:0: start 0.000000, end 131.381250
    Metadata:
      title           : Chapter 01
    Chapter #0:1: start 131.381250, end 945.861583
    Metadata:
      title           : Chapter 02
    Chapter #0:2: start 945.861583, end 1476.975500
    Metadata:
      title           : Chapter 03
    Chapter #0:3: start 1476.975500, end 2248.579667
    Metadata:
      title           : Chapter 04
    Chapter #0:4: start 2248.579667, end 3061.641917
    Metadata:
      title           : Chapter 05
    Chapter #0:5: start 3061.641917, end 3554.384167
    Metadata:
      title           : Chapter 06
    Chapter #0:6: start 3554.384167, end 4149.979167
    Metadata:
      title           : Chapter 07
    Stream #0:0(eng): Video: h264 (High), yuv420p(tv, bt709, progressive), 1920x1080 [sAR 1:1 DAR 16:9], 23.98 fps, 23.98 tbr, 1k tbn, 47.95 tbc
    Metadata:
      BPS-eng         : 24884159
      DURATION-eng    : 01:09:09.979166666
      NUMBER_OF_FRAMES-eng: 99500
      NUMBER_OF_BYTES-eng: 12908592378
      SOURCE_ID-eng   : 001011
      _STATISTICS_WRITING_APP-eng: MakeMKV v1.10.4 win(x64-release)
      _STATISTICS_WRITING_DATE_UTC-eng: 2017-03-01 16:39:56
      _STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES SOURCE_ID
    Stream #0:1(eng): Audio: dts (DTS-HD MA), 48000 Hz, stereo, s16p (default)
    Metadata:
      title           : Stereo
      BPS-eng         : 1684425
      DURATION-eng    : 01:09:09.856000000
      NUMBER_OF_FRAMES-eng: 389049
      NUMBER_OF_BYTES-eng: 873765548
      SOURCE_ID-eng   : 001100
      _STATISTICS_WRITING_APP-eng: MakeMKV v1.10.4 win(x64-release)
      _STATISTICS_WRITING_DATE_UTC-eng: 2017-03-01 16:39:56
      _STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES SOURCE_ID
    Stream #0:2(eng): Audio: dts (DTS), 48000 Hz, stereo, fltp, 1536 kb/s
    Metadata:
      title           : Stereo
      BPS-eng         : 1509000
      DURATION-eng    : 01:09:09.856000000
      NUMBER_OF_FRAMES-eng: 389049
      NUMBER_OF_BYTES-eng: 782766588
      SOURCE_ID-eng   : 001100
      _STATISTICS_WRITING_APP-eng: MakeMKV v1.10.4 win(x64-release)
      _STATISTICS_WRITING_DATE_UTC-eng: 2017-03-01 16:39:56
      _STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES SOURCE_ID
    Stream #0:3(eng): Subtitle: hdmv_pgs_subtitle
    Metadata:
      BPS-eng         : 41924
      DURATION-eng    : 01:08:14.945020833
      NUMBER_OF_FRAMES-eng: 2732
      NUMBER_OF_BYTES-eng: 21459731
      SOURCE_ID-eng   : 001200
      _STATISTICS_WRITING_APP-eng: MakeMKV v1.10.4 win(x64-release)
      _STATISTICS_WRITING_DATE_UTC-eng: 2017-03-01 16:39:56
      _STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES SOURCE_ID
 
So a quick breakdown of the ffprobe info, the video file has chapters, h264 video, eng DTS-HD MA, eng DTS, eng PGS subtitles. Lets say my systems can only play up to DTS but not DTS-HD MA so I choose to keep DTS only.  You use the -map parameter to do this. I want streams 0(video) and 2(dts) only, leaving out the subtitle as well.
how map works:
-map #(input file #):#(input file stream #) -c(codec):v/a/s(video/audio/subtitle):#(stream # in output file)
 
ffmpeg.exe -i "VideoFileNameAndPath.mkv" -map 0:0 -c:v:0 copy -map 0:2 -c:a:0 copy "OutputFileNameAndPath.mkv"
 
In my experience, ffmpeg with these settings should preserve chapter data and metadata in the output file from the input file.
 
Hope this helps you get started.
  • Like 1
Link to comment
Share on other sites

  • 1 month later...
Dizzy49

So, I wrote a script that goes through my collection and uses ffprobe to get details on all the files.

Looks like the basic format is.

Stream #0:x (lang): Video/Audio/Subtitle

 

The x can change, and the lang could change.  I found several Streams missing a language though.  Then it's just "Stream #0:x: Video/Audio/Subtitle"

However, in all instances, there are other indicators such as Metadata that can be used to determine.

 

I think if the data could be parsed, and check for language that it would at least resolve 90+% of my files.

However, I am not smart enough to be able to write a script to do it.  It took me WAY longer than it should have to write this simple batch file:

 

for /r . %%a in (*.mkv) do (
  if "%%~nxa" neq "trailer.mkv" ffprobe.exe -i "%%a" -hide_banner 2>> results.txt )
 
I could probably hack together a C# program to do it if I had time, which I have NONE OF while the kids are out of school...
Edited by Dizzy49
Link to comment
Share on other sites

nagetech

I use MKV toolnix:   https://mkvtoolnix.download/

 

It's painless.

I've never used that program before and I'd be interested in doing what the OP wanted to do. Does that program have a "monitor" feature where it keeps an eye on a directory and automatically "strips" all foreign languages out of a file?

Link to comment
Share on other sites

pir8radio

I've never used that program before and I'd be interested in doing what the OP wanted to do. Does that program have a "monitor" feature where it keeps an eye on a directory and automatically "strips" all foreign languages out of a file?

 

I'm not sure if you can do automated stuff with it, I have a pretty low volume of videos, so I use it as needed.

Link to comment
Share on other sites

  • 4 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...