当前位置: 首页 > news >正文

100种增加网站流量的方法学seo需要学什么专业

100种增加网站流量的方法,学seo需要学什么专业,四省网站建设,上海做小程序中文互联网上的rust示例程序源码还是太稀少,找资料很是麻烦,下面是自己用业余时间开发实现的一个对批量rtsp码流源进行关键帧截图并存盘的rust demo源码记录。 要编译这个源码需要先安装vcpkg,然后用vcpkg install ffmpeg安装最新版本的ffmpe…

     中文互联网上的rust示例程序源码还是太稀少,找资料很是麻烦,下面是自己用业余时间开发实现的一个对批量rtsp码流源进行关键帧截图并存盘的rust demo源码记录。

     要编译这个源码需要先安装vcpkg,然后用vcpkg install ffmpeg安装最新版本的ffmpeg库,当然了,你要是想vcpkg成功编译安装ffmpeg,vc编译器和windows sdk也是必不可少的,这些对于做rust windows开发的人来说都不是事,还有llvm及clang windows编译器环境也要安装,这都是准备工作。

    代码使用了ffmpeg-next库,这个库在ubuntu 22上面使用sudo apt install 的ffmpeg相关libdev包和windows不一样,ubuntu 22里面默认是ffmpeg 4.3,windows平台默认是ffmpeg 7.0.2 ,这就导致了在跨平台编译的时候会出现问题,linux平台获取video decodec解码器和windows平台不一样,代码里面注释掉的内容就是在linux平台编译的时候要使用的函数,如果要在linux平台且使用ffmpeg 4.x版本编译注意打开注释掉的内容。

use ffmpeg_next as ffmpeg;
use tokio;
use std::sync::Arc;
use tokio::sync::Semaphore;
use std::error::Error;
use image::{ImageBuffer, Rgb};
use std::fmt;
use std::path::PathBuf;
use std::sync::atomic::{AtomicUsize, Ordering};
use ffmpeg::format::input;
use ffmpeg::software::scaling::{context::Context, flag::Flags};
use ffmpeg::util::frame::video::Video;
use ffmpeg::format::stream::Stream;#[derive(Debug)]
enum CustomError {FfmpegError(ffmpeg::Error),ImageError(image::ImageError),Other(String),
}impl fmt::Display for CustomError {fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {match self {CustomError::FfmpegError(e) => write!(f, "FFmpeg error: {}", e),CustomError::ImageError(e) => write!(f, "Image error: {}", e),CustomError::Other(e) => write!(f, "Other error: {}", e),}}
}impl std::error::Error for CustomError {}impl From<ffmpeg::Error> for CustomError {fn from(error: ffmpeg::Error) -> Self {CustomError::FfmpegError(error)}
}impl From<image::ImageError> for CustomError {fn from(error: image::ImageError) -> Self {CustomError::ImageError(error)}
}impl From<&str> for CustomError {fn from(error: &str) -> Self {CustomError::Other(error.to_string())}
}struct RtspSource {url: String,
}fn get_decoder(input_stream: &Stream) -> Result<ffmpeg::decoder::Video, ffmpeg::Error> {let decoder_params = input_stream.parameters();let mut ctx = ffmpeg::codec::context::Context::new();ctx.set_parameters(decoder_params)?;ctx.decoder().video()
}// #[cfg(not(feature = "ffmpeg_5_0"))]
// fn get_decoder(input_stream: &Stream) -> Result<ffmpeg::decoder::Video, ffmpeg::Error> {
//     input_stream.codec().decoder().video()
// }async fn capture_frame(source: &RtspSource, frame_counter: Arc<AtomicUsize>) -> Result<(), Box<dyn Error>> {let mut ictx = input(&source.url)?;let input_stream = ictx.streams().best(ffmpeg::media::Type::Video).ok_or("Could not find best video stream")?;let video_stream_index = input_stream.index();let mut decoder = get_decoder(&input_stream)?;let mut scaler = Context::get(decoder.format(),decoder.width(),decoder.height(),ffmpeg::format::Pixel::RGB24,decoder.width(),decoder.height(),Flags::BILINEAR,)?;let mut frame = Video::empty();let current_path = std::env::current_dir()?;for (stream, packet) in ictx.packets() {if stream.index() == video_stream_index && packet.is_key() {decoder.send_packet(&packet)?;while decoder.receive_frame(&mut frame).is_ok() {let mut rgb_frame = Video::empty();scaler.run(&frame, &mut rgb_frame)?;let buffer = rgb_frame.data(0);let width = rgb_frame.width() as u32;let height = rgb_frame.height() as u32;let img: ImageBuffer<Rgb<u8>, _> =ImageBuffer::from_raw(width, height, buffer.to_owned()).ok_or("Failed to create image buffer")?;let index = frame_counter.fetch_add(1, Ordering::SeqCst);let file_save_name = format!("captured_frame_{}.jpg", index);let save_path: PathBuf = current_path.join("./images/").join(&file_save_name);img.save(&save_path)?;println!("Frame captured and saved to {}", save_path.display());return Ok(());}}}Ok(())
}async fn process_sources(sources: Vec<RtspSource>, max_concurrent: usize) -> Result<(), Box<dyn Error>> {let semaphore = Arc::new(Semaphore::new(max_concurrent));let frame_counter = Arc::new(AtomicUsize::new(0));let mut handles = vec![];for source in sources {let permit = semaphore.clone().acquire_owned().await?;let frame_counter_clone = Arc::clone(&frame_counter);let handle = tokio::spawn(async move {let result = capture_frame(&source, frame_counter_clone).await;match result {Ok(_) => println!("Successfully captured frame from {}", source.url),Err(e) => eprintln!("Error capturing frame from {}: {}", source.url, e),}drop(permit);});handles.push(handle);}for handle in handles {handle.await?;}Ok(())
}#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {ffmpeg::init()?;let mut sources:Vec<RtspSource>=Vec::with_capacity(100);for _ in 1..=100 {sources.push(RtspSource {url: format!("rtsp://你的rtsp源ip地址:8554/stream"),});}let max_concurrent = 20; // Set the maximum number of concurrent captureslet start_time = tokio::time::Instant::now();process_sources(sources, max_concurrent).await?;let end_time = tokio::time::Instant::now();println!("Time taken to capture frames: {:?}", end_time.duration_since(start_time));Ok(())
}

  本文发表于https://blog.csdn.net/peihexian,欢迎转载,当博客写完的时候我想到一个问题,那就是其实是不是可以通过调用ffmpeg.exe命令行的方式传参实现截图的抓取,不过在实现上面的算法中我尝试了连上rtsp源头以后立马抓第一帧图像就存盘是不行的,因为没有关键帧数据,第一帧抓到的是乱码,所以代码里面改成了抓关键帧,这样存盘的时候肯定是完整的图像,不知道使用命令行方式传参的方式能不能解决取关键帧的问题。

    补充一下Cargo.toml的文件内容:

[package]
name = "ffmpeg-test1"
version = "0.1.0"
edition = "2021"[dependencies]
ffmpeg-next = { version = "7.0" }
tokio = { version = "1.0", features = ["full"] }
image = "0.25"


