如何从视频显示图像作为播放列表的预览 [英] How to show Images from a video as preview for playlist

查看:190
本文介绍了如何从视频显示图像作为播放列表的预览的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你们已经看过Youtube了。在您正在观看视频的同时,您还将获得相关视频与链接预览。那么我们如何从视频本身获得它..可以这样做..我可以从数据库中获取url并显示它..当链接被点击它将播放在一个jquery播放器..所以之前的预览,或者你可以说播放列表将可供用户使用。



我已经更新了我的代码与我找到的链接..但是仍然我无法从视频中获取图像..我的代码有什么问题..请纠正我,如果我错了..



以下是我的前端代码:

 < form id =form1runat =server> 
< div id =examplesrunat =serverstyle =height:100%; width:100%>
< div id =vidhead>最新视频< / div>

< / div>

< / form>

我正在从页面上加载所有我的视频链接,如下所示:

  try 
{
con.Open();
com = new SqlCommand(通过[vid] desc从视频顺序选择视频,视频),con);
DbDataReader dr = com.ExecuteReader();
DataTable dt = new DataTable();

if(dr.HasRows)
{

int i = 0;
dt.Load(dr);
int rows = dt.Rows.Count;


for(i = 0; i< rows; i ++)
{
HtmlGenericControl d = new HtmlGenericControl(div);
HtmlGenericControl s = new HtmlGenericControl(span);
string [] link = new string [rows];
string [] name = new string [rows];

d.Attributes.Add(class,plst);
s.Attributes.Add(class,text);
link [i] = dt.Rows [i] [videourl]。ToString();
name [i] = dt.Rows [i] [videoname]。ToString();
string videothumb = link [i];
string svthto =**保存图像**的路径;
string imgpath = GetVideoThumbnail(videothumb,svthto,30);

sb.Append(< a id =+\a+ i +\+href =+\ +\+class =+\links\+>+ name [i] +< / a>);
s.InnerHtml = sb.ToString();
d.Controls.Add(s);
examples.Controls.Add(d);
sb.Clear();


}
}


}
catch(Exception ex)
{
ex .Message.ToString();
}

public string GetVideoThumbnail(string path,string saveThumbnailTo,int seconds)
{
string parameters = string.Format( - ss {0} -i {1} -f image2 -vframes 1 -y {2},秒,路径,saveThumbnailTo);
string pathToConvertor =C:\\Program Files\\\\ffmpeg\\\\ffmpeg.exe;
var processInfo = new ProcessStartInfo();
processInfo.FileName = pathToConvertor;
processInfo.Arguments = parameters;
processInfo.CreateNoWindow = true;
processInfo.UseShellExecute = false;

File.Delete(saveThumbnailTo);

使用(var process = new Process())
{
process.StartInfo = processInfo;
process.Start();
process.WaitForExit();
}

if(File.Exists(saveThumbnailTo))
return saveThumbnailTo;
else
返回找不到文件;
}

这里是我到现在为止的形象:



请注意:我我不是专注于你管视频。我正在质疑我在服务器端文件夹中存储的视频。所以如果有任何jquery技术或任何技术来做,那么请让我知道。)

解决方案

p> 首先我要感谢@rtpHarry谁介绍了我ffmpeg ..否则我不会来了解如何实现这一点..这可能不是唯一的方法..但这是很好的方式给我.. :)感谢@rtpHarry .. +50为那个...:)



经过长时间的搜索,我想出了这个解决方案现在看起来很酷很好,这是我期待的... ..)



这是我在后端页面加载事件。

  con.Open(); 
com = new SqlCommand(select * from video order by [vid] desc,con);
string thumbname =;
string newthumb =;
string newpath =;
reader = com.ExecuteReader();
if(reader.HasRows)
{
dt.Load(reader);
int rows = dt.Rows.Count;
int i = 0; (i = 0; i< rows; i ++)
{
int [] id = new int [rows];


string [] link = new string [rows];
string [] nid = new string [rows];

id [i] = Convert.ToInt32(dt.Rows [i] [vid]。ToString());
link [i] = dt.Rows [i] [videourl]。ToString();
nid [i] = id [i] .ToString();

thumbname = Server.MapPath(〜// Images // Video_Thumbs //)+ nid [i] +.jpg;
newthumb = nid [i] +.jpg;
string link1 = Server.MapPath(〜// Videos //)+ link [i];
string param = String.Format( - ss {0} -i \+ link1 +\-s 150 * 120 -vframes 1 -f image2 -vcodec mjpeg \+ thumbname +\,20);
进程p = new Process();
p.StartInfo.Arguments = param;
p.StartInfo.FileName = Server.MapPath(〜\\ffmpeg\\ffmpeg.exe);
p.StartInfo.CreateNoWindow = true;
p.StartInfo.UseShellExecute = false;
p.Start();

newpath =Images // Video_Thumbs //+ newthumb.ToString();
com1 = new SqlCommand(update video set vidthumb ='+ newpath +'其中vid =+ id [i] +,con);
com1.ExecuteNonQuery();
}
}
con.Close();

到目前为止,我还没有为视频设计fileupload部分,所以我已经在页面中写了这段代码加载。因此,当页面加载视频从表视频将被逐个检索时,20秒的帧将被捕获并保存在一个特定的文件夹以及表视频中。其实问题是,在路径之前没有识别出没有〜号的 Server.Mappath 。现在它的工作很好,这里是我期待的形象...:)





如果有人访问检查这个问题和答案,如果有人有疑问,那么请在这里留言..将是我的荣幸,帮助你们...,非常感谢ffmpeg ..:)


