duanjing1276 2013-08-07 10:53
浏览 135
已采纳

如何从youtube视频制作gif图像?

Anybody help me i want to developing a website using php code. GIF-KING this is my website i have completed jpeg image to gif creator but how to create GIF image from YouTube URL like yt2gif

I tried to search Google but there is not gives any sufficient result to fulfill my requirement.

I got the code upload video to GIF creator but unable to find the script making YouTube URL to GIF creator.

I got one solution first download YouTube video by using YouTube API. then convert it to in GIF images. But that is not the right way. i am unable to convert it in the middle part. Always convert from starting Also it is not possible to download huge number of video from YouTube.

See my process of creating GIF images from YouTube URL.

Screenshot-1 :

Copy the YouTube URL enter image description here

Screenshot-2 :

Paste it in the website http://www.gif-king.com/make-your-gif3 see below screenshot. enter image description here

Click on Create Gifs after some times the video details will appear See screenshot-3.

Screenshot-3 :

Showing the video details from YouTube

After click on Make Gif this video will convert to GIF.

It is working for a small video. but not working it for big video.

My php code:

ajax.php

if(isset($_REQUEST['vid'])){
    $vidID=$_REQUEST['vid'];
    if($vidID){
        include('curl.php');
        include('youtube.php');
        $tube = new youtube();

        $links = $tube->get("http://www.youtube.com/watch?v=".$vidID);
        $getVideo=$links[3]['url']; //Get the avi video from youtube 
        $cate=mysql_query("select * from category ORDER BY id ");
        while($categoryName=mysql_fetch_array($cate)){
            $getCatRes .= '<option value="'.$categoryName['id'].'">'.$categoryName['name'].'</option>';
        }
        if($getVideo) {
            $url = "http://gdata.youtube.com/feeds/api/videos/". $vidID;
            $doc = new DOMDocument;
            $doc->load($url);
            $title = $doc->getElementsByTagName("title")->item(0)->nodeValue;
            $duration = $doc->getElementsByTagName('duration')->item(0)->getAttribute('seconds');
            if($duration > 1200){
                $array[] = array('result'=>'error','message'=>'ERROR!!! Maximum 20 minutes video allowed');
            }
            else{
            $newVideo = "gifking_".time().".avi";
            $videoUploaded=file_put_contents("myvideo/".$newVideo,file_get_contents($getVideo));
            if($videoUploaded){
                    $video='<iframe width="360" height="240" frameborder="0" allowfullscreen="" src="http://www.youtube.com/embed/'.$vidID.'?enablejsapi=1&amp;playerapiid=ytplayer&amp;version=3&amp;cc_load_policy=0&amp;iv_load_policy=3&amp;modestbranding=1&amp;rel=0&amp;showinfo=0&amp;theme=light"></iframe>';

                    $video_title='<input type="text" class="add-gif-textbox" name="title" id="title" placeholder="Title" value="'.$title.'"  />';
                    $category='<select class="add-gif-dropdown" id="cat_id" name="cat_id">
                                  '.$getCatRes.'
                                  </select>';
                    $tag='<input type="text" class="add-gif-textbox" name="tag" id="tag" placeholder="tiger,book,flower" />';
                    $submitBtn='<input id="button" class="button1" type="submit" value="Make Gif" name="submit">';

                    $array[] = array('result'=>'success','title'=>$video_title,'category'=>$category,'video'=>$video,'duration'=>$duration,'tag'=>$tag,'filename'=>$newVideo,'submit_btn'=>$submitBtn);
                }
                else{
                    $array[] = array('result'=>'error','message'=>'ERROR!!! Uploading image please try again');
                }
            }
        }
        else{
            $array[] = array('result'=>'error','message'=>'ERROR!!! Invalid video id');
        }
        echo json_encode($array);
    }
}

Please suggest me how to creating that in php code?

  • 写回答

9条回答 默认 最新

  • dqd78456 2013-08-15 09:21
    关注

    It works totally easy, lucky for you! Here is a simple step-by-step program of that:

    1. You first of all download the video from Youtube (or any other video website not to make it too specific). This can be done with a download program. Those exist, there are popular ones.

    2. Then you need a video converter program. Those exist, there are popular ones. With it you extract each X frames as an image. Take care to get the timing right so you understand the duration in milliseconds between each of those X frames.

    3. Then you merge all the image files of the extracted frames again with a software that can create an animated gif. Those exist, there are popular ones. Take care here now that you set the timing right between the frames.

    4. Then you save the gif image to a specific filename.

    Good News: You are done.

    As far as the program of this is concerned (the programming question), you find the steps outlined in the list above.

    The implementation depends on tool suggestions which are off-topic here on site (but this shouldn't be show stopper for you as each step above is explained in detail within the interwebs and you seem to be clever enough to use the interwebs otherwise you wouldn't have asked on Stackoverflow).

    Good luck and have fun. Let us know how it worked out!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(8条)

报告相同问题?

悬赏问题

  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型
  • ¥15 求学软件的前人们指明方向🥺
  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题