Hacker News new | past | comments | ask | show | jobs | submit login

For anybody else irritated by watching all of the short segments stitched together by the video player at the Internet Archive, I wrote this script to concatenate the mp4 segments and re-encode as a single mp4 file.

  #!/bin/sh
  
  DIR=$1
  
  BASE=$(basename $DIR)
  
  echo copying from $DIR to create $BASE.mp4
  
  # copy the files over
  mkdir $BASE
  cp -v $DIR/*.xml .
  cp -v $DIR/*.mp4 $BASE/
  
  echo done copying
  echo convert segments to ts files
  
  # convert all the mp4 files to intermediate transport stream format
  for f in $BASE/?????.mp4; do
      echo "$f -> $f.ts"
      ffmpeg -i $f -c copy -bsf:v h264_mp4toannexb -f mpegts $f.ts > /dev/null 2>&1
  done
  
  # concatenate all the ts files and then re-encode them to mp4
  echo concatenate ts files and re-encode as mp4
  (cd $BASE;
   ffmpeg -i $(echo -n "concat:"; for f in *.ts; do echo -n "$f|"; done) -c copy -bsf:a aa  c_adtstoasc ../$BASE.mp4
  )
  
  # clean up
  echo clean up
  rm -rf $BASE
  echo done



Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: