huihui 5 vuotta sitten
vanhempi
commit
518e7730f1

+ 52 - 0
source/OtherDemo/其他API简单例子/遍历支持的解码器.txt

@@ -0,0 +1,52 @@
+
+下面简单介绍一下遍历ffmpeg中的解码器信息的方法(这些解码器以一个链表的形式存储):
+1.注册所有编解码器:av_register_all();
+
+2.声明一个AVCodec类型的指针,比如说AVCodec* p;
+
+3.调用av_codec_next()函数,即可获得指向链表下一个解码器的指针,循环往复可以获得所有解码器的信息。注意,如果想要获得指向第一个解码器的指针,则需要将该函数的参数设置为NULL。
+
+/**
+* If c is NULL, returns the first registered codec,
+* if c is non-NULL, returns the next registered codec after c,
+* or NULL if c is the last one.
+*/
+
+int getSupportCodecs(void)
+{
+    char *info = (char *)malloc(40000);
+    memset(info, 0, 40000);
+
+    av_register_all();
+
+    AVCodec *c_temp = av_codec_next(NULL);
+
+    while (c_temp != NULL)
+    {
+        if (c_temp->decode != NULL)
+        {
+            strcat(info, "[Decode]");
+        }
+        else
+        {
+            strcat(info, "[Encode]");
+        }
+        switch (c_temp->type)
+        {
+        case AVMEDIA_TYPE_VIDEO:
+            strcat(info, "[Video]");
+            break;
+        case AVMEDIA_TYPE_AUDIO:
+            strcat(info, "[Audeo]");
+            break;
+        default:
+            strcat(info, "[Other]");
+            break;
+        }
+        sprintf(info, "%s %10s\n", info, c_temp->name);
+        c_temp = c_temp->next;
+    }
+    fprintf(stderr, "%s %s\n", __FUNCTION__, info);
+    free(info);
+    return 0;
+}

+ 73 - 0
source/OtherDemo/其他API简单例子/遍历设备列表.txt

@@ -0,0 +1,73 @@
+
+extern "C"
+{
+#include "libavcodec/avcodec.h"
+#include "libavformat/avformat.h"
+#include "libswscale/swscale.h"
+#include "libavdevice/avdevice.h"
+}
+
+//'1' Use Dshow
+//'0' Use VFW
+#define USE_DSHOW 0
+
+//Show Dshow Device
+void show_dshow_device()
+{
+    AVFormatContext *pFormatCtx = avformat_alloc_context();
+    AVDictionary* options = nullptr;
+    av_dict_set(&options,"list_devices","true",0);
+    AVInputFormat *iformat = av_find_input_format("dshow");
+    printf("========Device Info=============\n");
+    avformat_open_input(&pFormatCtx,"video=dummy",iformat,&options);
+    printf("================================\n");
+}
+
+//Show Dshow Device Option
+void show_dshow_device_option()
+{
+    AVFormatContext *pFormatCtx = avformat_alloc_context();
+    AVDictionary* options = nullptr;
+    av_dict_set(&options,"list_options","true",0);
+    AVInputFormat *iformat = av_find_input_format("dshow");
+    printf("========Device Option Info======\n");
+    avformat_open_input(&pFormatCtx,"video=Integrated Camera",iformat,&options);
+    printf("================================\n");
+}
+
+//Show VFW Device
+void show_vfw_device()
+{
+    AVFormatContext *pFormatCtx = avformat_alloc_context();
+    AVInputFormat *iformat = av_find_input_format("vfwcap");
+    printf("========VFW Device Info======\n");
+    avformat_open_input(&pFormatCtx,"list",iformat,nullptr);
+    printf("=============================\n");
+}
+
+//Show AVFoundation Device
+void show_avfoundation_device()
+{
+    AVFormatContext *pFormatCtx = avformat_alloc_context();
+
+    AVDictionary* options = nullptr;
+    av_dict_set(&options,"list_devices","true",0);
+    AVInputFormat *iformat = av_find_input_format("avfoundation");
+    printf("==AVFoundation Device Info===\n");
+    avformat_open_input(&pFormatCtx, "",iformat, &options);
+    printf("=============================\n");
+}
+
+void getDeviceList()
+{
+    av_register_all();
+    avformat_network_init();
+    avdevice_register_all();
+	
+	    //Show Dshow Device
+    show_dshow_device();
+    //Show Device Options
+    show_dshow_device_option();
+    //Show VFW Options
+    show_vfw_device();
+}

BIN
source/OtherDemo/常用命令/FFMPEG命令.doc


