简体   繁体   English

Windows - FFmpeg - 如何将 jpg 文件映射到视频流 0:0 并且只包含音频流 0:2 而不是流 0:1 和 0:2

[英]Windows - FFmpeg - How to map a jpg file to video stream 0:0 and include only audio stream 0:2 and not stream 0:1 and 0:2 together

I am trying to write a batch script that begins by extracting a thumbnail "Cover.jpg" from an mkv video.我正在尝试编写一个批处理脚本,首先从 mkv 视频中提取缩略图“Cover.jpg”。 My end goal is to have this script recursively loop a folder full of videos to encode them all in one go.我的最终目标是让这个脚本递归地循环一个充满视频的文件夹,一次性对它们进行编码。

:: create cover art jpg
for %%G in (*.mkv) do (
%FF% -hide_banner -ss 30 -y -i "%%G" -vframes 1 -an Cover.jpg
)

Then I am trying to encode the 4K mkv video that I got the jpg thumbnail from to 1920x1080 resolution instead of it's native 4K to make it easier to play back on my home plex server.然后,我尝试将获得 jpg 缩略图的 4K mkv 视频编码为 1920x1080 分辨率,而不是原生 4K,以便更轻松地在我的家庭 plex 服务器上播放。

I have surround sound 6 channel speaker system so I want to take audio stream 0:2 which is Dolby DTS 6 channel and save some HDD space by converting it to -c:a ac3 -b:a 640k -ac 6 .我有环绕声 6 声道扬声器系统,所以我想采用杜比 DTS 6 声道的音频流 0:2 并通过将其转换为-c:a ac3 -b:a 640k -ac 6来节省一些硬盘空间。

I have gotten stuck because I can achieve everything I want except I keep encoding 2 of the 4 audio streams available in the end.我被卡住了,因为我可以实现我想要的一切,除了我最后对 4 个可用音频流中的 2 个进行编码。 I only want to keep 1 audio stream to maximize my space savings.我只想保留 1 个音频流以最大限度地节省空间。

Here is the entire script so far.这是到目前为止的整个脚本。

@echo off
setlocal enabledelayedexpansion
prompt $g
color 0a

pushd "%~dp0"

set FF=C:\MAB\local64\bin-video\ffmpeg.exe
set TITLE=MOVIETITLE

:: create cover art jpg file
for %%G in (*.mkv) do (
%FF% -hide_banner -ss 30 -y -i "%%G" -vframes 1 -an Cover.jpg
)

:: run ffmpeg x265
for %%I in (*.mkv) do (
set fname="%%~nxI"
set fout="%%~nI-temp.mkv"
call :runff !fname! !fout!
del /s /q *.jpg
pause
goto:eof
)

:runff
%FF% -ss 0 ^
-y ^
-i "%~1" ^
-attach "Cover.jpg" ^
-map_metadata 0 ^
-map_chapters 0 ^
-metadata title="%TITLE%" ^
-map 0:0 -metadata:s:v:0 language=eng ^
-map 0:2 -metadata:s:a:0 language=eng -metadata:s:a:0 title="Surround 5.1 (DTS)" ^
-map 0:3 -metadata:s:s:0 language=eng -metadata:s:s:0 title="English" -metadata:s:t:0 filename="Cover.jpg" -metadata:s:t:0 mimetype="image/jpeg" ^
-c:v libx265 -preset medium ^
-x265-params crf=18:qcomp=0.8:aq-mode=1:aq_strength=1.0:qg-size=16:psy-rd=0.7:psy-rdoq=5.0:rdoq-level=1:merange=44 ^
-c:a ac3 -b:a 640k -ac 6 ^
-t 3 ^
"%~2"
exit /b

Here are the output logs.这是输出日志。 https://pastebin.com/hVMy3VJW

You can see towards the bottom that it is encoding both audio streams.您可以在底部看到它正在编码两个音频流。

Any ideas guys?有什么想法吗?

Solved:解决了:

Update: 06.21.20 -Improved variable name output method.更新:06.21.20 - 改进了变量名输出方法。 -Formatting changes - 格式更改

