Answers.Body: <p>The <code>mkvtools</code> package provides a way to read and to edit the metadata of any Matroska file without the need to remux directly from the command line. This allows one to write a relatively simple bash script that does the job.</p>
  
  <p>In here the job is broken into three steps:</p>
  
  <ol>
  <li>UID of each file is read by <code>mkvinfo</code>, cleaned, and recorded into the <code>.uid</code> file. At the same time these files are copied to the previous and next file with the extensions <code>.nextuid</code> and <code>.prevuid</code>.</li>
  <li>Option file is generated by taking data from <code>.nextuid</code> and <code>.prevuid</code> files where they exist, this option file is saved with <code>.seqtags</code> extension.</li>
  <li>The tool <code>mkvpropedit</code> is used to write the information, and the temp files are deleted.</li>
  </ol>
  
  <p>The reason why it is not done in a single step is to allow the user to abort during the read process and to know that no files have yet been altered.</p>
  
  <p><em>mkvsequence.sh</em></p>
  
  <pre><code>#!/bin/bash
  # GPL3.0
  SAVEIFS=$IFS
  IFS=$(echo -en "\n\b")
  
  FILES=$(ls *.mkv|sort)
  
  echo First reading all the information
  for FILE in $FILES
  do
      echo Processing $FILE
      exec mkvinfo "${FILE}" | grep "Segment UID: "  | sed "s/^| *+ Segment UID: //g" &gt; "${FILE}.uid"
      if [ $PREVFILE ]
      then
          cp "${FILE}.uid" "${PREVFILE}.nextuid"
          cp "${PREVFILE}.uid" "${FILE}.prevuid"
      fi
      PREVFILE=$FILE
  done
  
  echo Creating the necessary option files
  for FILE in $FILES
  do
      echo Processing $FILE
      if [ -f "${FILE}.prevuid" -o -f "${FILE}.nextuid" ]
      then
          echo $FILE &gt; "${FILE}.seqtags"
          echo --edit &gt;&gt; "${FILE}.seqtags"
          echo info &gt;&gt; "${FILE}.seqtags"
  
          if [ -f "${FILE}.prevuid" ]
          then
              echo --set &gt;&gt; "${FILE}.seqtags"
              echo prev-uid=$(cat "${FILE}.prevuid") &gt;&gt; "${FILE}.seqtags"
          fi
  
          if [ -f "${FILE}.nextuid" ]
          then
              echo --set &gt;&gt; "${FILE}.seqtags"
              echo next-uid=$(cat "${FILE}.nextuid") &gt;&gt; "${FILE}.seqtags"
          fi
      fi
  done
  
  echo Now writing all the data
  for FILE in $FILES
  do
      echo Processing $FILE
      mkvpropedit "@${FILE}.seqtags"
      rm "${FILE}.uid" "${FILE}.prevuid" "${FILE}.nextuid" "${FILE}.seqtags"
  done
  
  IFS=$SAVEIFS
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-11-08T22:54:08.830Z
Answers.LastActivityDate: 2014-11-08T22:54:08.830Z
Answers.UserDisplayName: v010dya
Body: <p>Often there is a case where one has a series of the already muxed Matroska files, and they have a logical order. It may be desirable to chain them all together, giving a hint to the video player, that after finishing one of these files another one should start playing.</p>
  
  <p>Although the standard permits prev-uid and next-uid metadata tags it can be quite difficult to set them up on all the files, doing it by hand will all but guarantee some human error in pasting, and is way too tidious anyhow.</p>
  
Tags: <matroska>
Title: Chaining Matroska files
UserDisplayName: v010dya
ThreadText: # Chaining Matroska files
  
  (Asked by: username_0 on 2014-11-08)
  
  Often there is a case where one has a series of the already muxed Matroska files, and they have a logical order. It may be desirable to chain them all together, giving a hint to the video player, that after finishing one of these files another one should start playing.
  
  Although the standard permits prev-uid and next-uid metadata tags it can be quite difficult to set them up on all the files, doing it by hand will all but guarantee some human error in pasting, and is way too tidious anyhow.
  
  **Tags:** matroska
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2014-11-08. Score: 1
  
  The `mkvtools` package provides a way to read and to edit the metadata of any Matroska file without the need to remux directly from the command line. This allows one to write a relatively simple bash script that does the job.
  
  In here the job is broken into three steps:
  
  1. UID of each file is read by `mkvinfo`, cleaned, and recorded into the `.uid` file. At the same time these files are copied to the previous and next file with the extensions `.nextuid` and `.prevuid`.
  2. Option file is generated by taking data from `.nextuid` and `.prevuid` files where they exist, this option file is saved with `.seqtags` extension.
  3. The tool `mkvpropedit` is used to write the information, and the temp files are deleted.
  
  The reason why it is not done in a single step is to allow the user to abort during the read process and to know that no files have yet been altered.
  
  *mkvsequence.sh*
  
  ```
  #!/bin/bash
  # GPL3.0
  SAVEIFS=$IFS
  IFS=$(echo -en "\n\b")
  
  FILES=$(ls *.mkv|sort)
  
  echo First reading all the information
  for FILE in $FILES
  do
      echo Processing $FILE
      exec mkvinfo "${FILE}" | grep "Segment UID: "  | sed "s/^| *+ Segment UID: //g" > "${FILE}.uid"
      if [ $PREVFILE ]
      then
          cp "${FILE}.uid" "${PREVFILE}.nextuid"
          cp "${PREVFILE}.uid" "${FILE}.prevuid"
      fi
      PREVFILE=$FILE
  done
  
  echo Creating the necessary option files
  for FILE in $FILES
  do
      echo Processing $FILE
      if [ -f "${FILE}.prevuid" -o -f "${FILE}.nextuid" ]
      then
          echo $FILE > "${FILE}.seqtags"
          echo --edit >> "${FILE}.seqtags"
          echo info >> "${FILE}.seqtags"
  
          if [ -f "${FILE}.prevuid" ]
          then
              echo --set >> "${FILE}.seqtags"
              echo prev-uid=$(cat "${FILE}.prevuid") >> "${FILE}.seqtags"
          fi
  
          if [ -f "${FILE}.nextuid" ]
          then
              echo --set >> "${FILE}.seqtags"
              echo next-uid=$(cat "${FILE}.nextuid") >> "${FILE}.seqtags"
          fi
      fi
  done
  
  echo Now writing all the data
  for FILE in $FILES
  do
      echo Processing $FILE
      mkvpropedit "@${FILE}.seqtags"
      rm "${FILE}.uid" "${FILE}.prevuid" "${FILE}.nextuid" "${FILE}.seqtags"
  done
  
  IFS=$SAVEIFS
  
  ```
  
  
  ---
  
  