Log in

View Full Version : Ignore (soft-coded) subtitles with AviSynth?


wthreex
19th May 2020, 09:32
Is there a way to remove or ignore all existing subtitles in file with Avisynth or Megui ? Everytime i have to delete subtitles with my hand so im looking for some functions in avisynth to check if there are subtitles in files then ignore or delete them.

StainlessS
19th May 2020, 10:32
Soft coded subtitles in a video (eg mp4) have multiplexed subtitle streams, quite often in the SRT text format, hard coded have the subs 'burnt' into the video
and cannot be 'deleted', few people on D9 want to use hard coded subs unless for very specific reasons.
To remove soft subs, just remux without copying the subs stream. [athough I dont know why anybody would want to bother removing soft subs].

EDIT: You might be able to remove 'hard coded' subs using an avisyth delogo style plugin, but is a lot of work.
Soft subtitles are not visible in avisynth, they are not part of the video, ie not 'burnt in'.

wthreex
19th May 2020, 11:10
athough I dont know why anybody would want to bother removing soft subs

Because I burn my own subtitles and the other hand some players like potplayer shows the embedded subtitles by default, Can it be done by avisynth ? i dont want remux files without srt files by my hand everytime.

https://i.imgur.com/41pWOyM.png

StainlessS
19th May 2020, 11:13
Avisynth sees only uncompressed video, it has no idea at all whether or not the original source file has soft subs.
See above EDIT.

StainlessS
19th May 2020, 11:22
Use the remux option from here to batch remux files without subs. [Needs hand edit to remux mode, and maybe change output container to eg MP4 (at end of line)].

Demo.bat

REM https://forum.doom9.org/showthread.php?p=1908619#post1908619
REM We DO NOT LIKE SPACES IN FILE NAMES (REM == REMark ie comment)

setlocal

REM Where to Find ffmpeg
set FFMPEG="C:\BIN\ffmpeg.exe"

REM Where to get INPUT files, No terminating Backslash, "." = current directory (ie same as dir .bat file)
set INDIR="."

REM Where to place OUTPUT files, No terminating Backslash. "." would be same as .bat file, ".\OUT" = OUT folder in same directory as bat file.
set OUTDIR="D:"

REM Below, can add INPUT extensions as eg *.WEBM (SPACE separated, Batch Processes all INPUT type files in INDIR)
FOR %%A IN (*.AVI *.MKV *.MP4 *.MOV *.QT *.3GP *.DVB *.VOB *.MPG *.MPEG *M2P *.PS *.TS *.DIVX *.XVID *.FLV *.WMV *.ASF *.MXF) DO (

REM ****** Un-REM [ie SELECT] ONLY one of below lines, Comment out ie REM the remaining lines.
%FFMPEG% -i "%INDIR%\%%A" -vcodec utvideo -acodec pcm_s16le "%OUTDIR%\%%~nxA.AVI"
REM %FFMPEG% -i "%INDIR%\%%A" -vcodec huffyuv -acodec pcm_s16le "%OUTDIR%\%%~nxA.AVI"
REM %FFMPEG% -i "%INDIR%\%%A" -vcodec magicyuv -acodec pcm_s16le "%OUTDIR%\%%~nxA.AVI"
REM %FFMPEG% -i "%INDIR%\%%A" -vcodec v410 -acodec pcm_s16le "%OUTDIR%\%%~nxA.AVI"
REM %FFMPEG% -i "%INDIR%\%%A" -vcodec r210 -acodec pcm_s16le "%OUTDIR%\%%~nxA.AVI"
REM %FFMPEG% -i "%INDIR%\%%A" -vcodec copy -acodec copy "%OUTDIR%\%%~nxA.MKV"
REM %FFMPEG% -i "%INDIR%\%%A" -vcodec utvideo -acodec copy "%OUTDIR%\%%~nxA.MKV"
REM %FFMPEG% -i "%INDIR%\%%A" -vn -acodec pcm_s16le "%OUTDIR%\%%~nxA.WAV"
REM *****************************************************************************************.

)
Pause

REM ... Above Command lines, What they do if UnREM'ed (and all others REM'ed, UnREM=UnCOMMENT ) :
REM (1) Convert Video to UtVideo lossless, Convert Audio to 16 bit PCM audio (output AVI).
REM (2) Convert Video to HuffYUV lossless, Convert Audio to 16 bit PCM audio (output AVI).
REM (3) Convert Video to MagicYUV lossless, Convert Audio to 16 bit PCM audio (output AVI).
REM (4) Convert Video to v410 Uncompressed 4:4:4 10-bit lossless, Convert Audio to 16 bit PCM audio (output AVI).
REM (5) Convert Video to r210 Uncompressed RGB 10-bit lossless, Convert Audio to 16 bit PCM audio (output AVI).
REM (6) Remux, copy both video and audio (output MKV - see file extension at the end of the Remux line, ie MKV).
REM (7) Convert Video to UtVideo lossless, copy audio (output MKV).
REM (8) Skip any video, Convert Audio to 16 bit PCM (output WAV).
REM *****************************************************************************************.
REM In the UnREM'ed command Line [ie without a preceding REM]:-
REM '-vcodec utvideo' means convert video using utvideo codec.
REM '-vcodec copy' means copy video rather than convert.
REM '-vn' means no video output, use instead of eg '-vcodec utvideo'
REM '-acodec pcm_s16le' means convert audio using pcm_s16le codec.
REM '-acodec copy' means copy audio rather than convert.
REM '-an' means no audio output, use instead of eg '-acodec pcm_s16le'
REM The file extension at end of the line determines output container, eg '.AVI'
REM
REM From Command line with ffmpeg somewhere in your environment PATH:-
REM 'ffmpeg -codecs >D:\ffmpeg_codecs.txt'
REM Writes a txt file of ffmpeg available codecs to D:\
REM At start of txt file it shows a 'legend' or 'key' for codecs that can be used for video and audio,
REM use only ENCODING SUPPORTED codecs, prefereably LOSSLESS.
REM Supported codecs will vary with ffmpeg version.
REM *****************************************************************************************.


EDIT: Actually, I tried to add command to copy subtitles when remuxing in above BAT file, but just kept getting a 'command not supported' style error message,
so above remux does NOT copy subtitles [which is what you want anyway].

wthreex
19th May 2020, 15:35
StainlessS Ok i give up on avisynth in this case, I googled for some simple ffmpeg command (i tried your command but nothing happend) i found this:


for file in *.mp4; do ffmpeg -i file -map 0:s -c copy -f null - && ffmpeg -i file -map 0 -map -0:s -c copy file; done


But i dont know why it says: "file: No such file or directory"

I want something like this: get all mp4 files in folder, check file if it has subtitle, then remove subtitle and create new file

StainlessS
19th May 2020, 16:05
Read the instructions


REM https://forum.doom9.org/showthread.php?p=1908619#post1908619
REM We DO NOT LIKE SPACES IN FILE NAMES (REM == REMark ie comment)

setlocal

REM Where to Find ffmpeg
set FFMPEG="C:\BIN\ffmpeg.exe" <<<<<<<<<<< Where your ffmpeg is

REM Where to get INPUT files, No terminating Backslash, "." = current directory (ie same as dir .bat file)
set INDIR="." <<<<<<<<<<<<< Where your input files are

REM Where to place OUTPUT files, No terminating Backslash. "." would be same as .bat file, ".\OUT" = OUT folder in same directory as bat file.
set OUTDIR="D:" <<<<<<<<<<<<< where to write output files

REM Below, can add INPUT extensions as eg *.WEBM (SPACE separated, Batch Processes all INPUT type files in INDIR)
FOR %%A IN (*.AVI *.MKV *.MP4 *.MOV *.QT *.3GP *.DVB *.VOB *.MPG *.MPEG *M2P *.PS *.TS *.DIVX *.XVID *.FLV *.WMV *.ASF *.MXF) DO ( <<<<<<<< File types processed

REM ****** Un-REM [ie SELECT] ONLY one of below lines, Comment out ie REM the remaining lines.
REM %FFMPEG% -i "%INDIR%\%%A" -vcodec utvideo -acodec pcm_s16le "%OUTDIR%\%%~nxA.AVI" <<<<<<<<<<<<<<<<<< REM
REM %FFMPEG% -i "%INDIR%\%%A" -vcodec huffyuv -acodec pcm_s16le "%OUTDIR%\%%~nxA.AVI"
REM %FFMPEG% -i "%INDIR%\%%A" -vcodec magicyuv -acodec pcm_s16le "%OUTDIR%\%%~nxA.AVI"
REM %FFMPEG% -i "%INDIR%\%%A" -vcodec v410 -acodec pcm_s16le "%OUTDIR%\%%~nxA.AVI"
REM %FFMPEG% -i "%INDIR%\%%A" -vcodec r210 -acodec pcm_s16le "%OUTDIR%\%%~nxA.AVI"
%FFMPEG% -i "%INDIR%\%%A" -vcodec copy -acodec copy "%OUTDIR%\%%~nxA.MKV" <<<<<<<<<< the command MUST EDIT, ie UN-REM this one and REM ther others
REM %FFMPEG% -i "%INDIR%\%%A" -vcodec utvideo -acodec copy "%OUTDIR%\%%~nxA.MKV" # EDIT: and output file type in blue above
REM %FFMPEG% -i "%INDIR%\%%A" -vn -acodec pcm_s16le "%OUTDIR%\%%~nxA.WAV"
REM *****************************************************************************************.


EDIT: I dont have your system, and have no idea where ffmpeg is nor where source files are nor where you want to write output, you must edit for what you want.
I have ffmpeg in C:\BIN, I also have it in C:\NON-INSTALL\MeGUI\tools\ffmpeg\ffmpeg.exe.

wthreex
19th May 2020, 16:24
Now:


[mp4 @ 000001fa3499e7c0] Could not find tag for codec pcm_s16le in stream #1, codec not currently supported in container
Could not write header for output file #0 (incorrect codec parameters ?): Invalid argument
Error initializing output stream 0:1 --
Conversion failed!



the lines i changed:

set FFMPEG="C:\ffmpeg\bin\ffmpeg.exe"
set OUTDIR="C:\Users\Downloads"
%FFMPEG% -i "%INDIR%\%%A" -vcodec utvideo -acodec pcm_s16le "%OUTDIR%\%%~nxA.MP4"

StainlessS
19th May 2020, 16:34
no, this line
%FFMPEG% -i "%INDIR%\%%A" -vcodec copy -acodec copy "%OUTDIR%\%%~nxA.MKV" <<<<<<<<<< the command MUST EDIT, ie UN-REM this one and REM ther others

EDIT:
Each line has a different function, you want line 6


REM ... Above Command lines, What they do if UnREM'ed (and all others REM'ed, UnREM=UnCOMMENT ) :
REM (1) Convert Video to UtVideo lossless, Convert Audio to 16 bit PCM audio (output AVI).
REM (2) Convert Video to HuffYUV lossless, Convert Audio to 16 bit PCM audio (output AVI).
REM (3) Convert Video to MagicYUV lossless, Convert Audio to 16 bit PCM audio (output AVI).
REM (4) Convert Video to v410 Uncompressed 4:4:4 10-bit lossless, Convert Audio to 16 bit PCM audio (output AVI).
REM (5) Convert Video to r210 Uncompressed RGB 10-bit lossless, Convert Audio to 16 bit PCM audio (output AVI).
REM (6) Remux NO SUBTITLES, copy both video and audio but NOT subtitles(output MKV - see file extension at the end of the Remux line, ie MKV).
REM (7) Convert Video to UtVideo lossless, copy audio (output MKV).
REM (8) Skip any video, Convert Audio to 16 bit PCM (output WAV).

wthreex
19th May 2020, 16:40
Ok my bad :)

One note, This script apply on every files in folder even though there was no subtitles in file, Is it possible to check "if subtitles exists in the current file" do this... ?

StainlessS
19th May 2020, 16:47
I have no idea if ffmpeg can do that. Suggest only copy files that you wish processed.
You should make copy of the bat, and edit for whatever you require, also give it a sensible name. The supplied file is just a demo.

EDIT: I have a directory just for that bat file (and a number of similar bat files).
When I want to do somethng to a bunch of files, I copy them into that directory and execute one of the bats.

qyot27
19th May 2020, 16:53
for file in *.mp4; do ffmpeg -i file -map 0:s -c copy -f null - && ffmpeg -i file -map 0 -map -0:s -c copy file; done


But i dont know why it says: "file: No such file or directory
It says that because you're not using Bash. That's a Bash for loop. If you were inside of MSys2, Cygwin, git bash, or a WSL session (of the Linux distro of your choice) it'd work so long as the *.mp4 files exist in the directory where you executed the command.

manono
19th May 2020, 19:59
Because I burn my own subtitles and the other hand some players like potplayer shows the embedded subtitles by default, Can it be done by avisynth ?
Who cares what PotPlayer does? Unless they're hardcoded (burned into the video), the subs will never show up in your AviSynth script. You don't have to waste time removing embedded subs before adding your own.

You can do a quick check to determine if they're embedded or hardcoded. Open your video in VirtualDub2 (https://www.videohelp.com/software/VirtualDub2) and scroll around. If you see subs they're hardcoded. If you don't they're embedded and nothing to worry about.