LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 04-05-2017, 07:46 PM   #1
gilesaj001
Member
 
Registered: Apr 2017
Location: Australia
Distribution: Ubuntu
Posts: 79

Rep: Reputation: 0
How to capture the current image from a youtube live feed


I have been trying to use a script called iget to get the current image from a youtube live fed but because the url needs a filename to get I do not have that on youtube ?

Code:
#!/bin/bash
# iget.sh
#
#  Author: Gregory Strike
#     URL: http://www.gregorystrike.com/2007/06/06/bash-script-interval-get/
#
# Purpose: This script downloads a file from the Internet at a set interval.
#
#  example input ./iget.sh http://nfl.packers.com/multimedia/live_cams/image.jpeg lambeau.jpg 60
# Syntax:
# iget url filename i
# Where filename = The custom file name
# Where i = the interval of the download in seconds
REQPARAMS=3
url=$1
filename=$2
interval=$3
function download()
{
        #http://www.wluk.com/lambeaucam/lambeaucam.jpg
        wget $url -O $(date '+%Y-%m-%d_%H%M%S')_$filename
}
function pause()
{
        echo Downloading $url...
        echo Interval is set to $interval seconds...
        echo -n "Next download in "
        (( intervalleft=interval ))
        while (( intervalleft > 0 ))
        do
                echo -n -e "$intervalleft seconds..."
                if ((${intervalleft:${#intervalleft}-1:1}==9))#Detects if there is a nine at the end
                        then
                        echo -n -e " \\b"                       #If so, write a space and then backspace
                fi
                sleep 1                                         #Zzzzzz...  For 1 second.
                echo -n -e \\b\\b\\b\\b\\b\\b\\b\\b\\b\\b\\b    #Erases the "seconds..."
                backspaces=${#intervalleft}                     #Get the current number of digits
                while (( backspaces > 0 ))                      #Loop until the last digit has been backspaced
                do
                        echo -n -e \\b
                        (( backspaces-- ))
                done
                (( intervalleft-- ))
        done
}
if (( $# != $REQPARAMS ))
        then
                echo "Error: Incorrect Syntax"
                echo "Required: " $REQPARAMS " Passed: " $#
                echo
                echo "Syntax: ./iget.sh url filename interval"
                echo "URL = The URL/location of the file."
                echo "FILENAME = Base name of the file saved locally."
                echo "INTERVAL = The seconds between downloads."
        exit
fi
while ((1))
do
        download
        pause
done
I have searched the internet for a way to capture an image from a youtube video from the command line in Linux and have not been able to find one.

If you know if there is a filename for youtube videos please let me know how to find it.

The url that I am trying to get the latest image from is

https://youtu.be/n1HCKMD_8ss

or

https://www.youtube.com/watch?v=n1HC...ature=youtu.be

The syntax of "./iget.sh https://youtu.be/n1HCKMD_8ss osprey.jpg 60" seems to work but the file is either corrupted or empty as it cannot be opened as a jpg

Any help would be appreciated.
 
Old 04-06-2017, 12:52 PM   #2
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
what i'd do:
a) simply take a screenshot
or
b) just download the whole video (e.g. with this) and extract the last frame with ffmpeg.
 
Old 04-06-2017, 08:53 PM   #3
gilesaj001
Member
 
Registered: Apr 2017
Location: Australia
Distribution: Ubuntu
Posts: 79

Original Poster
Rep: Reputation: 0
Got an answer.

Quote:
Originally Posted by ondoho View Post
what i'd do:
a) simply take a screenshot
or
b) just download the whole video (e.g. with this) and extract the last frame with ffmpeg.
I am doing this in a script not in a GUI so taking a screenshot of the latest image in a live feed is what I would like to do but in a script.

I have tried to use youtube-dl but because it is a live feed there is not a video to download, well it does not seem to work on a live feed. I get this error which on yt-dl it says:
error:
Code:
ERROR: unable to download video info webpage: HTTP Error 402: Payment Required (caused by HTTPError())
The error is reported on yt.dl https://github.com/rg3/youtube-dl/issues/12562 and refers to this https://github.com/rg3/youtube-dl#ht...yment-required

Code:
HTTP Error 429: Too Many Requests or 402: Payment Required

These two error codes indicate that the service is blocking your IP address because of overuse. Contact the service and ask them to unblock your IP address, or - if you have acquired a whitelisted IP address already - use the --proxy or --source-address options to select another IP address.
So I guess the server IP on my dedicated server must have tried in the past. I will try a different server and see if I get the same error ??

Thanks for the reply.
 
Old 04-07-2017, 10:45 AM   #4
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
your script is just a fancy wrapper around this command:
Code:
wget $url -O $(date '+%Y-%m-%d_%H%M%S')_$filename
judging from the commented out url, i assume it was designed to capture images from a still image webcam; these still exist all over the web, but really it's just the URL to an image, and that image changes every time you reload the URL.

downloading a frame from a youtube video is a whole different piece of cake, and cannot be done in this way!!!

fwiw, i am watching 2 ospreys on my desktop right now, with mpv (*).
so it is possible, and i guess the 402 error means youtube kicked you out because too many requests.
close your browser, wait an hour or two, and try again.

(*) mpv uses youtube-dl for youtube videos. youtube-dl in turn uses ffmpeg.
here's a rough idea to capture one frame: restart the download every minute, only use the first frame.
(maybe that's precisely what caused the 402 error :-(
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Get image from live feed. dingo-den Linux - General 1 06-01-2014 02:27 AM
[SOLVED] Get image (jpg) from a Java live feed. dingo-den Linux - General 9 05-20-2014 09:22 PM
Zoneminder 1.25.0 on CentOS 6.3 - black image without live feed deeonline Linux - Software 1 04-28-2013 04:32 AM
accidentally burned live image over my current system, need to reverse bplis* Linux - Software 6 02-15-2012 07:45 AM
Exact time of image capture and Unicap library for video capture devices Dstruct0 Programming 3 09-10-2011 06:34 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 03:39 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration