考虑这个输出
General
Complete name : sample.mp4
Format : MPEG-4
Format profile : QuickTime
Codec ID : qt
File size : 37.3 MiB
Duration : 9mn 56s
Overall bit rate mode : Variable
Overall bit rate : 525 Kbps
Writing application : Lavf52.73.0
Video
ID : 1
Format : AVC
Format/Info : Advanced Video Codec
Format profile : [email protected]
Format settings, CABAC : No
Format settings, ReFrames : 3 frames
Codec ID : avc1
Codec ID/Info : Advanced Video Coding
Duration : 9mn 56s
Bit rate : 400 Kbps
Width : 424 pixels
Height : 240 pixels
Display aspect ratio : 16:9
Frame rate mode : Constant
Frame rate : 24.000 fps
Color space : YUV
Chroma subsampling : 4:2:0
Bit depth : 8 bits
Scan type : Progressive
Bits/(Pixel*Frame) : 0.164
Stream size : 29.9 MiB (80%)
Writing library : x264 core 98 r1629 9d1c441
Encoding settings : cabac=0 / ref=3 / deblock=1:0:0 / analyse=0x1:0x111 / me=hex / subme=7 / psy=1 / psy_rd=1.00:0.00 / mixed_ref=1 / me_range=16 / chroma_me=1 / trellis=0 / 8x8dct=0 / cqm=0 / deadzone=21,11 / fast_pskip=1 / chroma_qp_offset=-2 / threads=64 / sliced_threads=0 / nr=0 / decimate=1 / interlaced=0 / constrained_intra=0 / bframes=0 / weightp=0 / keyint=90 / keyint_min=25 / scenecut=40 / intra_refresh=0 / rc_lookahead=40 / rc=abr / mbtree=1 / bitrate=400 / ratetol=10.0 / qcomp=0.60 / qpmin=10 / qpmax=51 / qpstep=4 / vbv_maxrate=768 / vbv_bufsize=3000 / ip_ratio=1.41 / aq=1:1.00 / nal_hrd=none
Language : English
Audio
ID : 2
Format : AAC
Format/Info : Advanced Audio Codec
Format profile : LC
Codec ID : 40
Duration : 9mn 56s
Bit rate mode : Variable
Bit rate : 99.1 Kbps
Channel(s) : 2 channels
Channel positions : Front: L R
Sampling rate : 48.0 KHz
Compression mode : Lossy
Stream size : 7.04 MiB (19%)
Language : English
这是显示媒体信息的命令的示例输出。它在“视频”标题下包含一个比特率,在“音频”标题下包含另一个比特率。我的目标是将这两个变量存储为BASH脚本中的不同变量。
grep使用行号,因为某些文件可能包含音频部分,而有些则没有。那么,有什么方法可以将这两个同名的值保存到不同的变量中?
您可以使用sed分别打印“视频”和“音频”部分,然后使用另一个sed提取比特率。假设该信息位于文件中。
VIDEO=`sed -n '/^Video$/,/^$/p' file`
AUDIO=`sed -n '/^Audio$/,/^$/p' file`
VBR=`echo $VIDEO | sed -nr 's/^Bit rate +: //p'`
ABR=`echo $AUDIO | sed -nr 's/^Bit rate +: //p'`
关于提取视频和音频章节:
sed -n
选项表示无打印/.../,/.../
我定义一个开始的正则表达式和一个结束的正则表达式/^Audio$/
表示整行仅包含“音频”/^$/
表示空白行p
命令将打印上面定义的范围(该范围覆盖-n)本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句