Instructions: Create a batch file with this code and place it in the folder with the files you are wanting to change.说明:使用此代码创建一个批处理文件,并将其放置在您要更改的文件所在的文件夹中。 You must change the ff variable to point to your own ffmpeg.exe file if it is not on the system path.如果它不在系统路径上,您必须将ff变量更改为指向您自己的ffmpeg.exe文件。 This only works with .mkv videos.这仅适用于.mkv视频。

This script by default will erase all audio channels except for the first one and replace it with aac surround 6 channel encoding.默认情况下,此脚本将擦除除第一个之外的所有音频通道,并将其替换为 aac 环绕 6 通道编码。 It will name the channel the same name as the input file.它会将通道命名为与输入文件相同的名称。 The original file will still be there in case you make an error and need to retry.原始文件仍然存在,以防您出错并需要重试。

@echo off
setlocal enabledelayedexpansion
color 0a

pushd "%~dp0"

set ff=C:\MAB\local64\bin-video\ffmpeg.exe

set sec=30
set fjpeg=cover.jpg

for %%G in (*.mkv) do (
%ff% -hide_banner -ss %sec% -y -i "%%G" -vframes 1 -an !fjpeg!
)

for %%I in (*.mkv) do (
set fname="%%~nxI"
set title="%%~nI"
set audio="AAC Surround 5.1"
set fout="%%~nI_audio_new.mkv"
call :runFF !fname! !title! !audio! !fout!
del /q *.jpg
pause
goto :eof
)

:runFF
%ff% ^
-y ^
-i "%~1" ^
-attach "!fjpeg!" ^
-map_metadata 0 ^
-map_chapters 0 ^
-metadata title="%~2" ^
-map 0:0 -metadata:s:v:0 language=eng -metadata:s:s:0 language=eng -metadata:s:s:0 title="English" -metadata:s:t:0 filename="!fjpeg!" -metadata:s:t:0 mimetype="image/jpeg" ^
-map 0:1 -metadata:s:a:0 language=eng -metadata:s:a:0 title="%~3" ^
-c:v copy ^
-c:a ac3 -b:a 640k -ac 6 ^
"%~4"
exit /b

Original post below:原帖如下:

I figured out you can combine the different -map streams.我发现你可以组合不同的-map流。 So I took -map 0:0 and combined it with -map 0:3 and left -map 0:2 to decode the audio stream I wanted.所以我把-map 0:0-map 0:3和 left -map 0:2起来解码我想要的音频流。

Here is a working script that fits my question.这是一个适合我的问题的工作脚本。

@echo off
setlocal enabledelayedexpansion
prompt $g
color 0a

pushd "%~dp0"

set FF=C:\MAB\local64\bin-video\ffmpeg.exe

:: create cover art jpg file
for %%G in (*.mkv) do (
%FF% -hide_banner -ss 30 -y -i "%%G" -vframes 1 -an Cover.jpg
)

:: run ffmpeg x265
for %%I in (*.mkv) do (
set TITLE=%%~nI
set fname="%%~nxI"
set fout="%%~nI(1080p).mkv"
call :runff !fname! !fout!
del /s /q *.jpg
pause
goto:eof
)

:runff
%FF% ^
-y ^
-i "%~1" ^
-attach "Cover.jpg" ^
-map_metadata 0 ^
-map_chapters 0 ^
-metadata title="%TITLE%" ^
-map 0:0 -metadata:s:v:0 language=eng -metadata:s:s:0 language=eng -metadata:s:s:0 title="English" -metadata:s:t:0 filename="Cover.jpeg" -metadata:s:t:0 mimetype="image/jpeg" ^
-map 0:2 -metadata:s:a:0 language=eng -metadata:s:a:0 title="Surround 5.1 (DTS)" ^
-c:v libx265 -preset medium -crf 20 -vf "scale=1920:-1" -threads 0 ^
-c:a ac3 -b:a 640k -ac 6 ^
"%~2"
exit /b

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM