• AnyStream is having some DRM issues currently, Netflix is not available in HD for the time being.
    Situations like this will always happen with AnyStream: streaming providers are continuously improving their countermeasures while we try to catch up, it's an ongoing cat-and-mouse game. Please be patient and don't flood our support or forum with requests, we are working on it 24/7 to get it resolved. Thank you.

Subtitles

Plex requires internet I believe? One of the places I watch doesn't have internet. I'm stuck with a roku or bluray player.
Plex doesn't require internet, it just requires that if you don't have internet, that your media player is on the same LAN (Local Area Network or home network) as the Plex server. Plex reads the embedded subtitles just fine that are created with Anystream (As far as everything I've tested). Depending on how you have your Plex setup, you may have to select the subtitle each time, but it should be there. Plex only needs the internet for subtitles, if it is trying to pull subtitles for media you have that doesn't have the subtitles embedded (Anystream's embedding, not the plex burn-in stuff, or the likes). Plex does have an option on most versions of the player ("most" is an assumption) to automatically play subtitles for audio tracks that are not already in the default language, and it seems to work pretty well.
 
I did and it didn't change anything. I can see a half second blip on my taskbar but no widow actually opens and when I watched Task Manager I didn't see anything pop there either.

Oh and didn't we make it non-recursive? I just noticed it's also going down folder levels.

I have no idea wrong with your system.

I left it recursive because you said you didn't care. If you want to stop it, remove the /r from the for loop.
 
I have no idea wrong with your system.

I left it recursive because you said you didn't care. If you want to stop it, remove the /r from the for loop.

Yeah I probably did and forgot. No worries, not a big deal.
 
Yeah I probably did and forgot. No worries, not a big deal.

You could try putting like:
Echo hello
Pause

At the start of the script to see if you're even getting into it when you drag and drop.
 
You could try putting like:
Echo hello
Pause

At the start of the script to see if you're even getting into it when you drag and drop.

Window open, I get the hello. I hit a key to continue and the window closes and no MKV is output.
 
Window open, I get the hello. I hit a key to continue and the window closes and no MKV is output.

OK, good. That means it's at least getting in there. That eliminates a whole host of problems.

What OS are you running? I assumed it was Windows 10 like me, but maybe not.

If you running it from a command shell, and give it the path you're trying to drag to it, it should show you what error it's getting.
 
OK, good. That means it's at least getting in there. That eliminates a whole host of problems.

What OS are you running? I assumed it was Windows 10 like me, but maybe not.

If you running it from a command shell, and give it the path you're trying to drag to it, it should show you what error it's getting.

Yep Windows 10. When I ran it from the command prompt it worked fine. But drag and drop does not work. It just immediate closes once I hit a key to start the process after the Hello.

Although I fully admit that I'm command prompt dumb so I don't know that I did it right.
 
Yep Windows 10. When I ran it from the command prompt it worked fine. But drag and drop does not work. It just immediate closes once I hit a key to start the process after the Hello.

Although I fully admit that I'm command prompt dumb so I don't know that I did it right.

When you called it from the command prompt, did you give it the path?
 
I don't know what that means. I'm sorry. I open a command prompt window. CD to the location and then typed in the batch file name. So, I'm going to say that I did not give it a path.
 
I don't know what that means. I'm sorry. I open a command prompt window. CD to the location and then typed in the batch file name. So, I'm going to say that I did not give it a path.

Yeah, what you did is the same as just double clicking on it.

Try this, add these lines to the start of the script and drag your file or directory to it:

@Echo path is %1
@if exist "%~1" echo path exists
@if not exist "%~1" echo path doesn't exist
pause


what is the output?
 
Ah, I think I just replicated your issue. Does that path have spaces in it? I thought I properly compensated for that, but I just tested it and I got what you did. Seems like a classic "spaces in the file name" bug!

Give me a second...
 
Yeah, what you did is the same as just double clicking on it.

Try this, add these lines to the start of the script and drag your file or directory to it:

@Echo path is %1
@if exist "%~1" echo path exists
@if not exist "%~1" echo path doesn't exist
pause


what is the output?

path is "C:\Data\Movie Stuff\Anystream\test\Title title title_S01E01-[provider].mp4"
path exists
Press any key to continue . . .

hit a key and it disappeared.

Ah, I think I just replicated your issue. Does that path have spaces in it? I thought I properly compensated for that, but I just tested it and I got what you did. Seems like a classic "spaces in the file name" bug!

Give me a second...

Maybe not because when I try movie-[provider].mp4 is does the same thing and doesn't give an output and window just disappears.
 
OK, found it. When I added the double-click support, I forgot to strip any existing quoted before I explicitly quoted the command line argument to test it.

God, I really hate batch files. :)

Sorry about that. Give this a try.

Code:
@:: batch file to convert mp4 files to mkv
@echo off
setlocal EnableExtensions EnableDelayedExpansion

:: languages
set "langs=en eng"

:: subtitles file patterns
set "subpats={LNG}.forced {LNG} {LNG}-us {LNG}.cc {LNG}-us.cc"

:: separator (characters between title and subtitles pattern
set "subsep=."

:: location of mvkmerge
set "mkvmerge=C:\Program Files\MKVToolNix\mkvmerge.exe"

:: output subdirectory
set "outdir=Anystream\mkv"

:: if there are no arguments, process the directory containing the script
if "%~1" == "" (
  call :DIR "%~dp0"
  goto :DONE
)

:: iterator through command line arguments
:CMDS
set "curr=%~1"

if "%curr%" == "" goto :DONE

:: ensure current arg exists
if not exist "%curr%" goto :EOF

:: determine if current arg is a dir or a file
pushd "%curr%" >NUL 2>&1
if ERRORLEVEL 1 (
  call :FILE "%curr%"
) else (
  call :DIR "%curr%"
)

shift
goto :CMDS

:DIR
echo recursing %1...
for /r %%i in ("*.mp4") do call :FILE "%%~i"
popd
goto :EOF

:FILE
:: ignore non-mp4 files
if /i "%~x1" NEQ ".mp4" goto :EOF

echo processing %1
pushd "%~dp1"
mkdir "%outdir%" >NUL 2>&1

:: process subtitles
set subs=
for %%L in (%langs%) do (
  for %%P in (%subpats%) do (
  set opts=
   
  :: substitute current language into pattern
  set pat=%%P
  set "pat=!pat:{LNG}=%%L!"
   
  :: if file exist, process it
  set "file=%~n1%subsep%!pat!.srt"
  if exist "!file!" (
  echo found subtitles file: "!file!"

  :: check for "forced" in subtitle file name
  echo !file! | find /i "forced" > NUL 2>&1
  if ERRORLEVEL 1 (
  set "opts=!opt! --default-track 0:0 --forced-track 0:0 --track-name 0:!pat!"
  ) else (
  set "opts=!opt! --default-track 0:1 --forced-track 0:1 --track-name 0:!pat!"
  )

  :: add new subtitles file to list   
  set "subs=!subs! !opts! ^"!file!^""
  )
  )
)

"%mkvmerge%" --default-language en -o "%outdir%\%~n1.mkv" "%~nx1" %subs%
popd
goto :EOF

:DONE
echo Done.
pause
 
Winner winner chicken dinner.

Yes! See, Linux is easier because it automatically strips quotes, then you just ensure you always quote files names and you don't have this issue.
Windows doesn't. So, to ensure stuff is always quoted, you have to strip any that the user or system may have put on the file names, before explicitly added them. If not, you just end up with two sets of quotes, which breaks it.
 
I might have an alternative solution ... more graphical, and could take some seconds longer.

By no means I want to diminish the efforts put into the script created by DrXenos.
Programmers who can come up with something just like that have my greatest respect.
Maybe if I spend many hours, I could come up with something similar but far more dirty myself :whistle:
Because of that and the fact, that this script is customized for sycor, I'd like to propose the solution I would use.

You would need my favourite tools-combination Staxrip and the neat little Renamer Lite from den4b
Starting with the Renamer (the Lite version can handle a maximum of 5 rules, but we need only one) add a new (Replace-) Rule like this:
2022-03-20%2013_45_33-ReNamer.png

Note the ticked "Case sensitive" and unticked "Skip extension"
Now drag&drop single or multiple files or folders into the window.
You might want to play with the rule youself and check the result below without actually renaming anything.
When done, just Click "Rename"

That one is necessary, because Staxrip only recognizes the correct language text

Next up, Staxrip:
After the first start go to File > Project templates > Remux
Options > Audio > Preferred languages set to "All"
Options > Subtitles > Demux and include preferred languages .... Languages set to "all"
Options > Paths > (set your preferred temp and output path)
File > Save Project As Template > (Check "Load template on startup") OK

You can start by dragging the mp4 into the source field.
If you click "Container Configration" you can see the magic and why we needed to rename the subtitle files first.
2022-03-20%2014_17_23-Thor.png

Of course you can feed it multiple files and even folders by right-clinging the source field.
 
Last edited:
I might have an alternative solution ... more graphical, and could take some seconds longer.

By no means I want to diminish the efforts put into the script created by DrXenos.

No offense taken at all. All idea are welcome.

That script was just thrown together over a couple of day's for one person's specific needs.

For contrast, this is the script I use myself with AS. It's written in Bash, so it take a little more effort to make it run as seamlessly in Windows as a batch file (it will also run is WSL).

I always download with the subtitles embedded. That way, I more easily glean their languages and the track names are already set. Since mkvmerge doesn't handle timed text, the script uses My MP4Box to convert it to srt. Next, it determines and sets the forced flag when necessary. It does so heuristically, by either finding "forced" in the track name or by the number of subtitles being below a certain threshold (but non-zero because I have run into that corner case!).

Lastly, it prints out a summary of all the files that have forced subtitles in them.

Code:
#!/bin/bash
# convert mp4 files to mkv, converting timed text subtitles to srt

# determine if running on WSL (as opposed to msys)
WSL=0
if uname -a | grep -i "microsoft"; then
  WSL=1
fi

if (( $WSL )); then
MP4BOX="/mnt/c/Program Files/GPAC/mp4box.exe"
MKVMERGE="/mnt/c/Program Files/MKVToolNix/mkvmerge.exe"
else
MP4BOX="C:/Program Files/GPAC/mp4box.exe"
MKVMERGE="C:/Program Files/MKVToolNix/mkvmerge.exe"
fi

TMPFILE="mp42mkv.tmp"

forced_samples_threshold=50

# make file glob empty if not found
shopt -s nullglob nocasematch

# get list of files
if (( $# == 0 )); then
  files=(*.mp4)
else
  files=("$@")
fi

forced_list=()

function convert_file()
{
  local f="$1"
  local file="${f%.*}"
 
  #
  # extract subtiles from mp4 file
  #
 
  # get number of tracks
  tks=$("${MP4BOX}" -tracks "$f" | tr -d '\r')
  echo "$f ($tks tracks)"
 
  # arrays to save info on subtitles
  sub_track=()
  sub_lang=()
  sub_forced=()
  sub_name=()
  sub_filename=()

  # iterate through tracks
  for i in $(seq 1 $tks); do
  # get track info
  "${MP4BOX}" -infon $i "$f" &> "$TMPFILE"
 
  if grep --quiet tx3g "$TMPFILE"; then
  echo "track $i is subtitles"
 
  # get number of samples
  samp=$(egrep --only-matching '[0-9]+ samples' "$TMPFILE" | egrep --only-matching '[0-9]+')
  echo "number of samples is $samp"

  if (( samp > 0 )); then 
  # save track number
  sub_track+=($i)
 
  # get language code
  lng=$(egrep --only-matching 'Language[^(]*\([a-z]+' "$TMPFILE" | egrep --only-matching '[a-z]{3}$')

  # fix language issue
  if [[ "$lng" == "qbu" || "$lng" == "und" ]]; then
  lng=eng
  fi
 
  echo "language is \"$lng\""
 
  # save language code
  sub_lang+=($lng)
 
  # determine if subtitles are forced
 
  # check track name for "forced"
  if grep --quiet "forced" "$TMPFILE"; then
  forced=1
  # check if number of samples is less than threshold
  elif (( samp <= forced_samples_threshold )); then
  forced=1
  else
  forced=0
  fi
 
  if (( forced )); then
  echo "subtitles track $i are forced"
  forced_list+=("${file}.mkv")
  fi
 
  # save forced
  sub_forced+=($forced)
 
  # get track name
  name=$(egrep --only-matching 'Handler name:\s*.*' "$TMPFILE" | sed 's/Handler name:\s*//' | tr -d '\r')
 
  # ensure "forced is in the name of a forced subtitles track
  if (( forced )); then
  if [[ -z "$name" ]]; then
  name="Forced"
  elif [[ ! "$name" =~ .*forced.* ]]; then
  name="$name (forced)"
  fi
  fi

  echo "name is \"$name\""
 
  # save name
  sub_name+=("${name}")
 
  # extract subtitles track
  echo "extracting subtitles track $i"
  if ! "${MP4BOX}" -srt $i "$f"; then
  return 1
  fi
 
  # save filename
  sub_filename+=("${file}_${i}_text.srt")
  fi # samp > 0
  fi
  done
 
  #
  # remux mp4 file with mkvmerge
  #
 
  # build subtitles tracks options
  opt=()
 
  cnt=$(( ${#sub_track[@]} - 1 ))
  for i in $(seq 0 $cnt); do
     opt+=("--language" "0:${sub_lang[$i]}")
     opt+=("--default-track" "0:0")
     opt+=("--forced-track" "0:${sub_forced[$i]}")
     opt+=(--track-name "0:${sub_name[$i]}")
     opt+=("${sub_filename[$i]}")
  done
 
  # remux mp4 file to mkv
  echo "remuxing with mkvmerge"
  if ! "${MKVMERGE}" --disable-track-statistics-tags -o "${file}.mkv" --no-track-tags --no-global-tags "${f}" "${opt[@]}"; then
  return 1
  fi
 
  # remove subtitles files
  rm -f "${sub_filename[@]}" "$TMPFILE"
  return 0
}

for f in "${files[@]}"; do
  if [[ -d "$f" ]]; then
  pushd "$f" > /dev/null
 
  files2=(*.mp4) 
  for f2 in "${files2[@]}"; do
  if ! convert_file "$f2"; then
  exit 1
  fi
  done
 
  popd > /dev/null
 
  elif ! convert_file "$f"; then
  exit 1
  fi
done

# dump out list of files with forced subtitles
if (( ${#forced_list[@]} > 0 )); then
  echo -e "\n\nfiles with forced subtitles:"
  for i in "${forced_list[@]}"; do
     echo "$i"
  done
  echo -e "\n"
fi
 
Back
Top