0

my HD Homerun for PLEX saves .TS files (transport stream).

in order to shrink this to 720 i use the following script:

#!/bin/bash 
for INF in *.ts 
    do ffmpeg -i "$INF" -vf scale=-1:720 -c:v libx264 -crf 23 -preset ultrafast -c:a copy "${INF%.*}.mp4" 
done

this works well and converts every .TS in folder .sh script is stored in to an mp4 container. I then run the following script:

#!/usr/local/bin/bash
for INF in *.mp4 
do
    echo "Extracting subtitles"
    ccextractor "$INF" -o "/tmp/$(basename "$INF" .ts).srt"

    echo "Moving subtitles" 
    mv -v /tmp/*.srt .
done

My goal is combine both these bash loops into one script. Ideally i would like, one script that will: a) scan current folder and all sub-folders looking for .ts files. b) remux .ts to .mp4 c) pull closed captions out of .ts and store as .srt d) remove all .ts files

I am not sure I added a / after 'for INF in *.ts' would include sub-directories. and not sure how to join these two scripts into one file or where to put the remove file(s) code

any ideas would be greatly appreciated. -shaun

  • It looks to me that you're pulling the subtitles from the mp4 file, at least that is what your code snippet above does. – wurtel Feb 7 '18 at 12:28
  • yes the .ts transport stream is a container with an mpeg2 file as well as closed captioning. VLC picks up CC info from the stream; however, PLEX does not do so. So i have to extract it to .srt manually. So i convert .ts to smaller size mp4, extract closed captions. i want to create one script that will do all this, then remove the .ts files too. – NixonShaun Feb 7 '18 at 13:01
  • You're not reading my comment correctly. You write that you want to extract the subtitles from the .ts file, but the code you show is extracting it from the .mp4 files. So what is it? – wurtel Feb 7 '18 at 13:49
  • my apologies. I will try change it to .ts and see if it still pulls the closed captions out of the stream or if it has to pull it from the .mp4. will update you one i get home from work and am able to test it on .ts file. At present it is extracting the closed caption subtitles from the mp4 file. – NixonShaun Feb 7 '18 at 16:56
  • thank you i tested it and ccextract will work on both .ts and .mp4. I have changed the Bash Script to For INf in *.ts Do... this will take the closed caption subtitle from the original file not the remuxed one. – NixonShaun Feb 7 '18 at 20:09
1

How about this:

for x in *.ts
do
  y=$(basename "$x" .ts)
  ffmpeg -i "$x" "$y".mp4
  ffmpeg -i "$x" "$y".srt
done
  • using what you wrote i made a change or two to include the ffmpeg options i use and to use ccextractor for subs as they are closed captions buried in a transport stream. for x in *.ts do y=$(basename "$x" .ts) ffmpeg -i "$x" -vf scale=-1:720 -c:v libx264 -crf 23 -preset ultrafast -c:a copy "$y".mp4 ccextractor "$x" -o "$y".srt done – NixonShaun Feb 7 '18 at 11:58
  • could not get it to post in code block, tried 4 spaces and highliting text and ctr k, but did not seem to work – NixonShaun Feb 7 '18 at 11:59
  • @StevenPenny: To be fair — the OP doesn’t have enough rep to upvote, and maybe they want to delay the “accept” until they get the answer completely working. – G-Man Feb 8 '18 at 0:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.