美文网首页
ffmpeg # 转码过程中的time_base

ffmpeg # 转码过程中的time_base

作者: FlyingPenguin | 来源:发表于2019-05-12 22:54 被阅读0次
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;
        }
...
}

相关文章

  • ffmpeg # 转码过程中的time_base

    输入文件和输出文件的信息: 输入文件的基本信息:Stream #0:0: Video: h264 (Constra...

  • 时间戳

    ffmpeg time_base详解[https://blog.csdn.net/peckjerry/articl...

  • spring-boot & ffmpeg 搭建一个音频转

    利用FFMPEG实现一个音频转码服务 提供一个音频转码服务,主要是利用ffmpeg实现转码,利用java web对...

  • ffmpeg # 各种封装格式的time_base

    封装层的time_base ffmpeg code TSmpegts.c中: mpegtsenc.c中 mp4mo...

  • golang 运行ffmpeg命令

    golang 运行ffmpeg命令 系统命令 ffmpeg转码 ffmpeg录音 录音设备名由命令获取 录音

  • ffmpeg编译支持nvidia-GPU解码

    编译ffmpeg 在对视频数据进行转码时,通常使用 FFmpeg 库[https://www.ffmpeg.org...

  • ffmpeg 转码

    ffmpeg 转码使用 下载地址:https://www.ffmpeg.org/download.html[htt...

  • FFmpeg转码

    1.分离视频音频流 ffmpeg -i input_file -vcodec copy -an output_fi...

  • FFmpeg转码

    1.分离视频音频流 2.视频解复用 3.视频转码 //-bf B帧数目控制,-g 关键帧间隔控制,-s 分辨率控制...

  • FFmpeg工具

    ffmpeg在做音视频编解码时非常方便,所以很多场景下转码使用的是ffmpeg,通过ffmpeg –-help可以...

网友评论

      本文标题:ffmpeg # 转码过程中的time_base

      本文链接:https://www.haomeiwen.com/subject/zydhaqtx.html