Skip to content

Instantly share code, notes, and snippets.

@dwin
Created January 6, 2019 08:41
Show Gist options
  • Select an option

  • Save dwin/8212afda3085ea5c30a6bd782e8c1b51 to your computer and use it in GitHub Desktop.

Select an option

Save dwin/8212afda3085ea5c30a6bd782e8c1b51 to your computer and use it in GitHub Desktop.

Revisions

  1. dwin created this gist Jan 6, 2019.
    20 changes: 20 additions & 0 deletions convert.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    #!/bin/sh --
    # Make executable and Run in directory containing files?
    # Convert all '.ts' files in directory using ffmpeg using nvidia hardware hevc(x265) encoding, maintain orginal audio
    # and extract subtitles/closed-caption as '.srt' to current directory.

    # Start looping over files, tell what we do and log any output to screen and log.
    for MPEG in *.ts; do echo "Starting ${MPEG}"
    ffmpeg -i "${MPEG}" -c:a copy -c:v hevc_nvenc -b:v 3000k -minrate 1000k -maxrate 8000k -level 4.1 -tag:v hvc1 -preset slow -rc-lookahead 32 -movflags faststart "${MPEG%.ts}.mp4" 2>&1 | tee -a "conversion.log"
    # If ffmpeg exited OK, then say it and move the original to the backup directory.
    if [ $? -eq 0 ]; then
    # Extract subtitles
    ccextractor "${MPEG}"
    echo "Completed ${MPEG%.ts}.mp4"
    else
    # If ffmpeg failed, then say so and exit loop.
    echo "FAILED converting ${MPEG}, exiting."; exit 1;
    fi
    done # End of file loop
    # Exit.
    exit 0