[FFmpeg-user] ffmpeg script
Steve Boyer
steveboyer85 at gmail.com
Thu Feb 8 05:44:58 EET 2018
On Wed, Feb 7, 2018 at 9:24 PM, Steve Boyer <steveboyer85 at gmail.com> wrote:
>
> On Feb 7, 2018 6:37 PM, "Shaun Nixon" <nixon.shaun73 at gmail.com> wrote:
>
> i am working on an FFmpeg Bash script in linux.
> I am currently using HD Homerun which downloads ,TS files or transport
> stream which is a container with an mpeg2 inside with a closed caption
> steam for the subtitles. Plex media server will not recognize the closed
> caption though VLC will.
>
> my solution to date is to shrink the .ts file using ffmpeg and then extract
> the subtitle using ccextract.
>
> at present I run a bash script in each folder containing .ts files, but
> would like one I can run from the main directory that would look in all sub
> directories find .ts files remux them to mp4, extract the closed caption
> stream to .srt and then remove the .ts files.
>
> so far i have the following script. Steven Penny from Stack Exchange
> contributed code and i added in the ffmpeg and ccextract lines:
>
> #! /bin/bash
> 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
>
>
> This works well if I run it in a directory. I would like to add to it
> though and maybe have something like a
> Find . -name *.ts
> statement or some way for it to look in all folders on multimedia hdd for
> .ts files and then do the For Loop but am unsure how.
>
>
> Couple of suggestions:
> 1) tweak the script so it takes in an argument - the .ts file name that
> does the FFmpeg command and other programs. Generalize it.
> 2) instead of doing a for loop, do a "find . -iname '*.ts' -type f
> -execdir scriptname {} \+"
>
> This will find all filenames that end (case insensitive) with .ts, and
> execute your script on it.
>
>
> I also want to add something like
> rm /s *.ts
> but am unsure if this will work or where to add it after the For Loop.
> Would it need a [wait] statement after [done] on the last line.
>
>
> Another suggestion I've used in the past is FFmpeg returns 0 if
> successfully. In the script, have the if statement it checks be the FFmpeg
> command. If no problem, it returns 0 (if I recall correctly). Check this
> value and delete if you want. Give me a bit and I have an automatic DVD
> creation script I can copy and paste a section from.
>
NOTE: I'VE NOT EXECUTED THESE TONIGHT - MIGHT NOT WORK OR MIGHT NEED A FEW
TWEAKS
script.sh:
if [ ! -e lock ];
then touch lock;
if ffmpeg -y -i "$1" <options here> $(basename "$i" .ts) "$i.mp4";
then
rm "$1";
fi
Not at that box ATM (pulled script from my github repo), but should be able
to be invoked via
find <directory> -iname '*.ts' -type f -execdir /path/to/script.sh "{}" \;
I actually have that running as a crobjob that is ran every second. And the
"find" command actually ends in \+ for my use, which is really the wrong
way to do a find -execdir. Is it glamorous? no. Is there better way to
write it? yes. Have I taken the time to figure out if I can just use the \;
instead of \+? Nope - it is working, I ain't fixing it.
Steve
> any advice on writing a bash script that would search for .ts files,
> convert them to mp4, and then remove the .ts files would be greatly
> appreciated.
>
> -shaun
>
>
> Steve
>
> _______________________________________________
> ffmpeg-user mailing list
> ffmpeg-user at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-user
>
> To unsubscribe, visit link above, or email
> ffmpeg-user-request at ffmpeg.org with subject "unsubscribe".
>
>
>
More information about the ffmpeg-user
mailing list