+ 2 - 0
source/OtherDemo/常用命令/ffmpeg转码切片m3u8.txt

@@ -0,0 +1,2 @@
+./ffmpeg -i a.3gpp -ac 2 -ar 44100 -ab 32 a.aac
+./ffmpeg -i a.aac -codec copy -map 0 -f segment -segment_list audio/playlist.m3u8 -segment_list_flags +live -segment_time 10 audio/out%03d.aac

+ 37 - 0
source/OtherDemo/常用命令/功能介绍.txt

@@ -0,0 +1,37 @@
+fmpeg作为Linux下的LGPL开源程序,在Windows下编译需要特殊的工具。我这里提供的版本,使用MinGW编译,只有一个可执行文件,可直接运行(命令行程序)。
+FLV向其它格式(avi(mpeg4)、asf、mpeg)转换的简易方法:(圆括号内必填,方括号内可选)
+转换成wmv/asf
+ffmpeg -i (要转换的flv文件完整路径) -f asf -vcodec (wmv1或wmv2) [-b 视频码率] -acodec mp3 [-ab 音频码率] (输出的asf/wmv文件完整路径)
+转换成mpeg1
+ffmpeg -i (要转换的flv文件完整路径) -f mpeg -vcodec mpeg1video [-b 视频码率] -acodec mp2 [-ab 音频码率] (输出的mpg文件完整路径)
+转换成avi(msmpeg4)
+ffmpeg -i (要转换的flv文件完整路径) -f avi -vcodec (msmpeg4或msmpeg4v1或msmpeg4v2) [-b 视频码率] -acodec mp3 [-ab 音频码率] (输出的avi文件完整路径)
+
+ffmeg的7个技巧:
+1 音频转换
+ffmpeg -i my_audio.wav my_audio.mp3-i 后为要转换的音频文件,my_audio.mp3为目的音频文件
+2 视频转换
+ffmpeg -i my_video.mpeg -s 500×500 my_video.flv-i 后为源视频文件, -s 表示设置目标视频文件的分辨率 my_video.flv为目的视频文件
+3 从视频中截取图片
+ffmpeg -i test.mpg image%d.jpg默认1s截取25张图片,可以通过-r设置每秒截取的图片数量
+-r fps 设置帧率,也就是每秒截取图片的数量(默认25)
+ffmpeg -i test.mpg -r 1 image%d.jpg这样子每1s截取1张图片
+还可以设置截取间隔,起止
+-ss 设定时间位置,语法:hh:mm:ss[.xxx]
+-t 时长:限制转码/捕获视频的时间,语法:hh:mm:ss[.xxx]
+ffmpeg -i test.mpg -r 25 -ss 00:00:10 -t 00:00:05 images%05d.png在第10秒开始,以每秒截取25张图片的速度,截取5秒时长的图片
+4 从视频中采集音频
+ffmpeg -i video.avi -f mp3 audio.mp3-f 强制选择格式
+ffmpeg -i video.avi -vn audio.mp3-vn 取消截取视频(也就是只输出音频文件)
+5 创建截屏视频
+ffmpeg -f x11grab -r 25 -s wxga -i :0.0 /tmp/outputFile.mpg0.0 是你X11 server的屏幕显示号吗,和DISPLAY一样样的.
+此条命令以每秒25帧的速率来截取wxga屏幕视频,当然这里可以用-s 来设置视频分辨率,输出文件是/tmp/outputFile.mpg
+6 用图片制作视频
+ffmpeg -f image2 -i img%d.jpg /tmp/a.mpg
+将`img001.jpg’, `img002.jpg'这种顺序排列的图片文件转制作为视频
+7 从webcam中截取视频
+ffmpeg -f video4linux2 -s 320x240 -i /dev/video0 out.mpg
+同时截取音频和视频:
+ffmpeg -f oss -i /dev/dsp -f video4linux2 -s 320x240 -i /dev/video0 out.mpg
+/dev/video0为视频设备 /dev/dsp为音频设备
+

+ 2 - 0
source/OtherDemo/常用命令/音频文件转成pcm命令.txt

@@ -0,0 +1,2 @@
+Éú³Éµ¥ÉùµÀ 16bitµÄpcmÎļþ¡£
+ffmpeg.exe -i "D:/in.mp3" -f s16le -ac 1  D:/out.pcm

+ 3 - 0
source/OtherDemo/常用命令/音频转成AAC.txt

@@ -0,0 +1,3 @@
+ffmpeg -i E:/a.mp3 -ac 2 -ar 44100 -ab 32 E:/a.aac
+
+ffmpeg -i E:/a.mp3 -ac 2 E:/a.aac