You guys Have seen Youtube right. There while you are watching a video, You will also get related videos preview alongwith link. So how we can get it from video itself.. Is it possible to do so.. I am able to get the url from database and display it.. and when the link is clicked it will be played in a jquery player.. So before that a preview of that or you can say playlist of that will be available for user.

I have updated my code with a link I found.. But still I am not able to get the Image from Video.. Is there anything wrong in my code.. Please correct me if I am wrong..

Below is my front end code:

<form id="form1" runat="server">
    <div id="examples" runat="server" style="height:100%;width:100%">
        <div id="vidhead">Latest Videos</div>

    </div>

    </form>

and I am adding all my video links from backend on page load as shown below:

   try
    {
        con.Open();
        com = new SqlCommand("Select videourl, videoname from video order by [vid] desc",con);
        DbDataReader dr = com.ExecuteReader();
        DataTable dt = new DataTable();

        if (dr.HasRows)
        {

            int i = 0;
            dt.Load(dr);
            int rows = dt.Rows.Count;


            for (i = 0; i < rows; i++)
            {
                HtmlGenericControl d = new HtmlGenericControl("div");
                HtmlGenericControl s = new HtmlGenericControl("span");
                string[] link = new string[rows];
                string[] name = new string[rows];                    

                d.Attributes.Add("class", "plst");
                s.Attributes.Add("class", "text");
                link[i] = dt.Rows[i]["videourl"].ToString();
                name[i] = dt.Rows[i]["videoname"].ToString();
                string videothumb = link[i];
                string svthto="**Path to save Image**";
                string imgpath=GetVideoThumbnail(videothumb, svthto, 30);

                sb.Append("<a id=" + "\"a" + i + "\"" + " href=" + "\"" + link[i] + "\"" + " class=" + "\"links\"" + ">" + name[i] + "</a>");
                s.InnerHtml = sb.ToString();
                d.Controls.Add(s);
                examples.Controls.Add(d);
                sb.Clear();


            }
        }


    }
    catch(Exception ex)
    {
        ex.Message.ToString();
    }

public string GetVideoThumbnail(string path, string saveThumbnailTo, int seconds)
{
    string parameters = string.Format("-ss {0} -i {1} -f image2 -vframes 1 -y {2}", seconds, path, saveThumbnailTo);
    string pathToConvertor = "C:\\Program Files\\ffmpeg\\ffmpeg.exe";
    var processInfo = new ProcessStartInfo();
    processInfo.FileName = pathToConvertor;
    processInfo.Arguments = parameters;
    processInfo.CreateNoWindow = true;
    processInfo.UseShellExecute = false;

    File.Delete(saveThumbnailTo);

    using (var process = new Process())
    {
        process.StartInfo = processInfo;
        process.Start();
        process.WaitForExit();
    }

    if (File.Exists(saveThumbnailTo))
        return saveThumbnailTo;
    else
        return "File not Found";
}

and here is the image of what I am getting until now:

Please note: I am not concentrating on you tube videos. I am questioning regarding the videos which I store in server side folder. So if there is any jquery technique or any sort of technique to do this then please let me know.:)

解决方案

First of all I would like to thank @rtpHarry who introduced me to ffmpeg.. otherwise I wouldn't come to know about how to achieve this.. This might not be the only way.. But this was good way for me.. :) Thanks @rtpHarry.. +50 for that... :)

Well after a long search I have come up with this solution and it looks cool and fine now and this is what I was expecting.. :)

This is what I do in backend page load event.

con.Open();
        com = new SqlCommand("Select * from video order by [vid] desc", con);
        string thumbname = "";
        string newthumb = "";
        string newpath = "";
        reader = com.ExecuteReader();
        if (reader.HasRows)
        {
            dt.Load(reader);
            int rows = dt.Rows.Count;
            int i = 0;

            for (i = 0; i < rows; i++)
            {
                int[] id = new int[rows];
                string[] link=new string[rows];
                string[] nid = new string[rows];

                id[i] = Convert.ToInt32(dt.Rows[i]["vid"].ToString());
                link[i] = dt.Rows[i]["videourl"].ToString();
                nid[i]=id[i].ToString();

                thumbname = Server.MapPath("~//Images//Video_Thumbs//") + nid[i] + ".jpg";
                newthumb = nid[i] + ".jpg";
                string link1 = Server.MapPath("~//Videos//") + link[i];
                string param = String.Format("-ss {0} -i \"" + link1 + "\" -s 150*120  -vframes 1 -f image2 -vcodec mjpeg \"" + thumbname + "\"",20);
                Process p = new Process();
                p.StartInfo.Arguments = param;
                p.StartInfo.FileName = Server.MapPath("~\\ffmpeg\\ffmpeg.exe");
                p.StartInfo.CreateNoWindow = true;
                p.StartInfo.UseShellExecute = false;
                p.Start();

                newpath="Images//Video_Thumbs//"+newthumb.ToString();
                com1 = new SqlCommand("update video set vidthumb='" + newpath + "' where vid=" + id[i] + "", con);
                com1.ExecuteNonQuery();
            }
        }
        con.Close();

As of now I have not designed the fileupload part for the videos so I have written this code in page load. So when ever the page loads the videos from the table "Video" will be retrieved one by one and a frame at 20sec time will be captured and saved in a specific folder and also in table "Video". Actually, the problem was, it was not recognizing the Server.Mappath without "~" sign before the path. Now its working well and fine and here is the image of what I was expecting... :)

If anyone visits checks this question and answer and if anyone has some doubt then please comment here.. It will be my pleasure to help you people... and Great thanks to ffmpeg.. :)

这篇关于如何从视频显示图像作为播放列表的预览的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