ubuntu平台使用ffmpeg视频处理

本文介绍了如何在Ubuntu16.04上安装FFmpeg,并提供了视频转GIF、MP4文件合并及处理h265视频aac音频的方法。通过FFmpeg的命令行工具,可以进行视频剪切、格式转换以及合并操作,同时展示了如何查看视频的详细信息。
摘要由CSDN通过智能技术生成
1 安装ffmpeg

(ubuntu 16.04)

sudo add-apt-repository ppa:kazam-team/unstable-series
sudo apt-get update && sudo apt-get install kazam
sudo apt-repository ppa:kirillshkrogalev/ffmpeg-next 
sudo apt-get update
sudo apt-get install ffmpeg
2 mp4视频转gif
ffmpeg -ss 2 -t 12 -i test.mp4 -s 649x320 -r 15 output1.gif

其中,-ss接起始秒数,-t接持续时长,-s接输出分辨率,-r接输出帧率

3 mp4文件合并

方法一:

ffmpeg -i 1.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb 1.ts
ffmpeg -i 2.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb 2.ts
ffmpeg -i "concat:1.ts|2.ts" -acodec copy -vcodec copy -absf aac_adtstoasc output.mp4

先把MP4转成ts再合并,其实也可以用以下方法,转化格式没太大必要:

方法二:

ffmpeg -f concat -safe 0 -i filenames.txt -c copy output.mp4

其中,filenames文件中写入要合并的视频名称,格式如:

file /home/Documents/001/cut1.v264
file /home/Documents/001/cut2.v264
file /home/Documents/001/cut3.v264

4 处理h265视频aac音频的文件

以剪切视频文件的操作为例:

ffmpeg -ss 2 -t 25 -i input.mp4 -strict -2 output.mp4

如果不加“-strict -2”就会报错:

[aac @ 0x8be6e0] The encoder ‘aac’ is experimental but experimental codecs are not enabled, add ‘-strict -2’ if you want to use it.

5 查看视频详细信息

使用ffprobe命令直接加文件名即可。也可以以json形式输出:

ffprobe -v quiet -print_format json -show_format -show_streams test.mp4

输出示例如下:

{
    "streams": [
        {
            "index": 0,
            "codec_name": "hevc",
            "codec_long_name": "HEVC (High Efficiency Video Coding)",
            "profile": "Main",
            "codec_type": "video",
            "codec_time_base": "1/15",
            "codec_tag_string": "hev1",
            "codec_tag": "0x31766568",
            "width": 2560,
            "height": 1440,
            "coded_width": 2560,
            "coded_height": 1440,
            "has_b_frames": 0,
            "sample_aspect_ratio": "0:1",
            "display_aspect_ratio": "0:1",
            "pix_fmt": "yuvj420p",
            "level": 150,
            "color_range": "pc",
            "color_space": "bt709",
            "color_transfer": "bt709",
            "color_primaries": "bt709",
            "refs": 1,
            "r_frame_rate": "15/1",
            "avg_frame_rate": "167680000/11178223",
            "time_base": "1/90000",
            "start_pts": 0,
            "start_time": "0.000000",
            "duration_ts": 100604007,
            "duration": "1117.822300",
            "bit_rate": "1747605",
            "nb_frames": "16768",
            "disposition": {
                "default": 1,
                "dub": 0,
                "original": 0,
                "comment": 0,
                "lyrics": 0,
                "karaoke": 0,
                "forced": 0,
                "hearing_impaired": 0,
                "visual_impaired": 0,
                "clean_effects": 0,
                "attached_pic": 0
            },
            "tags": {
                "creation_time": "2021-03-25 13:19:00",
                "language": "und",
                "handler_name": "VideoHandler"
            }
        },
        {
            "index": 1,
            "codec_name": "pcm_alaw",
            "codec_long_name": "PCM A-law / G.711 A-law",
            "codec_type": "audio",
            "codec_time_base": "1/8000",
            "codec_tag_string": "alaw",
            "codec_tag": "0x77616c61",
            "sample_fmt": "s16",
            "sample_rate": "8000",
            "channels": 1,
            "bits_per_sample": 8,
            "r_frame_rate": "0/0",
            "avg_frame_rate": "0/0",
            "time_base": "1/90000",
            "start_pts": 5670,
            "start_time": "0.063000",
            "duration_ts": 100597396,
            "duration": "1117.748844",
            "bit_rate": "64004",
            "nb_frames": "8733",
            "disposition": {
                "default": 1,
                "dub": 0,
                "original": 0,
                "comment": 0,
                "lyrics": 0,
                "karaoke": 0,
                "forced": 0,
                "hearing_impaired": 0,
                "visual_impaired": 0,
                "clean_effects": 0,
                "attached_pic": 0
            },
            "tags": {
                "creation_time": "2021-03-25 13:19:00",
                "language": "und",
                "handler_name": "AudioHandler"
            }
        }
    ],
    "format": {
        "filename": "test.mp4",
        "nb_streams": 2,
        "nb_programs": 0,
        "format_name": "mov,mp4,m4a,3gp,3g2,mj2",
        "format_long_name": "QuickTime / MOV",
        "start_time": "0.000000",
        "duration": "1117.822000",
        "size": "268435456",
        "bit_rate": "1921132",
        "probe_score": 100,
        "tags": {
            "major_brand": "isom",
            "minor_version": "512",
            "compatible_brands": "isomiso2mp41",
            "creation_time": "2021-03-25 13:19:00"
        }
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

寒墨阁

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值