ffmpeg -i /Users/Private/sample.flv -c:v libx264 -vframes 600 -y /Users/Private/out.mp4
输入文件和输出文件的信息:
$ ffmpeg -i /Users/Private/sample.flv -c:v libx264 -vframes 600 -y /Users/Private/out.mp4
ffmpeg version N-92079-gab492f9322 Copyright (c) 2000-2018 the FFmpeg developers
built with Apple LLVM version 10.0.0 (clang-1000.11.45.5)
configuration: --pkg-config-flags=--static --enable-libx264 --enable-libx265 --enable-libfreetype --enable-libfontconfig --enable-libfribidi --disable-doc --enable-version3 --enable-debug=3 --enable-gpl --disable-optimizations --disable-stripping --disable-ffplay --disable-ffprobe --disable-decoder=vp9
libavutil 56. 19.101 / 56. 19.101
libavcodec 58. 31.101 / 58. 31.101
libavformat 58. 18.103 / 58. 18.103
libavdevice 58. 4.104 / 58. 4.104
libavfilter 7. 33.100 / 7. 33.100
libswscale 5. 2.100 / 5. 2.100
libswresample 3. 2.100 / 3. 2.100
libpostproc 55. 2.100 / 55. 2.100
Input #0, flv, from '/Users/Private/sample.flv':
Metadata:
major_brand : qt
minor_version : 512
compatible_brands: qt
encoder : Lavf58.20.100
Duration: 00:09:56.46, start: 0.000000, bitrate: 530 kb/s
Stream #0:0: Video: h264 (Constrained Baseline), yuv420p(progressive), 424x240, 420 kb/s, 24 fps, 24 tbr, 1k tbn, 48 tbc
Stream #0:1: Audio: aac (LC), 48000 Hz, stereo, fltp, 99 kb/s
Stream mapping:
Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
Stream #0:1 -> #0:1 (aac (native) -> aac (native))
Press [q] to stop, [?] for help
[libx264 @ 0x7ffce401ae00] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 0x7ffce401ae00] profile High, level 2.1
[libx264 @ 0x7ffce401ae00] 264 - core 155 r2917 0a84d98 - H.264/MPEG-4 AVC codec - Copyleft 2003-2018 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=7 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=24 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to '/Users/Private/out.mp4':
Metadata:
major_brand : qt
minor_version : 512
compatible_brands: qt
encoder : Lavf58.18.103
Stream #0:0: Video: h264 (libx264) (avc1 / 0x31637661), yuv420p(progressive), 424x240, q=-1--1, 24 fps, 12288 tbn, 24 tbc
Metadata:
encoder : Lavc58.31.101 libx264
Side data:
cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
Stream #0:1: Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s
Metadata:
encoder : Lavc58.31.101 aac
-
输入文件的基本信息:
Stream #0:0: Video: h264 (Constrained Baseline), yuv420p(progressive), 424x240, 420 kb/s, 24 fps, 24 tbr, 1k tbn, 48 tbc
Stream #0:1: Audio: aac (LC), 48000 Hz, stereo, fltp, 99 kb/s -
输出文件的基本信息:
Stream #0:0: Video: h264 (libx264) (avc1 / 0x31637661), yuv420p(progressive), 424x240, q=-1--1, 24 fps, 12288 tbn, 24 tbc
Stream #0:1: Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s
转码过程的time_base
输入封装层time_base
输入编码层time_base
后续补充。
输出编码层time_base
static int init_output_stream_encode(OutputStream *ost)
{
...
switch (enc_ctx->codec_type) {
case AVMEDIA_TYPE_AUDIO:
...
// 采样率
init_encoder_time_base(ost, av_make_q(1, enc_ctx->sample_rate));
break;
case AVMEDIA_TYPE_VIDEO:
// 输出帧率
init_encoder_time_base(ost, av_inv_q(ost->frame_rate));
...
}
输出封装层time_base
static int mov_init(AVFormatContext *s)
{
MOVMuxContext *mov = s->priv_data;
AVDictionaryEntry *global_tcr = av_dict_get(s->metadata, "timecode", NULL, 0);
int i, ret;
mov->fc = s;
/* Default mode == MP4 */
mov->mode = MODE_MP4;
...
for (i = 0; i < s->nb_streams; i++) {
AVStream *st= s->streams[i];
MOVTrack *track= &mov->tracks[i];
AVDictionaryEntry *lang = av_dict_get(st->metadata, "language", NULL,0);
if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
...
if (mov->video_track_timescale) {
track->timescale = mov->video_track_timescale;
} else {
track->timescale = st->time_base.den; // 转码时 这里是帧率
while(track->timescale < 10000) // 不到10000 则翻倍
track->timescale *= 2; // 按照这个逻辑 如果帧率为24 则结果为12288,如果帧率为25, 则结果为12800
}
...
}
else if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
track->timescale = st->codecpar->sample_rate; // 采样率
...
}
else if (st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE) {
track->timescale = st->time_base.den;
} else if (st->codecpar->codec_type == AVMEDIA_TYPE_DATA) {
track->timescale = st->time_base.den;
} else {
track->timescale = MOV_TIMESCALE;
}
...
}
网友评论