Pass image to STDIN for ffprobe to read in Ruby - ruby

I have a script that is currently using wget to grab an image from a url then passing that image to ffprobe. I'd like to remove the wget dependancy. What is the best way to download this image from the URL into STDIN so that ffprobe can read it.
Current logic is:
wget_command = "wget --header=\"ApiKey: #{#config.api_key}\" -O- #{file} | "
ffprobe_command = "ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=s=x:p=0 -i"
Open3.capture3("#{wget_command} #{ffprobe_command} -")
Other places in the script use Faraday for http requests so that is ideally what I would like to use to pull the image.

What is the best way to download this image from the URL into STDIN so
that ffprobe can read it.
ffprobe itself can get network resource, from ffprobe docs, your case is somewhat more complicated, but it should be possible if ffprobe does act in this are same way as ffmpeg which allows you to pass http headers, I suggest starting with following command
ffprobe -headers $'ApiKey: YOURAPIKEY' -i URLTOIMAGE -v trace

Related

ffmpeg: How to save SSIM and PSNR to a file?

I'm a ffmpeg newbie.
I would like my script (on Windows) to output the average PSNR and average SSIM values to a file.
(but not the values for every frame)
I can output them to the standard output but not to a file.
I use this line:
ffmpeg -i ref.avi -i compressed.avi -lavfi "ssim;[0:v][1:v]psnr" -f null -
I understand I have to change something here: "-f null -" , but I cannot make it work.
Using ssim & psnr filters
On Linux and macOS you can use grep:
$ ffmpeg -i compressed.avi -i reference.avi -lavfi "[0][1]ssim;[0][1]psnr" -f null - |& grep Parsed_ > ff.log
Simple, but major downside is it won't show you the console output, so you may miss errors. To fix that add tee:
$ ffmpeg -i compressed.avi -i reference.avi -lavfi "[0][1]ssim;[0][1]psnr" -f null - |& tee >(grep Parsed_ > ff.log)
Example contents of ff.log from either command:
[Parsed_ssim_0 # 0x5579d7f17b40] SSIM Y:0.796135 (6.906565) U:0.843488 (8.054531) V:0.822424 (7.506157) All:0.820682 (7.463768)
[Parsed_psnr_1 # 0x5579d7f12b00] PSNR y:24.940925 u:23.938192 v:23.641771 average:24.138969 min:23.298059 max:26.880485
If you want to append to ff.log instead of overwrite use grep Parsed_ >> ff.log instead.
If |& does not work for you use 2>&1 instead.
Or use libvmaf
libvmaf filter is slower but will output a log file containing the VMAF, SSIM, and PSNR aggregate scores along with the per frame scores in XML or JSON. Your ffmpeg will need to be compiled with --enable-libvmaf to use this filter.
ffmpeg -i compressed.avi -i reference.avi -lavfi "[0][1]libvmaf=log_path=vmaf.xml:log_fmt=xml:ssim=1:psnr=1" -f null -

Output luma and chroma data in txt format

Good day!
I would like to know if there's a way to get Y/luma values in txt format
here it is the command line
-https://ffmpeg.org/ffmpeg-filters.html#Examples-105
https://ffmpeg.org/ffmpeg-filters.html#signalstats-1
and one more thing I would like to know the way to get all YUV min/max values at once
thanx
regards.
Use a less verbose log level and append the command with > output.txt:
ffprobe -loglevel error -f lavfi movie=input.mp4,signalstats -show_entries frame_tags=lavfi.signalstats.YMIN,lavfi.signalstats.YLOW,lavfi.signalstats.YAVG,lavfi.signalstats.YHIGH,lavfi.signalstats.YMAX,lavfi.signalstats.UMIN,lavfi.signalstats.ULOW,lavfi.signalstats.UAVG,lavfi.signalstats.UHIGH,lavfi.signalstats.UMAX,lavfi.signalstats.VMIN,lavfi.signalstats.VLOW,lavfi.signalstats.VAVG,lavfi.signalstats.VHIGH,lavfi.signalstats.VMAX > output.txt
You can change the output format with the -of option.

Subtract two timecodes in bash, for use in ffmpeg

I am running ffmpeg in terminal on a mac, to trim a movie file losslessly using the following in bash:
startPosition=00:00:14.9
endPosition=00:00:52.1
ffmpeg -i mymovie.mov -ss $startPosition -to $endPosition -c copy mymovie_trimmed.mov
But that doesn't seek the nearest keyframe and causes sync issues. See here: https://github.com/mifi/lossless-cut/pull/13
So I need to rearrange my code like this:
ffmpeg -ss $startPosition -i mymovie.mov -t $endPosition -c copy mymovie_trimmed.mov
(the -to property seems to get ignored, so I am using -t (duration) instead). My question is how can I reliably subtract the $startPosition variable from the $endPosition to get the duration?
EDIT: I used oguz-ismail's suggestion with using gdate instead of date (and brew install coreutils):
startPosition=00:00:10.1
endPosition=00:00:50.1
x=$(gdate -d"$endPosition" +'%s%N')
y=$(gdate -d"$startPosition" +'%s%N')
duration=$(bc -lq <<<"scale=1; ($x - $y) / 1000000000")
This gives me output of 40.1, how would I output it as 00:00:40.0 ?

could use some help on ffprobe

I'm currently running the following command and it's giving me mostly what I need, but I would like to also have it include the file name.
for %%A IN (%VAR0%\*.wav) DO "C:\program files (x86)\ffmpeg\bin\ffprobe" -i "%%A" -show_entries format=duration -v quiet -of csv="p=0" >>output.txt
The above produces this:
110.994375
This is great, but what I would really want is something like this as I need to import this data into a db for further processing. I need to know which file the 110.9943765 came from.
recording1.wav, 110.994375
Thanks,
Steven
All you need is to add the filename key as well.
ffprobe -i "%%A" -show_entries format=filename,duration -v quiet -of csv="p=0" >>output.txt

ffprobe reports different format depending on file extension

I am using ffprobe on Windows to identify files. The command/parameters I use are:
ffprobe -show_entries format=format_name -v quiet filename
I noticed with certain image files ffprobe reports a different format if the file name has (or does not have) and extension. For example, for a BMP image file named XXX
ffprobe -show_entries format=format_name -v quiet XXX
reports
[FORMAT]
format_name=mp3
[/FORMAT]
But, if I rename the file to XXX.BMP and rerun the command
ffprobe -show_entries format=format_name -v quiet XXX.BMP
reports
[FORMAT]
format_name=image2
[/FORMAT]
Is this behavior expected? Has anyone else encountered this issue? I am using the most recent version of ffmpeg.

Resources