FFmpeg 简单实现转码

Android集成FFmpeg并实现视频转码 1.配置环境 再Android Studio中新建工程,选择Native C++ 在工程的\app\src\main\cpp\目录下新建ffmpeg目录,将编译好的.so文件和头文件拷贝到此目录,还需要将FFmpeg源码根目录下的config.h和以下文件拷贝到此目录: fftools\cmdutils.c fftools\cmdutils.h fftools\ffmpeg.c fftools\... 阅读详情

首发地址,会更错

本文汇总前面几篇文章,把所有流程合并到一块,简单实现转码的流程。其中有些异常不做处理。

转码原理

先看雷神的一张图:

上图描述的很明白,上完图发现已经不需要语言描述了[Dog]。 但还是画个来说明一下这块之间的联系:

其中,AVFormatContext、AVPacket等重要的结构体请看:FFmpeg重要结构体(转自雷神) 。

代码实现

/**
 * @author 秦城季
 * @email xhunmon@126.com
 * @Blog https://qincji.gitee.io
 * @date 2021/01/08
 * description: 转码
 * 主要思路:
 * 格式1-->解封装--[解封装数据AVPacket]-->解码--[原始数据AVFrame]-->编码-->[编码后数据AVPacket]-->封装-->格式2
 *
 * 2021/01/11 增加音频重采样变换
 * <br>
 */
#include <stdint.h>
#include <stdio.h>

extern "C" {
#include <libavformat/avformat.h>
#include <libavcodec/avcodec.h>

#include <libavutil/channel_layout.h>
#include <libavutil/common.h>
#include <libavutil/frame.h>
#include <libavutil/samplefmt.h>

#include <libavutil/opt.h>
#include <libavutil/imgutils.h>
#include <libswresample/swresample.h>
}

int main(int argc, char **argv) {
//    const char *in_filename = "source/lol.mp4";
//    const char *out_filename = "output/lol.wma";
//    const char *in_filename = "source/Kobe.flv";
//    const char *out_filename = "output/Kobe.avi";
//    const char *in_filename = "source/lol.mp4";
//    const char *out_filename = "output/lol.avi";
    const char *in_filename = "source/Kobe.flv";
    const char *out_filename = "output/Kobe2.avi";
    remove(out_filename);

    SwrContext *swr_ctx;//当有需要时,需要重采样
    AVFormatContext *ifmt_ctx = NULL, *ofmt_ctx = NULL;
    AVPacket *ipkt = NULL, *opkt = NULL;
    AVFrame *iframe = NULL, *oframe_a = NULL;
    AVCodecContext *ic_v = NULL, *ic_a = NULL, *oc_v = NULL, *oc_a = NULL;
    AVCodec *ocodec_v = NULL, *ocodec_a = NULL;
    int iindex_v = -1, iindex_a = -1, oindex_v = -1, oindex_a = -1, ret, dst_nb_samples;

    ipkt = av_packet_alloc();
    opkt = av_packet_alloc();

    /**(解封装 1.1):创建并初始化AVFormatContext*/
    if (avformat_open_input(&ifmt_ctx, in_filename, NULL, NULL) < 0) {
        fprintf(stderr, "Could not open source file %s\n", in_filename);
        goto end;
    }
    /**(解封装 1.2):检索流信息,这个过程会检查输入流中信息是否存在异常*/
    if (avformat_find_stream_info(ifmt_ctx, NULL) < 0) {
        fprintf(stderr, "Could not find stream information\n");
        goto end;
    }
    /**(解封装 1.3):查找视频和音频的下标*/
    if ((iindex_v = av_find_best_stream(ifmt_ctx, AVMEDIA_TYPE_VIDEO, -1, -1, NULL, 0)) < 0) {
        fprintf(stderr, "Could not find video stream\n");
        goto end;
    }
    if ((iindex_a = av_find_best_stream(ifmt_ctx, AVMEDIA_TYPE_AUDIO, -1, -1, NULL, 0)) < 0) {
        fprintf(stderr, "Could not find video stream\n");
        goto end;
    }

    /**(解码 2.1):解码器直接从AVFormatContext对象的流中获取,然后指定该解码器的AVCodec*/
    ic_v = ifmt_ctx->streams[iindex_v]->codec;
    if (!(ic_v->codec = avcodec_find_decoder(ic_v->codec_id))) {
        fprintf(stderr, "Could find in video AVCodec\n");
        goto end;
    }
    ic_a = ifmt_ctx->streams[iindex_a]->codec;
    if (!(ic_a->codec = avcodec_find_decoder(ic_a->codec_id))) {
        fprintf(stderr, "Could find in audio AVCodec\n");
        goto end;
    }
    /**(解码 2.2):初始化码器器上下文*/
    if (avcodec_open2(ic_v, ic_v->codec, NULL) < 0) {
        fprintf(stderr, "Could not open codec v\n");
        goto end;
    }
    if (avcodec_open2(ic_a, ic_a->codec, NULL) < 0) {
        fprintf(stderr, "Could not open codec a\n");
        goto end;
    }

    /**(封装 4.1):根据文件格式初始化封装器上下文AVFormatContext*/
    avformat_alloc_output_context2(&ofmt_ctx, NULL, NULL, out_filename);
    if (!ofmt_ctx) {
        fprintf(stderr, "Could not create output context\n");
        goto end;
    }

    /**(封装 4.2):创建输入的视频和音频AVCodec*/
    if (!(ocodec_v = avcodec_find_encoder(ofmt_ctx->oformat->video_codec))) {
        fprintf(stderr, "Could find out video AVCodec\n");
        goto end;
    }
    if (!(ocodec_a = avcodec_find_encoder(ofmt_ctx->oformat->audio_codec))) {
        fprintf(stderr, "Could find out audio AVCodec\n");
        goto end;
    }

    /**(封装 4.3):创建输出视频和音频AVStream,并与关联上AVFormatContext。(编码 3.1):创建我们所需的编码器*/
    for (int i = 0; i < ifmt_ctx->nb_streams; i++) {
        if (i != iindex_v && i != iindex_a) {
            continue;
        }
        AVStream *out_stream = avformat_new_stream(ofmt_ctx, NULL);
        if (!out_stream) {
            fprintf(stderr, "Failed allocating output stream\n");
            goto end;
        }

        out_stream->codecpar->codec_tag = 0;

        /*********************************************************************************************/
        /**   这一块是编码器的参数信息设置,ffmpeg生产的默认编码器信息可能不是我们想要的,需要根据具体情况进行设置    **/
        /*********************************************************************************************/
        if (i == iindex_v) {
            oindex_v = out_stream->index;
//            oc_v = ofmt_ctx->streams[oindex_v]->codec; //这是旧版的写法
            if (!(oc_v = avcodec_alloc_context3(ocodec_v))) {
                fprintf(stderr, "Could not allow out AVCodecContext v\n");
                goto end;
            }
            oc_v->height = ic_v->height;
            oc_v->width = ic_v->width;
            oc_v->sample_aspect_ratio = ic_v->sample_aspect_ratio;
            oc_v->pix_fmt = ocodec_v->pix_fmts[0];
            oc_v->time_base = ic_v->time_base;
            oc_v->has_b_frames = ic_v->has_b_frames;
            //输出将相对于输入延迟max_b_frames + 1-->但是输入的为0!
//            oc_v->max_b_frames = ic_v->max_b_frames + 1;
            oc_v->max_b_frames = 2;
            oc_v->bit_rate = ic_v->bit_rate;
            oc_v->codec_type = ic_v->codec_type;
            if ((ret = avcodec_parameters_from_context(out_stream->codecpar, oc_v)) < 0) {
                fprintf(stderr, "Could not copy the out stream parameters v\n");
                goto end;
            }

            if (avcodec_open2(oc_v, ocodec_v, NULL) < 0) {
                fprintf(stderr, "Could not open out codec v\n");
                goto end;
            }
        } else if (i == iindex_a) {
            oindex_a = out_stream->index;
//            oc_a = ofmt_ctx->streams[oindex_a]->codec;
            if (!(oc_a = avcodec_alloc_context3(ocodec_a))) {
                fprintf(stderr, "Could not allow out AVCodecContext v\n");
                goto end;
            }
            oc_a->sample_rate = ic_a->sample_rate;
            oc_a->channel_layout = ic_a->channel_layout;
            oc_a->channels = av_get_channel_layout_nb_channels(ic_a->channel_layout);
            oc_a->sample_fmt = ocodec_a->sample_fmts[0];
            oc_a->time_base = {1, ic_a->sample_rate};
            oc_a->bit_rate = ic_a->bit_rate;
            oc_a->codec_type = ic_a->codec_type;

            if ((ret = avcodec_parameters_from_context(out_stream->codecpar, oc_a)) < 0) {
                fprintf(stderr, "Could not copy the out stream parameters a\n");
                goto end;
            }

            if (avcodec_open2(oc_a, ocodec_a, NULL) < 0) {
                fprintf(stderr, "Could not open out codec a\n");
                goto end;
            }
        }
    }

    /**(封装 4.4):初始化AVIOContext*/
    /* open the output file, if needed */
    if (!(ofmt_ctx->oformat->flags & AVFMT_NOFILE)) {
        if (avio_open(&ofmt_ctx->pb, out_filename, AVIO_FLAG_WRITE)) {
            fprintf(stderr, "Could not open '%s': %s\n", out_filename,
                    av_err2str(ret));
            goto end;
        }
    }

    /**(重采样 5.1):申请内存*/
    if (!(swr_ctx = swr_alloc())) {
        fprintf(stderr, "Could not allocate resampler context\n");
        goto end;
    }

    /**(重采样 5.2):设置参数*/
    av_opt_set_int(swr_ctx, "in_channel_count", ic_a->channels, 0);
    av_opt_set_int(swr_ctx, "in_sample_rate", ic_a->sample_rate, 0);
    av_opt_set_sample_fmt(swr_ctx, "in_sample_fmt", ic_a->sample_fmt, 0);
    av_opt_set_int(swr_ctx, "out_channel_count", oc_a->channels, 0);
    av_opt_set_int(swr_ctx, "out_sample_rate", oc_a->sample_rate, 0);
    av_opt_set_sample_fmt(swr_ctx, "out_sample_fmt", oc_a->sample_fmt, 0);

    /**(重采样 5.3):初始化SwrContext*/
    if ((ret = swr_init(swr_ctx)) < 0) {
        fprintf(stderr, "Failed to initialize the resampling context\n");
        goto end;
    }

    /**(封装 4.5):写入文件头*/
    if ((ret = avformat_write_header(ofmt_ctx, NULL)) < 0) {
        fprintf(stderr, "Error occurred when opening output file: %s\n",
                av_err2str(ret));
        goto end;
    }

    /**(解封装 1.4):读取到AVPacket中*/
    while (av_read_frame(ifmt_ctx, ipkt) >= 0) {
        if (!iframe) {
            if (!(iframe = av_frame_alloc())) {
                fprintf(stderr, "Could not allocate iframe\n");
                goto end;
            }
        }
        if (!oframe_a) {
            if (!(oframe_a = av_frame_alloc())) {
                fprintf(stderr, "Could not allocate oframe_a\n");
                goto end;
            }
            oframe_a->format = oc_a->sample_fmt;
            oframe_a->channel_layout = oc_a->channel_layout;
            oframe_a->sample_rate = oc_a->sample_rate;
            oframe_a->nb_samples = oc_a->frame_size;

            if (oframe_a->nb_samples) {
                ret = av_frame_get_buffer(oframe_a, 0);
                if (ret < 0) {
                    fprintf(stderr, "Error allocating an oframe_a buffer\n");
                    goto end;
                }
            }
        }

        AVCodecContext *ic_temp, *oc_temp;
        AVStream *in_stream, *out_stream;
        int oindex_temp = -1;
        if (ipkt->stream_index == iindex_v) {
            ic_temp = ic_v;
            oc_temp = oc_v;
            oindex_temp = oindex_v;
        } else if (ipkt->stream_index == iindex_a) {
            ic_temp = ic_a;
            oc_temp = oc_a;
            oindex_temp = oindex_a;
        } else {
            fprintf(stderr, "has other streams?\n");
            continue;
        }

        in_stream  = ifmt_ctx->streams[ipkt->stream_index];
        out_stream = ofmt_ctx->streams[oindex_temp];

        /**(解码 2.3):将得到的AVPacket送去解码器*/
        ret = avcodec_send_packet(ic_temp, ipkt);
        if (ret < 0) {
            fprintf(stderr, "Error submitting the packet to the decoder\n");
            goto end;
        }

        /* read all the output frames (in general there may be any number of them */
        while (ret >= 0) {
            //接到解码后的<AVPacket数据>,读取到AVFrame中
            /**(解码 2.4):从解码器中得到的数据到AVFrame*/
            ret = avcodec_receive_frame(ic_temp, iframe);
            if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) {
                break;
            } else if (ret < 0) {
                fprintf(stderr, "Error during decoding\n");
                goto end;
            }

            /**(编码 3.2):将裸数据AVFrame送去编码器*/
            //报错:more samples than iframe size (avcodec_encode_audio2) 的解决方案; 参考官方例子:transcoding.c/* 这种情况需要重采样 */
            if (ipkt->stream_index == iindex_a && iframe->nb_samples != oc_temp->frame_size) {
                oframe_a->nb_samples = oc_temp->frame_size;
//                dst_nb_samples = av_rescale_rnd(swr_get_delay(swr_ctx, ic_a->sample_rate) +
//                                                        ic_a->frame_size, oc_a->sample_rate, ic_a->sample_rate, AV_ROUND_UP);
                /**(重采样 5.4):重新采样*/
                ret = swr_convert(swr_ctx, oframe_a->data, oc_a->frame_size, (const uint8_t **) iframe->data,
                                  ic_a->frame_size);
                if (ret < 0) {
                    fprintf(stderr, "Error while converting\n");
                    goto end;
                }
                ret = avcodec_send_frame(oc_temp, oframe_a);
            } else {
                ret = avcodec_send_frame(oc_temp, iframe);
            }
            if (ret < 0) {
                fprintf(stderr, "Error sending the iframe to the encoder\n");
                goto end;
            }

            /* read all the available output packets (in general there may be any
             * number of them */
            while (ret >= 0) {
                /**(编码 3.3):从编码器中得到编码后数据,放入AVPacket中*/
                ret = avcodec_receive_packet(oc_temp, opkt);
                if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)
                    break;
                else if (ret < 0) {
                    fprintf(stderr, "Error encoding iframe\n");
                    goto end;
                }

                //设置pts等信息---> 从输入的信息转换成输出的信息;参考官方例子:doc/examples/remuxing.c
                opkt->stream_index = oindex_temp;
                opkt->pts = av_rescale_q_rnd(ipkt->pts, in_stream->time_base, out_stream->time_base, (AVRounding)(AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX));
                opkt->dts = av_rescale_q_rnd(ipkt->dts, in_stream->time_base, out_stream->time_base, (AVRounding)(AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX));
                opkt->duration = av_rescale_q(ipkt->duration, in_stream->time_base, out_stream->time_base);
                opkt->pos = -1;

//                printf("in Read    1 Packet. size:%5d\tstream_index:% d\tdts:%lld\tpts:%lld\tduration:%lld\tcur_dts:%lld\n",
//                       ipkt->size, ipkt->stream_index, ipkt->dts, ipkt->pts, ipkt->duration,
//                       ofmt_ctx->streams[oindex_temp]->cur_dts);
                printf("out Write  1 Packet. size:%5d\tstream_index:% d\tdts:%lld\tpts:%lld\tduration:%lld\tcur_dts:%lld\n",
                       opkt->size, opkt->stream_index, opkt->dts, opkt->pts, opkt->duration,
                       ofmt_ctx->streams[oindex_temp]->cur_dts);
                /**(封装 4.6):写入数据*/
                if (av_interleaved_write_frame(ofmt_ctx, opkt) < 0) {
                    fprintf(stderr, "Error muxing packet\n");
                    goto end;
                }

                av_packet_unref(opkt);
            }
        }

        av_packet_unref(ipkt);
    }

    //刷新缓存
    avcodec_send_packet(ic_v, NULL);
    avcodec_send_packet(ic_a, NULL);
    avcodec_send_frame(oc_v, NULL);
    avcodec_send_frame(oc_a, NULL);

    /**(封装 4.7):写入文件尾*/
    av_write_trailer(ofmt_ctx);
    printf("finish.\n");
    end:
    av_frame_free(&iframe);
    av_frame_free(&oframe_a);
    av_packet_free(&ipkt);
    avformat_close_input(&ifmt_ctx);
    avformat_close_input(&ofmt_ctx);
    return 0;
}

参考

  • https://blog.youkuaiyun.com/leixiaohua1020/article/details/26838535


FFmpeg转码 业务功能为了适应安卓平台对语音以及视频的正常播放,故所以使用FFmpeg对音频以及视频的转码。 刚开始知道到这个技能点的时候我也是一脸茫然,百度搜索一波也是各种使用命令行的讲解。 每个人编码的方式都有自定义的风格,故小编将搜刮回来的信息总结归纳了一下 当然也是亲测有效的,方可直接套用。 FFmpeg概念小编在这里就不描述了,有兴趣的小码 阅读详情

相关推荐

ffmpeg转码视频

转码和编辑视频FFmpeg是一套可以用来记录、转换数字音频、视频,并能将其转化为流的开源计算机程序。采用LGPL或GPL许可证。它提供了录制、转换以及流化音视频的完整解决方案。它包含了非常先进的音频/视频编解码库libavcodec,为了保证高可移植性和编解码质量,libavcodec里很多code都是从头开发的。FFmpeg在Linux平台下开发,但它同样也可以在其它操作系统环境中编译运行,包括Windows、Mac OS X等。

yinshipin007的博客 4955

ffmpeg中AVFrame\AVPacket与自己的数据交互

在使用ffmpeg的过程中有时候我们自己的数据结构比如yuv数据或者压缩后的H264数据想要转为ffmpeg中的AVFrame或者AVPacket结构体,怎么转呢? 这个在ffmpg的libavcodec的v4l2_buffers.h/.c中有非常好的案例。

weixin_43360707的博客 1098

ffmpeg视频转码记录

前言 关于ffmpeg的详细参数介绍可见: 【Python】ffmpeg模块处理视频、音频信息 但是说实话,一般人用不到这么复杂的自定义设置,除非有专业需求。 在写这篇博客之前,我看了这个视频 ffmpeg常用命令_bilibili (注:以上两个视频你们可以不用看,直接看我教程即可. 需求: mac上录制的视频是.mov, 但是实际上mp4会更通用些(并且体积会更小),所以我们就想着能不能用开源工具转一下。(开源相比于现成软件而言,不用交钱,二是某些在线转换工具可能会有泄露视频的风险) 前期准备 需要安

andy dennis的博客 1110

C#学习系列之image控件配合ffmpeg播放视频(bitmap转image)

bitmap转image

arriettyandray的博客 1492

【FFmpeg】AVPacket的使用详解

1、AVPacket简介 AVPacket是存储压缩编码数据相关信息的结构体,内部有压缩数据。它通常由解码器导出,或者作为输入传递给解码器,或者传递给muxers。 对于视频,它通常应该包含一个压缩帧。对于音频,它可能包含几个压缩帧。 重要的变量有以下几个: AVBufferRef *buf; 参考计数 uint8_t *data: 压缩编码后的数据。 例如对于H.264来说。1个AVPacket的data通常对应一个NAL。 注意:在这里只是对应,而不是一模一样。他们之间有微小的差别:使用FFMPE

郭老二 3691

SpringBoot 实现大文件视频转码(转码基于FFMPEG实现)

最近项目需要将用户上传的视频如果不是MP4格式,需要全部转码为MP4格式的,这里我通过FFMPeg进行大文件视频转码的实现。 1、安装FFMPeg 首先我们需要在机器上安装FFMPeg用于我们的视频转码,传送门如下: Centos7 安装FFMPEG Ubuntu 安装FFMPEG及简单使用 2、视频转码实现 package com.openailab.oascloud.file.c...

专注基础架构领域 1万+

AVPacket

AVPacket是存储压缩编码数据相关信息的结构 AVPacket是FFmpeg中很重要的一个数据结构,它保存了解复用之后,解码之前的数据(仍然是压缩后的数据)和关于这些数据的一些附加信息,如显示时间戳(pts)、解码时间戳(dts)、数据时长,所在媒体流的索引等。对于视频来说,AVPacket通常包含一个压缩的Frame,而音频(Audio)则有可能包含多个压缩的Frame。并且,一个Packet有可能是空的,不包含任何压缩数据,只含有side data(side data,容器提供的关于Packet的

weixin_42123332的博客 2207

FFmpeg转码流程详解

FFmpeg是一个非常强大的开源多媒体框架,它支持几乎所有的视频和音频格式,并且能够实现转码、录制、转流、以及播放等功能。容器格式的转换,比如MP4转换为MOV容器中音视频数据编码方式转换,比如H264编码转换成MPEG4编码,MP3换为AAC音视频码率的转换,比如4M的视频码率降为2M视频分辨率的转换,比如1080P视频变为720P,音频重采样等等。

程序猿老樊的博客 4589

最简单的基于FFMPEG的转码程序

本文介绍一个简单的基于FFmpeg的转码器。转码器在视音频编解码处理的程序中,属于一个比较复杂的东西。因为它结合了视频的解码和编码。一个视频播放器,一般只包含解码功能;一个视频编码工具,一般只包含编码功能;而一个视频转码器,则需要先对视频进行解码,然后再对视频进行编码,因而相当于解码器和编码器的结合。下图例举了一个视频的转码流程。输入视频的封装格式是FLV,视频编码标准是H.264,音频编码标准是

雷霄骅(leixiaohua1020)的专栏 9万+

linux下配置ffmpeg(支持x264编码)

在网上找了好多配置ffmpeg的教程,大多操作复杂。 我写了一个脚本,给它执行权限了(chmod +x install_ffmpeg.sh),一键式安装ffmpeg环境,配置了x264编码库,希望有人用得到。

保姆级教程:用STM32CubeMX HAL库搞定ESP8266连接,附串口printf调试全流程

本文提供了一份详细的STM32CubeMX HAL库教程,指导开发者如何实现ESP8266无线模块的连接与调试。从开发环境搭建、串口配置到AT指令通信解析,涵盖了物联网开发中的关键步骤和常见问题解决方案,帮助开发者快速掌握STM32与ESP8266的集成技术。

weixin_28273593的博客 504

ffmpeg转码cpu很高,ffmpeg实现GPU(硬编码)加速转码,解决ffmpeg转码速度慢

ffmpeg实现GPU(硬编码)加速转码 # 项目场景: 提示:ubuntu16将视频流(监控流)数据转码,使用GPU实现加速转码: 例如:将一个路径中的h264视频流数据转换到另一个路径中 准备工作 确定服务器有GPU lspci | grep NVIDIA # 查看NVIDIA显卡 ubuntu-drivers devices 先在$HOME目录下创建目录(文件夹) 1、依赖库安装: nasm 汇编编译器,编译某些依赖库的时候需要 cd ~/ffmpeg_sources curl -O

QQ小冰的博客 3万+

OpenCV中SGBM中BT代价计算

这里写自定义目录标题欢迎使用Markdown编辑器新的改变功能快捷键合理的创建标题,有助于目录的生成如何改变文本的样式插入链接与图片如何插入一段漂亮的代码片生成一个适合你的列表创建一个表格设定内容居中、居左、居右SmartyPants创建一个自定义列表如何创建一个注脚注释也是必不可少的KaTeX数学公式新的甘特图功能,丰富你的文章UML 图表FLowchart流程图导出与导入导出导入 欢迎使用Markdown编辑器 你好! 这是你第一次使用 Markdown编辑器 所展示的欢迎页。如果你想学习如何使用Mar

qq_27606639的博客 5976

ffmpeg教程及加速视频转码

ffmpeg加速视频转码

生而无畏,战至终章 2393

手把手教你获取全国街道级GeoJSON数据:前端地图开发必备技巧

本文详细介绍了获取全国街道级GeoJSON数据的多种方法,从前端地图开发的实际需求出发,涵盖了免费获取省市县级数据的工具如阿里云DataV.GeoAtlas和HashTang,以及进阶的街道级数据获取方案,包括使用Bigemap GIS Office和专业数据采购。文章还提供了数据处理与优化技巧,帮助开发者高效使用GeoJSON数据进行地图可视化。

weixin_29053383的博客 289

华为交换机与思科/华三设备LACP对接实战:手把手教你配置链路聚合

本文详细解析了华为交换机与思科、华三设备间的LACP链路聚合配置实战,涵盖核心原理、配置步骤及排错技巧。通过对比不同厂商的实现差异,提供可落地的跨厂商对接方案,助力企业网络工程师高效部署高可靠性链路聚合。

weixin_30836759的博客 422

linux下的java调用ffmpeg进行视频转码

linux下的java调用ffmpeg进行视频转码 上一篇文章介绍了如何在linux下安装ffmpeg,在安装完ffmpeg之后,遇到的问题就是如何在java中调用linux的ffmpeg命令进行视频转码和截图,话不多说,直接上代码! 这是视频上传转码的方法 public String uploadVideo() { User user = (User) session.get

wmt1432的博客 8894

Qt界面编程(三)—— 父子关系、对象树、信号和槽(自定义信号和槽、Qt5与Qt4的写法)

Qt框架默认提供的标准信号和槽不足以完成我们日常应用开发的需求,比如说点击某个按钮让另一个按钮的文字改变,这时候标准信号和槽就没有提供这样的函数。但是Qt信号和槽机制提供了允许我们自己设计自己的信号和槽。声明在类的signals域下没有返回值,void类型的函数只有函数声明,没有定义可以有参数,可以重载通过emit关键字来触发信号,形式:emit object->sig(参数);

此心光明事上练的博客 1695

FFMPEG 使用显卡加速转码

FFMPEG 使用显卡加速转码 前言 视频转码时如果遇见视频比较大、时长很长的时候,转码压制需要等待很久且及占用cpu,所以就在想有没有什么办法可以加速转码进度呢 ,故本篇文章记录FFMPEG如何调用显卡对转换编码格式或者压制进行加速。 软硬编解码的区分: 软编码:使用CPU进行编码 硬编码:使用非CPU进行编码,如显卡GPU、专用的DSP、FPGA、ASIC芯片等 软硬编解码的区别: 软编码:实现直接、简单,参数调整方便,升级易,但CPU负载重,性能较硬编码低,低码率下质量通常比硬编码要好一点。

蜀道难,难于上青天。 1万+

滴滴数据分析80道面试题及参考答案

常见的模型评价指标有准确率、召回率、F1 值、均方误差、均方根误差、R 方等。准确率是指模型预测正确的样本数占总样本数的比例,它反映了模型预测的准确性。召回率是指模型预测为正例的样本中实际为正例的比例,它衡量了模型对正例的捕捉能力。F1 值是准确率和召回率的调和平均数,综合考虑了两者的平衡。均方误差是预测值与真实值之差的平方的平均值,它衡量了模型预测值与真实值的平均偏离程度。均方根误差是均方误差的平方根,与均方误差类似,但更直观地反映了误差的大小。

大模型大数据攻城狮的专栏 1697

Python爬虫教程:抓取地方政府网站的公开文件与政策信息

Web爬虫是指一种自动化脚本,用于模拟人类浏览器访问网页、提取网页内容的数据抓取工具。发送请求到目标网页;获取网页内容;解析网页内容,提取所需数据;将数据保存或进一步处理。爬虫可以抓取各种形式的数据,如文本、图片、文件等。本教程将重点展示如何抓取地方政府网站上公开的政策文件、公告等信息。许多政府网站都会采取一定的反爬虫措施,防止大量数据被爬取。IP封锁:如果短时间内大量请求来自同一IP,可能会被封锁。验证码:一些网站会使用验证码来验证访问者是否为机器人。动态加载。

2201_76125261的博客 1981

java ffmpeg 转码

转: Java 视频转码(转为MPEG-4格式) 1、引入相关依赖 2、视频转码工具类 二、使用ffmpeg工具转码 参考:java+ffmpeg实现mp4转m3u8切片(ts)在实际开发中,可以通过调用命令,使用ffmpeg进行切片操作

qq_30436011的博客 4681

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

获取ffmpeg转码的实时进度

本文记录查看 ffmpeg 进行转码时的实时进度。使用FFmpeg4.3.1的SDK官方开发包编译ffmpeg.c。

明天你好的博客 4231

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

上一篇: FFmpeg Encode(编码)
下一篇: 重磅音视频开发资料库!!!
秦城季
博客等级 码龄10年 46粉丝 38原创
评论 3
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值