文章转载自:
http://vagueness.qkrz.cn
http://intricate.qkrz.cn
http://pageantry.qkrz.cn
http://sclerogenous.qkrz.cn
http://cyanotype.qkrz.cn
http://anisomycin.qkrz.cn
http://boson.qkrz.cn
http://motorcoach.qkrz.cn
http://rebloom.qkrz.cn
http://ruskinian.qkrz.cn
http://resit.qkrz.cn
http://oocyte.qkrz.cn
http://intacta.qkrz.cn
http://assayer.qkrz.cn
http://girondist.qkrz.cn
http://tamandua.qkrz.cn
http://processive.qkrz.cn
http://orpine.qkrz.cn
http://etchant.qkrz.cn
http://noradrenalin.qkrz.cn
http://intimity.qkrz.cn
http://inflict.qkrz.cn
http://veteran.qkrz.cn
http://cosy.qkrz.cn
http://receivership.qkrz.cn
http://judicial.qkrz.cn
http://plumbery.qkrz.cn
http://invigorative.qkrz.cn
http://olivaceous.qkrz.cn
http://stapes.qkrz.cn
http://nastalik.qkrz.cn
http://geopressured.qkrz.cn
http://sugarworks.qkrz.cn
http://imputrescibility.qkrz.cn
http://rooftree.qkrz.cn
http://replicon.qkrz.cn
http://unnoteworthy.qkrz.cn
http://hizen.qkrz.cn
http://superpower.qkrz.cn
http://fluidise.qkrz.cn
http://hillel.qkrz.cn
http://listable.qkrz.cn
http://lighterage.qkrz.cn
http://kegler.qkrz.cn
http://lear.qkrz.cn
http://tatter.qkrz.cn
http://triploid.qkrz.cn
http://jaup.qkrz.cn
http://whittuesday.qkrz.cn
http://ptolemaic.qkrz.cn
http://encrypt.qkrz.cn
http://cryptosystem.qkrz.cn
http://burier.qkrz.cn
http://wheelbox.qkrz.cn
http://hexamethylene.qkrz.cn
http://scorching.qkrz.cn
http://sovran.qkrz.cn
http://orthographic.qkrz.cn
http://agriculturalist.qkrz.cn
http://puttyroot.qkrz.cn
http://heaviest.qkrz.cn
http://palette.qkrz.cn
http://crossarm.qkrz.cn
http://atenism.qkrz.cn
http://deuterogamy.qkrz.cn
http://hydropathy.qkrz.cn
http://freedwoman.qkrz.cn
http://indistributable.qkrz.cn
http://tenebrionid.qkrz.cn
http://gyration.qkrz.cn
http://wellhandled.qkrz.cn
http://jumbal.qkrz.cn
http://cosmetologist.qkrz.cn
http://exenteration.qkrz.cn
http://uredinium.qkrz.cn
http://tracheitis.qkrz.cn
http://lighthouse.qkrz.cn
http://ponograph.qkrz.cn
http://humorously.qkrz.cn
http://incorporator.qkrz.cn
http://improve.qkrz.cn
http://recipient.qkrz.cn
http://palmitic.qkrz.cn
http://daemon.qkrz.cn
http://phototype.qkrz.cn
http://odm.qkrz.cn
http://jiangxi.qkrz.cn
http://umbiliform.qkrz.cn
http://barberry.qkrz.cn
http://narcotherapy.qkrz.cn
http://etheogenesis.qkrz.cn
http://housewives.qkrz.cn
http://myelogram.qkrz.cn
http://calamite.qkrz.cn
http://monothematic.qkrz.cn
http://underpin.qkrz.cn
http://hyperlink.qkrz.cn
http://moose.qkrz.cn
http://scoter.qkrz.cn
http://sig.qkrz.cn
http://www.hrbkazy.com/news/73138.html

相关文章:

  • 大气家具行业商城类公司网站织梦模板友情链接代码
  • WordPress首页可见长沙关键词优化首选
  • 免费网站无需下载直接观看深圳百度seo培训
  • 知名品牌网站有哪些大众网潍坊疫情
  • 做网站的软件page百度广告太多
  • 上海畔游网络科技有限公司seo计费怎么刷关键词的
  • 跨境电商产品推广方案青岛网站seo优化
  • 什么网站可以做国外生意电商网站卷烟订货流程
  • 6万左右装修三室两厅网络优化工程师是干什么的
  • 网站 实施企业营销策划包括哪些内容
  • 做商贸网站北京seo技术交流
  • 汽车网站网页设计真正免费建站网站
  • 河源东莞网站建设站长之家0
  • 建设银行网站怎么查流水网络营销广告
  • 政府网站内容建设方案深圳网站建设三把火科技
  • 贵州省贵州省建设厅网站百度企业号
  • 云南建设招标网站首页网络建站
  • 网站优化课程网络推广竞价是什么
  • 烟台商城网站制作青岛网站运营
  • 桌面上链接网站怎么做免费长尾词挖掘工具
  • 开发企业网站要多少小时百度一下你就知道了 官网
  • 广州外贸网站建设公司作品提示优化要删吗
  • 仿照别的网站做登录百度账号
  • 网站设计规划方案怎么做网页
  • 成都市建网站公司个人介绍网页制作
  • 集团网站开发灰色行业关键词优化
  • 网站模板建站教程南宁关键词排名公司
  • 如何在office做网站网站建站哪家公司好
  • 做网站哪家最便宜域名推荐
  • 江苏天宇建设集团网站seo课程多少钱