为什么用分流器(小型交换机)将一根网线分为分为两根后能够产生两个ip地址?

为什么用分流器(小型交换机)将一根网线分为分为两根后能够产生两个ip地址?

大一的时候宿舍的网口不够用,于是去网上买了一个分流器将一根网线分为两个,能够供两个小伙伴使用,当时去看了接上了这两根网线的ip地址,发现他们不一样,我就很困惑,它们都是经过同一根网线出去的,为什么它们的地址不一样呢?

直到后来学了计算机网络后终于懂了。
原来网络不是我想的这样,在有dpcp服务的系统中,每台主机接入系统都会请求分配ip地址,所以经过同一个网线的两台主机有两个ip地址,ip地址也不是固定在网线上的,甚至mac地址也不是固定在网线上的,网线只不过是一条路。

在C++中可以使用FFmpeg库对音视频行处理,包括分离和合成。下面是一个简单的示例代码,将一个视频文件分离成视频和音频两个文件。 ```c++ #include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include "ffmpeg.h" using namespace std; // 分离音视频 int split(const char* input_filename, const char* video_filename, const char* audio_filename) { AVFormatContext *pFormatCtx = NULL; AVCodecContext *pCodecCtx = NULL; AVCodec *pCodec = NULL; AVFrame *pFrame = NULL; AVPacket packet; int video_index = -1, audio_index = -1; int frame_count = 0; av_register_all(); // 注册FFmpeg库中所有可用的文件格式和编解码器 // 打开输入文件 if (avformat_open_input(&pFormatCtx, input_filename, NULL, NULL) != 0) { printf("Could not open input file %s\n", input_filename); return -1; } // 查找流信息 if (avformat_find_stream_info(pFormatCtx, NULL) < 0) { printf("Could not find stream information\n"); return -1; } // 查找音视频流索引 for (int i = 0; i < pFormatCtx->nb_streams; i++) { if (pFormatCtx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { video_index = i; } else if (pFormatCtx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { audio_index = i; } } // 打开视频解码器 if (video_index >= 0) { pCodec = avcodec_find_decoder(pFormatCtx->streams[video_index]->codecpar->codec_id); if (pCodec == NULL) { printf("Could not find video codec\n"); return -1; } pCodecCtx = avcodec_alloc_context3(pCodec); if (avcodec_parameters_to_context(pCodecCtx, pFormatCtx->streams[video_index]->codecpar) < 0) { printf("Failed to copy video codec parameters\n"); return -1; } if (avcodec_open2(pCodecCtx, pCodec, NULL) < 0) { printf("Failed to open video codec\n"); return -1; } } // 打开音频解码器 if (audio_index >= 0) { pCodec = avcodec_find_decoder(pFormatCtx->streams[audio_index]->codecpar->codec_id); if (pCodec == NULL) { printf("Could not find audio codec\n"); return -1; } pCodecCtx = avcodec_alloc_context3(pCodec); if (avcodec_parameters_to_context(pCodecCtx, pFormatCtx->streams[audio_index]->codecpar) < 0) { printf("Failed to copy audio codec parameters\n"); return -1; } if (avcodec_open2(pCodecCtx, pCodec, NULL) < 0) { printf("Failed to open audio codec\n"); return -1; } } // 分离音视频并写入文件 while (av_read_frame(pFormatCtx, &packet) >= 0) { if (packet.stream_index == video_index) { // 视频帧 if (video_filename) { FILE* video_file = fopen(video_filename, "ab"); fwrite(packet.data, 1, packet.size, video_file); fclose(video_file); } } else if (packet.stream_index == audio_index) { // 音频帧 if (audio_filename) { FILE* audio_file = fopen(audio_filename, "ab"); fwrite(packet.data, 1, packet.size, audio_file); fclose(audio_file); } } av_packet_unref(&packet); // 释放packet } // 关闭解码器 if (pCodecCtx != NULL) { avcodec_free_context(&pCodecCtx); } // 关闭文件 avformat_close_input(&pFormatCtx); return 0; } int main(int argc, char* argv[]) { if (argc < 2) { printf("Usage: %s input_file [video_file] [audio_file]\n", argv[0]); return -1; } const char* input_filename = argv[1]; const char* video_filename = NULL; const char* audio_filename = NULL; if (argc > 2) { video_filename = argv[2]; } if (argc > 3) { audio_filename = argv[3]; } if (split(input_filename, video_filename, audio_filename) < 0) { printf("Failed to split file %s\n", input_filename); return -1; } printf("Split file %s successfully\n", input_filename); return 0; } ``` 这个示例代码可以将一个视频文件分成视频和音频两个文件,并保存在指定的文件名中。你可以据自己的需求修改代码。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值