删除视频的音频流 - 递归地,无需使用 FFMPEG 转换音频或视频

删除视频的音频流 - 递归地,无需使用 FFMPEG 转换音频或视频

假设您有一季电视节目,这是您能找到的最佳编码,但它有多个您不需要的音频流。您不想重新编码,降低视频/音频质量,浪费时间,但您也不想浪费空间来存储额外的音频流。而且,根据音频流的顺序,错误的音频流可能是默认的。

如何以递归方式剥离/转换文件树中的所有视频文件并仅保留所需的音频流?

我读到过 ffmpeg 是实现这一目的的最佳工具。

答案1

取消注释您要使用的行和文件类型。您可以添加更多“预设/标志”,这只是一个想法。

sudo nano /media/audio.sh

---视频递归转换脚本剥离音频流并且不转换任何内容!

#!/bin/bash

#Uncomment a Preset FLAGS depending on video/subtitle/audio stream wanting to keep, easy to find which stream via playing in VLC and hitting CTRL + J (when not in fullscreen)

#TO ADD SUBTITLES< THEY MUST BE SAME NAME AS FILE*Check out Filebot Filerenamer*
#Don't Strip audio and do subtitles at the same time, do one at a time
#To add subtitles, just uncomment the line under ADD SUBTITLES

#TO FIX AUDIO SYNC
#Use hotkeys J/K in VLC to find correct value
#DONT use FLAGS, just OFFSET 

#FLAGS DESC:
#"-map 0:0 -vcodec copy" -- which video stream to copy
#"-map 0:1 -acodec copy" -- which audio stream to copy
#"-map 0:2 -scodec copy" -- which subtitle stream to copy
#"-itsoffset 0.2"        -- DELAY Audio by 0.2 seconds can do -0.2 for opposite effect!

###Video Stream 0 Audio stream 1 Subtitle Stream 2
#export FLAGS="-map 0:0 -vcodec copy -map 0:1 -acodec copy -map 0:2 -scodec copy"

###Video Stream 0 Audio Stream 1
#export FLAGS="-map 0:0 -vcodec copy -map 0:1 -acodec copy"

###Audio Stream 2
#export FLAGS="-map 0:0 -vcodec copy -map 0:2 -acodec copy"

###Audio Stream 3
#export FLAGS="-map 0:0 -vcodec copy -map 0:3 -acodec copy"

##FIX AUDIO SYNC
#export OFFSET="-itsoffset 0.2"

if [ -z "$1" ] ; then
    TRANSCODEDIR="."
else
    TRANSCODEDIR="$1"
fi

    ##To remove source files after conversion and rename back to original w/o *FINAL*, uncomment second line #&&find (Must become 1 line of code IE: Hit delete 2 times)
    ##I do not reccomend using this unless you are 100% of what you are doing, it will delete source files even if conversion fails, basically unless you are creator of files
    ##ANY files without FINAL will be deleted, be warned, I have personally deleted many a files I didnt want to by using this line :P
    ##USE ALIASES (and confirm script results) INSTEAD OF &&FIND REMOVE AUTOMATION

    #AVI
    #find "$TRANSCODEDIR"/* -type f -name "*.avi" -exec bash -c 'ffmpeg -i "$1" $FLAGS "${1%\.*}"FINAL.avi ' __ {} \; 
#&& find . -type f -not -name '*FINAL.avi' -name '*.avi' -delete && rename 's/FINAL//' *.avi
    #AUDIO SYNC
    #find "$TRANSCODEDIR"/* -type f -name "*.avi" -exec bash -c 'ffmpeg -i "$1" $OFFSET -i "$1" -map 0:v -vcodec copy -map 1:a -acodec copy -map 0:s? -scodec copy "${1%\.*}"FINAL.avi ' __ {} \;
#&& find . -type f -not -name '*FINAL.mp4' -name '*.avi' -delete && rename 's/FINAL//' *.avi

    #MKV
    #FROM ORIGINAL STREAMS
    #find "$TRANSCODEDIR"/* -type f -name "*.mkv" -exec bash -c 'ffmpeg -i "$1" $FLAGS "${1%\.*}"FINAL.mkv ' __ {} \;
#&& find . -type f -not -name '*FINAL.mkv' -name '*.mkv' -delete && rename 's/FINAL//' *.mkv
    #ADD SUBTITLES
    #find "$TRANSCODEDIR"/* -type f -name "*.mkv" -exec bash -c 'ffmpeg -i "$1" -sub_charenc CP1252 -i "${1%\.*}".srt -vcodec copy -acodec copy "${1%\.*}"FINAL.mkv ' __ {} \;
#&& find . -type f -not -name '*FINAL.mkv' -name '*.mkv' -delete && rename 's/FINAL//' *.mkv
    #AUDIO SYNC
    #find "$TRANSCODEDIR"/* -type f -name "*.mkv" -exec bash -c 'ffmpeg -i "$1" $OFFSET -i "$1" -map 0:v -vcodec copy -map 1:a -acodec copy -map 0:s? -scodec copy "${1%\.*}"FINAL.mkv ' __ {} \;
#&& find . -type f -not -name '*FINAL.mp4' -name '*.mkv' -delete && rename 's/FINAL//' *.mkv

    #MP4
    #FROM ORIGINAL STREAMS
    #find "$TRANSCODEDIR"/* -type f -name "*.mp4" -exec bash -c 'ffmpeg -i "$1" $FLAGS "${1%\.*}"FINAL.mp4 ' __ {} \;
#&& find . -type f -not -name '*FINAL.mp4' -name '*.mp4' -delete && rename 's/FINAL//' *.mp4
    #ADD SUBTITLES
    #find "$TRANSCODEDIR"/* -type f -name "*.mp4" -exec bash -c 'ffmpeg -i "$1" -f srt -i "${1%\.*}".srt -c:v copy -c:a copy -c:s mov_text "${1%\.*}"FINAL.mp4 ' __ {} \;
#&& find . -type f -not -name '*FINAL.mp4' -name '*.mp4' -delete && rename 's/FINAL//' *.mp4
    #AUDIO SYNC
    #find "$TRANSCODEDIR"/* -type f -name "*.mp4" -exec bash -c 'ffmpeg -i "$1" $OFFSET -i "$1" -map 0:v -vcodec copy -map 1:a -acodec copy -map 0:s? -scodec copy "${1%\.*}"FINAL.mp4 ' __ {} \;
#&& find . -type f -not -name '*FINAL.mp4' -name '*.mp4' -delete && rename 's/FINAL//' *.mp4

--别名和自动化

sudo nano ~/.bashrc && sudo source ~/.bashrc 

alias audioscript="sudo cp /media/audio.sh ./ && sudo nano ./audio.sh ; nohup ./audio.sh > convert.nohup &"

alias mkvfinal="find . -type f -not -name '*FINAL.mkv' -name '*.mkv' -delete && rename 's/FINAL//' *.mkv && find . -name 'audio.sh' -delete && find . -name 'convert.nohup' -delete"

alias avifinal="find . -type f -not -name '*FINAL.avi' -name '*.avi' -delete && rename 's/FINAL//' *.avi && find . -name 'audio.sh' -delete && find . -name 'convert.nohup' -delete"

alias mp4final="find . -type f -not -name '*FINAL.mp4' -name '*.mp4' -delete && rename 's/FINAL//' *.mp4 && find . -name 'audio.sh' -delete && find . -name 'convert.nohup' -delete"

alias srtremove="find . -name '*.srt' -delete"

相关内容