ffprobe - getting file info from pipe
Asked Answered
P

3

13

I've got an oog file (it was mixed by sox from two audiostreams recorded by pbx Asterisk) and I'm trying to get file information with ffprobe. When I use something like

cat %filename%.ogg | ffprobe -i - 

I get invalid file info (Duration : N/A, wrong bitrate and etc.) When I try

ffprobe -i %filename%

Everything works fine and I get file info. What could be wrong? File content?

Properly answered 7/12, 2012 at 12:24 Comment(2)
I know its over 4 years later but I was trying to recently do something similar and you can't. Most formats need to read the whole file to work out the duration, which is why specifying the direct filename works because it has access to that - and ffprobe would need to be changed ! Very annoying! You can do something with ffmpeg but it would mean reading the whole file: ffmpeg -i pipe:0 -f null /dev/null < inputfile.mp4Vanhorn
I just got hit by this. Why did they close the ticket on ffmpeg?Thought
R
5

Just a quick note to say that piping input to ffprobe seems to work just fine. Use a hyphen in place of the input file and you are off to the races. Here is an example with a random video file on my system:

cat 01.mp4 | ffprobe -show_format -pretty -loglevel quiet -

Returns:

[FORMAT]
filename=pipe:
nb_streams=2
nb_programs=0
format_name=mov,mp4,m4a,3gp,3g2,mj2
format_long_name=QuickTime / MOV
start_time=N/A
duration=0:02:56.400000
size=N/A
bit_rate=N/A
probe_score=100
TAG:major_brand=isom
TAG:minor_version=512
TAG:compatible_brands=isomiso2mp41
TAG:creation_time=1970-01-01T00:00:00.000000Z
TAG:title=yy.mp4
TAG:encoder=Lavf52.78.3
[/FORMAT]
Representational answered 14/2, 2018 at 20:6 Comment(1)
bit_rate is absent if input is a pipe and present if input is a file. any thoughts on this ?Emeliaemelin
P
3

As of version 1.0.7 of ffprobe you can even get the output in a JSON formatted output:

ffprobe -v quiet -print_format json -show_format Ramp\ -\ Apathy.mp3

Which produces the follwing output:

{
    "format": {
        "filename": "Ramp - Apathy.mp3",
        "nb_streams": 2,
        "format_name": "mp3",
        "format_long_name": "MP2/3 (MPEG audio layer 2/3)",
        "start_time": "0.000000",
        "duration": "203.638856",
        "size": "4072777",
        "bit_rate": "159999",
        "tags": {
            "title": "Apathy",
            "artist": "Ramp",
            "album": "Evolution Devolution Revolution",
            "date": "1999",
            "genre": "Metal"
        }
    }
}

I think you can get the probe using cat, do you have any requirement to cat the file contents? If not just use ffprobe without cat.

Persas answered 28/5, 2013 at 22:45 Comment(3)
He specifically asks for input from pipe - not a file! Thanks, but is useless, he said he had the duration with file input...Vanhorn
This is the answer to the other question. Question: "how to read from pipe", answer: "you can use JSON format", strange, isn't it? I've checked the history of edits - question didn't change. (stackoverflow.com/posts/13763047/revisions)Goldengoldenberg
I can't send the nicely formatted json to another file using either stdout 1> or stderr 2>. -o output.file.json is rejected as an unknown option. Any ideas?Setzer
T
0

And you can pipeline it from remote site by curl

curl  --silent --header "Range: bytes=0-51200" https://example.com/your.mp4 | ffprobe -v quiet -show_format -of flat=s=_ -show_entries stream=height,width,nb_frames,duration,codec_name -
Tahoe answered 28/2, 2022 at 12:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.