Coder Social home page Coder Social logo

mkvtoolnix-missing-ctts-atom-repair's Introduction

MKVToolNix-missing-ctts-atom-repair

Scripts to add the missing ctts atom to MP4 files created using MKVToolNix prior to version 45.

Purpose of this script

MKVToolNix prior to version 45 failed to make a ctts atom which created a shuddering effect for mp4 files made from mkvs assembled using MKVToolNix. More technical information can be found here:

https://gitlab.com/mbunkus/mkvtoolnix/-/issues/2777#note_315725406

The bash scripts listed in this repo are designed to "repair" the mp4 files by creating a temporary mkv file, using ffmpeg to override the original mp4 file, and than deleting the temporary mkv file.

THESE SCRIPTS ARE DESTRUCTIVE

All of these scripts are designed to override the original mp4 files. This is a warning that no warranty exists, implied or expressed. It is very much a possibility that a loss of data may occur. These scripts are being shared "AS IS."

These scripts are also known to potentially offset subtitles from previous mp4 files that lacked a ctts atom.

Requirements

This script was tested on Ubuntu 20.04 and should work using the default package manager APT install packages that come with Ubuntu 20.04 and newer.

The scripts also require bash 4.0+, which mostly affect MacOS users. To use these scripts on the MacOS a user will need to add/upgrade your bash install a version 4.0 or newer.

-atomicparsley (for manually checking for the presence of a ctts atom)

-MKVToolNix 45 or newer (needed to create the new/temporary mkv files with a ctts atom present)

-ffmpeg (used to create the new/temporary mkv files and to later extract the videos files and putting them into a new mp4 file with a ctts atom)

-bash 4.0+ (older versions of bash lack glostar, making transversing subdirectories more difficult)

Ubuntu 20.04 and likely newer install instructions.

As always, make sure apt-get is up-to-date. sudo apt-get update

Atomicparsley, apt install.

sudo apt-get install atomicparsley

MKVToolNix, apt install.

sudo apt-get install mkvtoolnix

FFmpeg, apt install.

sudo apt-get install ffmpeg

Ubuntu 20.04 comes with bash version 5.0.17 or newer. This version of bash works by default with these scripts. MacOS users will need to upgrade/secondary install bash 4.0 or newer.

Usage

If wanting to check if an individual file has a ctts atom, you can use atomicparsley to verify the file has the ctts atom.

AtomicParsley <input.mp4> -T 1 | grep ctts

If the file does not contain a ctts atom, move fixall.sh into the folder of the file you want to repair. It is important to note the script will repair any .mp4 file in the same directory or sub directory of the bash script.

To run the script, run the script by specifying the bash script is a bash script.

bash fixall.sh

As RARBG files have been brought as files that have been affected by the MKVToolNix/ctts atom issue, two scripts have been added that will attempt to repair all RARBG x265 files based on the RARBG naming convenction. If placed and run in the root of a media folder, the script will attempt to repair/replace the ctts in all RARBG files, if the files are still using the RARBG naming convention.

This will fix/repair mp4 files using the x265-RARBG naming convention:

bash fix-x265-RARBG.sh

This will fix/repair mp4 files using the x265-VXT naming convention:

bash fix-x265-VXT.sh

A big thank you to lightmaster, _incorrect, and everyone else over at the Plex Thread that put together the info that helped me to put together a bash workable script for repairing HEVC mp4 files with a broken ctts atom. https://forums.plex.tv/t/example-of-stuttering-hevc-playback-on-apple-tv-4k/558255

mkvtoolnix-missing-ctts-atom-repair's People

Contributors

gbballpack avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

mkvtoolnix-missing-ctts-atom-repair's Issues

Drops any additional audio streams in final merge MP4

Heya! Found your lovely script(s) to fix a lot of my issues from older files. Thank you.

WARNING: Do not run any of these scripts on any multi-audio files. You will strip out any additional streams of audio in the final output MP4.

Input #0, matroska,webm, from 'Movie (Year)/Movie.mkv':
  Metadata:
    encoder         : libebml v1.4.2 + libmatroska v1.6.4
    creation_time   : 2022-09-05T01:17:12.000000Z
  Duration: 01:49:19.76, start: 0.000000, bitrate: 2450 kb/s
  Stream #0:0: Video: hevc (Main 10), yuv420p10le(tv), 1920x1036 [SAR 1:1 DAR 480:259], 23.98 fps, 23.98 tbr, 1k tbn, 23.98 tbc (default)
    Metadata:
      BPS             : 2000601
      DURATION        : 01:49:19.720000000
      NUMBER_OF_FRAMES: 157276
      NUMBER_OF_BYTES : 1640423128
      _STATISTICS_WRITING_APP: mkvmerge v70.0.0 ('Caught A Lite Sneeze') 64-bit
      _STATISTICS_WRITING_DATE_UTC: 2022-09-05 01:17:12
      _STATISTICS_TAGS: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
  Stream #0:1(chi): Audio: aac (LC), 48000 Hz, 5.1, fltp (default)
    Metadata:
      BPS             : 224000
      DURATION        : 01:49:02.677000000
      NUMBER_OF_FRAMES: 306688
      NUMBER_OF_BYTES : 183194966
      _STATISTICS_WRITING_APP: mkvmerge v70.0.0 ('Caught A Lite Sneeze') 64-bit
      _STATISTICS_WRITING_DATE_UTC: 2022-09-05 01:17:12
      _STATISTICS_TAGS: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
  Stream #0:2(eng): Audio: aac (LC), 48000 Hz, 5.1, fltp (default)
    Metadata:
      BPS             : 224000
      DURATION        : 01:49:18.570000000
      NUMBER_OF_FRAMES: 307433
      NUMBER_OF_BYTES : 183639979
      _STATISTICS_WRITING_APP: mkvmerge v70.0.0 ('Caught A Lite Sneeze') 64-bit
      _STATISTICS_WRITING_DATE_UTC: 2022-09-05 01:17:12
      _STATISTICS_TAGS: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
Output #0, mp4, to 'Movie (Year)/Movie.mp4':
  Metadata:
    encoder         : Lavf58.76.100
  Stream #0:0: Video: hevc (Main 10) (hev1 / 0x31766568), yuv420p10le(tv), 1920x1036 [SAR 1:1 DAR 480:259], q=2-31, 23.98 fps, 23.98 tbr, 16k tbn, 1k tbc (default)
    Metadata:
      BPS             : 2000601
      DURATION        : 01:49:19.720000000
      NUMBER_OF_FRAMES: 157276
      NUMBER_OF_BYTES : 1640423128
      _STATISTICS_WRITING_APP: mkvmerge v70.0.0 ('Caught A Lite Sneeze') 64-bit
      _STATISTICS_WRITING_DATE_UTC: 2022-09-05 01:17:12
      _STATISTICS_TAGS: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
  Stream #0:1(chi): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, 5.1, fltp (default)
    Metadata:
      BPS             : 224000
      DURATION        : 01:49:02.677000000
      NUMBER_OF_FRAMES: 306688
      NUMBER_OF_BYTES : 183194966
      _STATISTICS_WRITING_APP: mkvmerge v70.0.0 ('Caught A Lite Sneeze') 64-bit
      _STATISTICS_WRITING_DATE_UTC: 2022-09-05 01:17:12
      _STATISTICS_TAGS: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:1 -> #0:1 (copy)

Seems omitting -map 0 in the end ffmpeg script command: ffmpeg -i "$i" -y -flags +global_header -movflags faststart -c:v copy -c:a copy "${i%.mkv}.mp4"; gives only one video stream and one audio stream.

Adding -map 0 properly preserves additional streams:

Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:1 -> #0:1 (copy)
  Stream #0:2 -> #0:2 (copy)

Unfortunately, I found out after running this script and have to fix a bunch of my files now. Sadfacey.

Is there any adverse effect to putting -map 0 into the final MP4 conversion line? Just want to make sure I'm not fixing one issue and introducing another.

Add mkv container to the script

I checked a few files i had that got the missing ctts error from AtomicParsley, but the file was .mkv.
So would be nice to get both mp4 and mvk files with the bash scripts?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.