ffmpeg / avconv:使用相同的编解码器和参数作为输入进行转码 [英] ffmpeg/avconv: transcode using same codec and params as input

查看:180
本文介绍了ffmpeg / avconv:使用相同的编解码器和参数作为输入进行转码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法告诉ffmpeg和/或avconv使用与输入编码相同的编解码器的输出,但是进行转码?



我正在寻找类似的东西:

  ffmpeg -i input.mp4 -vcodec same_as_input output.mp4 

请注意,我不是在寻找 -vcodec copy ,因为这将复制流而不进行代码转换。我想要它进行代码转换,但使用与编码输入文件相同的编解码器。



另外,如果可能的话,我想要为所有可能的参数,即:使用相同的比特率,帧大小等,从一个给定的输入文件中获取每个可能参数的值,而不是使用任何其他默认值。



上面的例子可能看起来很愚蠢,因为它过于简单(结果将与复制相同),但是想象一下,我添加了一些处理,例如开始时间和长度,或者甚至更复杂,例如添加重叠图像,但是我想确保它使用与输入文件相同的编码器(可能与参数相同)进行编码。

解决方案

这是一个简单的bash脚本。您需要调整它以包括音频流信息和您想要的其他任何参数。只测一次;结果可能会有所不同。

 #!/ bin / bash 
#复制相同的视频编解码器和比特率:通常这是不是一个好主意
#用法:./vidsame输入输出

echo计算视频比特率,这可能需要很长时间。

#或者你可以使用ffprobe来获取视频流比特率,
#但是并不是所有的输入将显示流比特率信息,所以ffmpeg用于
#完全解码输入得到实际的比特率。

bitratev =$(ffmpeg -i$ 1-f null - |& grep video:| awk -F'[:| kB]''{print $ 2}')
codecv =$(ffprobe -loglevel error -select_streams v:0 -show_entries stream = codec_name -of default = nk = 1:nw = 1$ 1)

ffmpeg -i$ 1 -c:v$ codecv-b:v$ bitratevk$ 2

echo视频比特率:$ bitratev
echo视频编解码器:$ codecv


Is there a way to tell ffmpeg and/or avconv to use for the output the same codec as the one the input is encoded with, but do the transcoding?

I'm looking for something like:

ffmpeg -i input.mp4 -vcodec same_as_input output.mp4

Note that I'm not looking for -vcodec copy, as that would copy the stream without transcoding. I want it to do the transcoding but use the same codec the input file is encoded with.

Also, if possible, I'd like to have the same for every possible parameter, that is: use the same bitrate, frame size, etc, take the value for every possible parameter from one given input file, rather than using any other defaults.

The above example may seem stupid because it's oversimplified (the result would be the same as copying), but imagine I add some processing, e.g. a start time and length, or even something more complex such as adding an overlay image, but I want to make sure it's encoded with the same encoder (and possibly the same parameters) as the input file.

解决方案

Here's a simple bash script. You'll need to adapt it to include audio stream info and whatever other parameters you want. Only tested once; results may vary.

#!/bin/bash
# Copies the same video codec and bitrate: usually this is not a good idea.
# Usage: ./vidsame input output

echo "Calculating video bitrate. This can take a long time."

# Alternatively you could just use ffprobe to get video stream bitrate,
# but not all inputs will show stream bitrate info, so ffmpeg is used to
# completely decode the input to get the actual bitrate.

bitratev="$(ffmpeg -i "$1" -f null - |& grep video: | awk -F'[:|kB]' '{print $2}')"
codecv="$(ffprobe -loglevel error -select_streams v:0 -show_entries stream=codec_name -of default=nk=1:nw=1 "$1")"

ffmpeg -i "$1" -c:v "$codecv" -b:v "$bitratev"k "$2"

echo "Video bitrate: $bitratev"
echo "Video codec: $codecv"

这篇关于ffmpeg / avconv:使用相同的编解码器和参数作为输入进行转码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