获取网页视频文件

方法很多,这里说一个比较简单的方法:

you-get

安装 python;

pip install you-get

获取视频:

如,某视频网站: https://www.video.com/video/VideoP=01

1: 这个表示 视频的 网页, 01 表示 这个视频的 第一集;

2: you-get -i    https://www.video.com/video/VideoP=01

       这里会显示当前视频的 format:mp4hd 等等好几条;

3: you-get --format=mp4hd   https://www.video.com/video/VideoP=01

获取相关 format 类型的分辨率 类型的 视频;

注意:一般默认 获取的音视频都有,但是有些网站,一个视频文件,会获取两个 mp4,其实一个是视频文件,一个是音频文件,所以需要 通过 ffmpeg 组合一下,windows 上可以用 powershell:

如 1.00.mp4, 1.01.mp4

ffmpe.exe -i "t:\1.00.mp4" -i "t:\1.01.mp4"  -vcodec copy -acodec copy ./out1.mp4

可以直接 将文件放到 命令行中  获取 地址;

you-get : 中文说明:

中文说明 · soimort/you-get Wiki · GitHub

// ffmpeg_you-get视频合成.cpp 这个代码,简单执行了 音频文件 和 视频文件 合成;

// 这里在 windows 上默认文件枚举的排列的方式 是名称排列,所以不需要每次便利对比;

// 可以更加文件名的实际情况修改;

// 这里程序以多字节设置运行;

// ffmpeg_you-get视频合成.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//

#include <iostream>
#include <string>
#include <windows.h>
#include <vector>

#include   <shlobj.h>
#include <iostream>
using namespace std;


const char* pstrDir = "F:\\test";

std::vector<std::string> g_vector_strPath;


void   EnumerateFolder(const char *   path)
{
	HRESULT   hr;  
	hr = CoInitialize(NULL); 


	LPMALLOC   pMalloc = NULL;
	hr = SHGetMalloc(&pMalloc);

	LPSHELLFOLDER   psfDesktop = NULL;  
	hr = SHGetDesktopFolder(&psfDesktop);


	OLECHAR   olePath[MAX_PATH];   //   wide-char   version   of   path   name   
 	MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, path, -1, olePath, MAX_PATH);

	LPITEMIDLIST   pidl = NULL;
	hr = psfDesktop->ParseDisplayName(NULL, NULL, olePath/*path*/, NULL, &pidl, NULL);
	LPSHELLFOLDER   psfFolder = NULL;
	hr = psfDesktop->BindToObject(pidl, NULL, IID_IShellFolder, (void**)&psfFolder);

	psfDesktop->Release();
	pMalloc->Free(pidl);

	LPENUMIDLIST   penumIDL = NULL;
	hr = psfFolder->EnumObjects(NULL, SHCONTF_FOLDERS | SHCONTF_NONFOLDERS, &penumIDL);

	while (1)
	{
		hr = penumIDL->Next(1, &pidl, NULL);
		if (hr == NOERROR)
		{
			WIN32_FIND_DATA   ffd;   //   let 's   cheat   a   bit   :)
			hr = SHGetDataFromIDList(psfFolder, pidl, SHGDFIL_FINDDATA, &ffd, sizeof(WIN32_FIND_DATA));

			g_vector_strPath.push_back(std::string(ffd.cFileName));

			//cout << "Name   =   " << ffd.cFileName << endl;
			//cout << "Type   =   " << ((ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? "dir\n " : "file\n ");
			//cout << "Size   =   " << ffd.nFileSizeLow << endl;

			pMalloc->Free(pidl);
		}
		else
		{
			break;
		}
	}

	penumIDL->Release();
	psfFolder->Release();
	pMalloc->Release();

	CoUninitialize();   //   shut   down   COM
}




void ffmpeg_you_get()
{
	int n_vector = g_vector_strPath.size();
	
	std::string strDir = std::string(pstrDir) + std::string("\\");
	
	for (int n = 0; n < n_vector; n++)
	{
		//std::cout << g_vector_strPath.at(n) << std::endl;
	}



	int nVector = g_vector_strPath.size();

	while (g_vector_strPath.size() >= 2)
	{

		std::string strFile1 = g_vector_strPath.at(0);
		std::string strFile2 = g_vector_strPath.at(1);


		for (int n = 0; n < nVector; n++)
		{
			std::string strP = std::string("P") + std::to_string(n) + std::string("."); //根据实际文件命名修改;


			std::string str_00 = "[00].mp4";
			std::string str_01 = "[01].mp4";


// 			std::string strFile1 = g_vector_strPath.at(0);
// 			std::string strFile2 = g_vector_strPath.at(1);

			int nPstrFile1 = strFile1.find(strP, 0);
			int nPstrFile2 = strFile2.find(strP, 0);

			int nstr_00 = strFile1.find(str_00);
			int nstr_01 = strFile2.find(str_01);

			int nstrFile1Len = strFile1.length();
			int nstrFile2Len = strFile2.length();

			if ((nstrFile1Len == nstrFile2Len) && (nPstrFile1 > 0) && (nPstrFile1 == nPstrFile2) && (nstr_00 > 0) && (nstr_00 == nstr_01))
			{
				std::string strFullFile1 = std::string("\"") + strDir + strFile1 + "\"";
				std::string strFullFile2 = std::string("\"") + strDir + strFile2 + "\"";

				std::string strFullFile_out = std::string("\"") + strFile1 + "\"";


				std::string strffmpeg = std::string("F:\\t1\\bin\\ffmpeg.exe");

				std::string ffmpegParam =  std::string(" -i ") + strFullFile1 + " -i " + strFullFile2 + " -acodec copy -vcodec copy " + strFullFile_out;

				std::string strFFmpegCmd = strffmpeg + ffmpegParam;


				if(0)
				{
					WinExec(strFFmpegCmd.c_str(), SW_SHOW);
				}
				else
				{			

						SHELLEXECUTEINFO ShExecInfo;

						ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
						ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
						ShExecInfo.hwnd = NULL;
						ShExecInfo.lpVerb = NULL;
						ShExecInfo.lpFile = strffmpeg.c_str();
						ShExecInfo.lpParameters = ffmpegParam.c_str();
						ShExecInfo.lpDirectory = NULL;
						ShExecInfo.nShow = SW_SHOW;
						ShExecInfo.hInstApp = NULL;

						ShellExecuteEx(&ShExecInfo);
						//是否等待直到另一个程序启动;

						WaitForSingleObject(ShExecInfo.hProcess, 100000);

 
				}



				//删除前两个已经完成的;
				for (int i = 0; i<2; i++)
				{
					g_vector_strPath.erase(g_vector_strPath.begin());
				}

				break;

			}

		}

	}





}





int main()
{
	EnumerateFolder(pstrDir);


	ffmpeg_you_get();

}

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

chinabinlang

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

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

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

打赏作者

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

抵扣说明:

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

余额充值