Giter Site home page Giter Site logo

Comments (10)

Reed97123 avatar Reed97123 commented on July 2, 2024
#!/usr/bin/env bash

#LD_LIBRARY_PATH is set and will mess up ffmpeg, unset it, then re-set it when done
ldPath=${LD_LIBRARY_PATH}
unset LD_LIBRARY_PATH

exitcode=0

ffmpegPath="ffmpeg"
comskipPath="comskip"

if [[ $# -lt 1 ]]; then

  exename=$(basename "$0")

  echo "Add chapters to video file using EDL file"
  echo "     (If no EDL file is found, comskip will be used to generate one)"
  echo ""
  echo "Usage: $exename infile [outfile]"

  exit 1
fi

comskipini=$HOME/.comskip.ini

deleteedl=true
deletemeta=true
deletelog=true
deletelogo=true
deletetxt=true
verbose=false
lockfile=""

while [[ $# -gt 1 ]]
do
key="$1"
case $key in
    --keep-edl)
    deleteedl=false
    shift
    ;;
    --keep-meta)
    deletemeta=false
    shift
    ;;
    --verbose)
    verbose=true
    shift
    ;;
    --ffmpeg=*)
    ffmpegPath="${key#*=}"
    shift
    ;;
    --comskip=*)
    comskipPath="${key#*=}"
    shift
    ;;
    --comskip-ini=*)
    comskipini="${key#*=}"
    shift
    ;;
    --lockfile=*)
    lockfile="${key#*=}"
    shift
    ;;
    *)
    break
    ;;
esac
done

# Setup for verbose
exec 3>&1
exec 4>&2

if ! $verbose; then
  exec 1>/dev/null
  exec 2>/dev/null
fi

if [ ! -z "$lockfile" ]; then

  echo "lockfile: $lockfile"
  while [[ -f "$lockfile" ]]; do
    echo "Waiting"
    sleep 5
  done

  touch "$lockfile"
fi

if [ ! -f "$comskipini" ]; then
  echo "output_edl=1" > "$comskipini"
elif ! grep -q "output_edl=1" "$comskipini"; then
  echo "output_edl=1" >> "$comskipini"
fi

infile=$1

if [[ -z "$2" ]]; then
  outfile="$infile"
else
  outfile="$2"
fi

outdir=$(dirname "$outfile")

outextension="${outfile##*.}"

edlfile="${infile%.*}.edl"
metafile="${infile%.*}.ffmeta"
logfile="${infile%.*}.log"
logofile="${infile%.*}.logo.txt"
txtfile="${infile%.*}.txt"

if [ ! -f "$edlfile" ]; then
  $comskipPath --ini="$comskipini" "$infile"

  if [ ! -f "$edlfile" ] || [ ! -s "$edlfile" ]; then
    echo Error running comskip. 1>&3 2>&4

    if [ ! -z "$lockfile" ]; then
      rm "$lockfile"
    fi

    exit -1
  fi
fi

start=0
i=0
hascommercials=false

echo ";FFMETADATA1" > "$metafile"
# Reads in from $edlfile, see end of loop.
while IFS=$'\t' read -r -a line
do
  ((i++))

  end="${line[0]}"
  startnext="${line[1]}"
  hascommercials=true

  echo [CHAPTER] >> "$metafile"
  echo TIMEBASE=1/1 >> "$metafile"
  echo START="$start" >> "$metafile"
  echo END="$end" >> "$metafile"
  echo "title=Chapter $i" >> "$metafile"

  echo [CHAPTER] >> "$metafile"
  echo TIMEBASE=1/1 >> "$metafile"
  echo START="$end" >> "$metafile"
  echo END="$startnext" >> "$metafile"
  echo "title=Commercial $i" >> "$metafile"

  start=$startnext
done < "$edlfile"

if $hascommercials ; then
  ((i++))
  echo [CHAPTER] >> "$metafile"
  echo TIMEBASE=1/1 >> "$metafile"
  echo START="$start" >> "$metafile"
  echo END=`$ffmpegPath -i "$infile" 2>&1 | grep Duration | awk '{print $2}' | tr -d , | awk -F: '{ print ($1 * 3600) + ($2 * 60) + $3 }'` >> "$metafile"
  echo "title=Chapter $i" >> "$metafile"

  if [ "$infile" -ef "$outfile" ] ; then

    tempfile=`mktemp --suffix=."$outextension" "$outdir"/XXXXXXXX`

    echo Writing file to temporary file: "$tempfile"
    if $ffmpegPath -loglevel error -hide_banner -nostdin -i "$infile" -i "$metafile" -map_metadata 1 -codec copy -y "$tempfile" 1>&3 2>&4; then
      mv -f "$tempfile" "$outfile"
      echo Saved to: "$outfile"
    else
      echo Error running ffmpeg. 1>&3 2>&4
      exitcode=-1
    fi
  else
    if $ffmpegPath -loglevel error -hide_banner -nostdin -i "$infile" -i "$metafile" -map_metadata 1 -codec copy -y "$outfile" 1>&3 2>&4; then
      echo Saved to: "$outfile"
    else
      echo Error running ffmpeg. 1>&3 2>&4
      exitcode=-1
    fi
  fi

  if [ ! -f "$outfile" ]; then
    echo Error, "$outfile" does not exist. 1>&3 2>&4
    exitcode=-1
  fi
else
  echo Error, no Commercials found, not saving to new location.  Nothing to do. 1>&3 2>&4
  exitcode=-1
fi

if $deleteedl ; then
  if [ -f "$edlfile" ] ; then
    rm "$edlfile";
  fi
fi

if $deletemeta ; then
  if [ -f "$metafile" ]; then
    rm "$metafile";
  fi
fi

if $deletelog ; then
  if [ -f "$logfile" ]; then
    rm "$logfile";
  fi
fi

if $deletelogo ; then
  if [ -f "$logofile" ]; then
    rm "$logofile";
  fi
fi

if $deletetxt ; then
  if [ -f "$txtfile" ]; then
    rm "$txtfile";
  fi
fi

if [ ! -z $ldPath ] ; then
  #re-set LD_LIBRARY_PATH
  export LD_LIBRARY_PATH="$ldPath"
fi

if [ ! -z "$lockfile" ]; then
  rm "$lockfile"
fi

exit $exitcode

from comchap.

BrettSheleski avatar BrettSheleski commented on July 2, 2024

I'm looking forward to reviewing this. It would be tons easier if it were made into a pull request.

However I disagree on point number 5. I don't think it should be an error when no commercials were detected.

Thanks for reviewing and cleaning up the code, feedback like this is always helpful.

from comchap.

Reed97123 avatar Reed97123 commented on July 2, 2024

I tried creating a pull request in the past, but I ended up accidentally forking the code to my area. Any simple tips to creating a pull request?

from comchap.

BrettSheleski avatar BrettSheleski commented on July 2, 2024

There may be easier ways, but I find forking the repo, committing to the
fork easiest. GitHub then makes it easy to submit a pull request from
your fork to the original.

On Tue, Nov 22, 2016, 12:26 PM Reed97123 [email protected] wrote:

I tried creating a pull request in the past, but I ended up accidentally
forking the code to my area. Any simple tips to creating a pull request?


You are receiving this because you commented.

Reply to this email directly, view it on GitHub
#9 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAjwuvPVHx_xoFFnMlBEAjDn9u0BToETks5rAzPcgaJpZM4K5wU6
.

from comchap.

Reed97123 avatar Reed97123 commented on July 2, 2024

I found a typo in what I submitted above. I'm testing the fix now and I'll update the above and create a pull request once I confirm it's good.

On point 5 my logic is the following:

  • I run comchap because I believe there are commercials in the video and I want it processed.
  • If no commercials are found it is likely a symptom of an error such as: video file is somehow truncated/corrupt, .comskip.ini has an issue, etc.
  • In every case I can imagine I want the issue brought to my attention so I can fix it.
  • Flagging it as an error brings it to my attention and allows me to fix it.

from comchap.

BrettSheleski avatar BrettSheleski commented on July 2, 2024

I see your point, but just don't necessarily agree it should be seen as an
error. I realize in your situation you'd like to treat it as such, but I
don't think this would be the general case.

With that said, I wouldn't see a problem making some sort of command line
argument which would exit with error status when no commercials found.

I'm unsure exactly what that would look like at the moment though.

On Tue, Nov 22, 2016, 12:40 PM Reed97123 [email protected] wrote:

I found a typo in what I submitted above. I'm testing the fix now and I'll
update the above and create a pull request once I confirm it's good.

On point 5 my logic is the following:

  • I run comchap because I believe there are commercials in the video
    and I want it processed.
  • If no commercials are found it is likely a symptom of an error such
    as: video file is somehow truncated/corrupt, .comskip.ini has an issue, etc.
  • In every case I can imagine I want the issue brought to my attention
    so I can fix it.
  • Flagging it as an error brings it to my attention and allows me to
    fix it.


You are receiving this because you commented.

Reply to this email directly, view it on GitHub
#9 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAjwushMa72q9Ok2hT-TahlsEzE6Jb5Lks5rAzcJgaJpZM4K5wU6
.

from comchap.

BrettSheleski avatar BrettSheleski commented on July 2, 2024

On the topic of creating a pull request, I think the proper way of doing so is to create your own branch in this repository then commit to that. Then create a pull request from your branch to master.

from comchap.

Reed97123 avatar Reed97123 commented on July 2, 2024

Okay, I think I created the pull request correctly. Thanks for the tips.

from comchap.

BrettSheleski avatar BrettSheleski commented on July 2, 2024

I see it. I'll review when I get time to sit at a computer.

from comchap.

Reed97123 avatar Reed97123 commented on July 2, 2024

Created a new pull request to address the issues mentioned in the pull request discussion.

from comchap.

Related Issues (20)

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.