简体   繁体   English

如何对音频流进行一次转码,但在两个输出中使用也分别转码的视频流?

[英]How to transcode audio stream once but use in two outputs with also video streams transcoded separately?

I wish to optimize the process of video transcoding.我希望优化视频转码的过程。 Exactly I need to get two different video resolutions with the same audio stream options, but now I transcode audio stream twice (as I think ffmpeg works).确切地说,我需要使用相同的音频流选项获得两种不同的视频分辨率,但现在我对音频流进行了两次转码(因为我认为 ffmpeg 有效)。

Source video has such audio stream:源视频有这样的音频流:

ffprobe /v
 /v: Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, 5.1, fltp, 437 kb/s (default)

Now I use these options for transcode one video into two qualities:现在我使用这些选项将一个视频转码为两种质量:

ffmpeg -to 00:00:10 -i /v \
  -c:a mp3 -ab 42k -vcodec libx264 -s 1920x1080 -b:v 4000k -preset fast -vprofile main -g 50 -f flv 1.mp4 \
  -c:a mp3 -ab 42k -vcodec libx264 -s 1280x720 -b:v 2000k -preset fast -vprofile main -g 50 -f flv 2.mp4

As you can see, I define audio stream settings twice for each output, and I think ffmpeg transcodes audio stream twice (does he?).如您所见,我为每个输出定义了两次音频流设置,并且我认为 ffmpeg 对音频流进行了两次转码(是吗?)。 I get audio stream parameters as expected:我得到了预期的音频流参数:

ffprobe 1.mp4
ffprobe 2.mp4
    1.mp4: Stream #0:1: Audio: mp3, 48000 Hz, stereo, fltp, 42 kb/s
    2.mp4: Stream #0:1: Audio: mp3, 48000 Hz, stereo, fltp, 42 kb/s

I wish to transcode audio stream once and use its output for two output files.我希望对音频流进行一次转码并将其输出用于两个输出文件。 How to do that?怎么做? I tried this, but got different audio stream parameters:我试过了,但得到了不同的音频流参数:

ffmpeg -to 00:00:10 -i /v \
  -c:a mp3 -ab 42k \
  -vcodec libx264 -s 1920x1080 -b:v 4000k -preset fast -vprofile main -g 50 -f flv 1.mp4 \
  -vcodec libx264 -s 1280x720 -b:v 2000k -preset fast -vprofile main -g 50 -f flv 2.mp4
ffprobe 1.mp4
ffprobe 2.mp4
    1.mp4: Stream #0:1: Audio: mp3, 48000 Hz, stereo, fltp, 42 kb/s
    2.mp4: Stream #0:1: Audio: mp3, 48000 Hz, stereo, fltp, 128 kb/s

As you can see, 2.mp4 has audio bitratte 128 Kb/s instead of 42 Kb/s.如您所见,2.mp4 的音频比特率为 128 Kb/s 而不是 42 Kb/s。 I tried to read about -map and -filter_complex, but hope on your help.我尝试阅读有关 -map 和 -filter_complex 的信息,但希望得到您的帮助。

AFAIK, there is no way to copy an output stream from one output file to another. AFAIK,没有办法将输出流从一个输出文件复制到另一个。 If OK to encode for each file, you can run如果可以对每个文件进行编码,则可以运行

ffmpeg -to 00:00:10 -i /v \
  -c:a mp3 -ab 42k \
  -vcodec libx264 -s 1920x1080 -b:v 4000k -preset fast -vprofile main -g 50 -f flv 1.mp4 \
  -c:a mp3 -ab 42k \
  -vcodec libx264 -s 1280x720 -b:v 2000k -preset fast -vprofile main -g 50 -f flv 2.mp4

All the codec options must be specified for each output file.必须为每个输出文件指定所有编解码器选项。

If the audio encoding does take substantial amount of time (typically it is insignificant compared to video encoding), you can try to chain 2 ffmpeg calls, piping one output to another.如果音频编码确实需要大量时间(通常与视频编码相比微不足道),您可以尝试链接 2 个 ffmpeg 调用,将一个输出管道传输到另一个。 Something like:就像是:

First command:第一个命令:

ffmpeg -to 00:00:10 -i /v \
  -f mp3 -ab 42k -

Second command:第二条命令:

ffmpeg -to 00:00:10 -i /v -f mp3 - \
  -map 0:v -map 1:a -vcodec libx264 -s 1920x1080 -b:v 4000k -preset fast -vprofile main -g 50 -f flv 1.mp4 \
  -map 0:v -map 1:a -vcodec libx264 -s 1280x720 -b:v 2000k -preset fast -vprofile main -g 50 -f flv 2.mp4

The caveat of this approach is audio/video synchronization.这种方法的警告是音频/视频同步。 They may be out-of-sync due to how they were cut.由于剪辑方式不同,它们可能不同步。 So, YMMV.所以,YMMV。

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

相关问题 合并 2 个音频流和一个视频 stream - Merge 2 audio streams and a video stream 如何检测转码音频的生成丢失 - How to detect generation loss of a transcoded audio 将两个音频流混合到android中的单个音频流中? - Mixing two audio streams into a single audio stream in android? 如何使用 ffmpeg 将所有音频流(在视频文件中)合并到一个音频通道中? - How do I use ffmpeg to merge all audio streams (in a video file) into one audio channel? 仅使用ffmpeg(以及所有音频流)重新编码视频流 - Re-encode video stream only with ffmpeg (and with all audio streams) 如何在自动化中验证音频/视频流 - How to verify audio/video streams in automation 如何使用具有多个音频流的 mpv 播放视频 - How to play a Video with mpv with multiple audio streams 如何在视频中仅选择两个音频流并将其馈送到 ffmpeg 中的 ebur128 过滤器? - How can select only two audio streams in a video and feed it to the ebur128 filter wiithin ffmpeg? 如何识别不同视频流和音频流的rtmp数据包 - how to identify rtmp packets of different video streams and audio streams Android MediaPlayer,如何播放没有音频的视频并且不中断其他音频流 - Android MediaPlayer, How to play video with no audio and not interrupt other audio streams
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM