PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, July 17, 2022

[FIXED] How to make gif image from youtube video?

 July 17, 2022     gif, javascript, php, youtube, youtube-api     No comments   

Issue

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?


Solution

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!



Answered By - hakre
Answer Checked By - David Goodson (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing