FFprobe scripting question

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

FFprobe scripting question

Rodney Baker
Hi all. Is there an easy way to use FFprobe in a script to get just the size
or bitrate of a video stream? I have a video conversion script using FFmpeg
and I want to make a decision on encoding bitrate based on whether or not the
original stream is a HD (1440x1080) or SD (720x576) stream (as recorded from a
dvb-t card).

I know I could probably do it using something like

ffprobe -show_streams 2>/dev/null  |  grep 'width'

and then strip off the "width=" string but I was kind of hoping there might be
an easier way to do it.

Thanks in advance,
Rodney.

--
==========================================================================
Rodney Baker VK5ZTV
[hidden email]
==========================================================================
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user
Reply | Threaded
Open this post in threaded view
|

Re: FFprobe scripting question

Adam Klobukowski
2012/6/15 Rodney Baker <[hidden email]>:

> Hi all. Is there an easy way to use FFprobe in a script to get just the size
> or bitrate of a video stream? I have a video conversion script using FFmpeg
> and I want to make a decision on encoding bitrate based on whether or not the
> original stream is a HD (1440x1080) or SD (720x576) stream (as recorded from a
> dvb-t card).
>
> I know I could probably do it using something like
>
> ffprobe -show_streams 2>/dev/null  |  grep 'width'
>
> and then strip off the "width=" string but I was kind of hoping there might be
> an easier way to do it.

I had the same problem, and found mplayer much easier for this task.

My code (bash):

TEST=`mplayer -msglevel identify=6 -frames 0 "$NAME" 2>&1 | grep -e
"ID_AUDIO_BITRATE="`
BITRATE=$(trim `echo "$TEST" | cut -d= -f2`)


--
Semper Fidelis

Adam Klobukowski
[hidden email]
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user
Reply | Threaded
Open this post in threaded view
|

Re: FFprobe scripting question

Clément Bœsch
In reply to this post by Rodney Baker
On Fri, Jun 15, 2012 at 05:05:11PM +0930, Rodney Baker wrote:

> Hi all. Is there an easy way to use FFprobe in a script to get just the size
> or bitrate of a video stream? I have a video conversion script using FFmpeg
> and I want to make a decision on encoding bitrate based on whether or not the
> original stream is a HD (1440x1080) or SD (720x576) stream (as recorded from a
> dvb-t card).
>
> I know I could probably do it using something like
>
> ffprobe -show_streams 2>/dev/null  |  grep 'width'
>
> and then strip off the "width=" string but I was kind of hoping there might be
> an easier way to do it.
>
ffprobe -v 0 -show_streams | grep width

You can also look at the different output formats such as JSON or flat
("-of json"), which might be easier to interface with your app. The
"compact" also makes possible to strip off the keys IIRC. You can also use
eval in your shell to assign the value.

There is a -show_format_entry option, but nothing for streams, you might
want to open a feature request for this.

[...]

--
Clément B.

_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

attachment0 (501 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: FFprobe scripting question

Clément Bœsch
On Fri, Jun 15, 2012 at 05:47:39PM +0200, Clément Bœsch wrote:

> On Fri, Jun 15, 2012 at 05:05:11PM +0930, Rodney Baker wrote:
> > Hi all. Is there an easy way to use FFprobe in a script to get just the size
> > or bitrate of a video stream? I have a video conversion script using FFmpeg
> > and I want to make a decision on encoding bitrate based on whether or not the
> > original stream is a HD (1440x1080) or SD (720x576) stream (as recorded from a
> > dvb-t card).
> >
> > I know I could probably do it using something like
> >
> > ffprobe -show_streams 2>/dev/null  |  grep 'width'
> >
> > and then strip off the "width=" string but I was kind of hoping there might be
> > an easier way to do it.
> >
>
> ffprobe -v 0 -show_streams | grep width
>
> You can also look at the different output formats such as JSON or flat
> ("-of json"), which might be easier to interface with your app. The
> "compact" also makes possible to strip off the keys IIRC. You can also use
> eval in your shell to assign the value.
>
> There is a -show_format_entry option, but nothing for streams, you might
> want to open a feature request for this.
>
More info about the writers and their options here:
http://ffmpeg.org/ffprobe.html#Writers

--
Clément B.

_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

attachment0 (501 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: FFprobe scripting question

Stefano Sabatini-2
In reply to this post by Clément Bœsch
On date Friday 2012-06-15 17:47:39 +0200, Clément Bœsch encoded:

> On Fri, Jun 15, 2012 at 05:05:11PM +0930, Rodney Baker wrote:
> > Hi all. Is there an easy way to use FFprobe in a script to get just the size
> > or bitrate of a video stream? I have a video conversion script using FFmpeg
> > and I want to make a decision on encoding bitrate based on whether or not the
> > original stream is a HD (1440x1080) or SD (720x576) stream (as recorded from a
> > dvb-t card).
> >
> > I know I could probably do it using something like
> >
> > ffprobe -show_streams 2>/dev/null  |  grep 'width'
> >
> > and then strip off the "width=" string but I was kind of hoping there might be
> > an easier way to do it.
> >
>
> ffprobe -v 0 -show_streams | grep width

Another variant:
ffprobe INPUT -show_streams -print_format default=nk=1:nw=1 | sed -n 9p
--
ffmpeg-user random tip #23
FFmpeg FAQs (and answers):
http://ffmpeg.org/faq.html
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user
Reply | Threaded
Open this post in threaded view
|

Re: FFprobe scripting question

Rodney Baker
On Sat, 16 Jun 2012 08:33:11 Stefano Sabatini wrote:
> -show_streams -print_format default=nk=1:nw=1 | sed -n 9p

Thanks Adam, Clement and Stefano. This produces the required result (but I
still need to redirect stderr to /dev/null to get just the numeric answer that
I'm looking for).

A slight modification to sed -n 8,9p prints both horizontal and vertical
pixels which is even better. :-)

Now I just need to learn how to do arrays in bash (or learn another
programming language other than Visual Basic) so I can do something useful
with the rest of the output that I'm currently throwing away. :-)

Have a great weekend!
Rodney.

--
==========================================================================
Rodney Baker VK5ZTV
[hidden email]
==========================================================================
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user
Reply | Threaded
Open this post in threaded view
|

Re: FFprobe scripting question

Clément Bœsch
On Sat, Jun 16, 2012 at 11:48:38AM +0930, Rodney Baker wrote:

> On Sat, 16 Jun 2012 08:33:11 Stefano Sabatini wrote:
> > -show_streams -print_format default=nk=1:nw=1 | sed -n 9p
>
> Thanks Adam, Clement and Stefano. This produces the required result (but I
> still need to redirect stderr to /dev/null to get just the numeric answer that
> I'm looking for).
>
> A slight modification to sed -n 8,9p prints both horizontal and vertical
> pixels which is even better. :-)
>
This is not reliable if we add entries.

> Now I just need to learn how to do arrays in bash (or learn another
> programming language other than Visual Basic) so I can do something useful
> with the rest of the output that I'm currently throwing away. :-)
>

If you're scripting with bash I would suggest something like this:

% ./ffprobe -v 0 INPUT -show_streams -of flat=s=_:h=0 | grep -E '(width|height)'
stream_0_width=1280
stream_0_height=720

And eval that output, so you can directly access the information with
$stream_0_width and $stream_0_height.

--
Clément B.

_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

attachment0 (501 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: FFprobe scripting question

Clément Bœsch
On Sat, Jun 16, 2012 at 03:04:28PM +0200, Clément Bœsch wrote:

> On Sat, Jun 16, 2012 at 11:48:38AM +0930, Rodney Baker wrote:
> > On Sat, 16 Jun 2012 08:33:11 Stefano Sabatini wrote:
> > > -show_streams -print_format default=nk=1:nw=1 | sed -n 9p
> >
> > Thanks Adam, Clement and Stefano. This produces the required result (but I
> > still need to redirect stderr to /dev/null to get just the numeric answer that
> > I'm looking for).
> >
> > A slight modification to sed -n 8,9p prints both horizontal and vertical
> > pixels which is even better. :-)
> >
>
> This is not reliable if we add entries.
>
> > Now I just need to learn how to do arrays in bash (or learn another
> > programming language other than Visual Basic) so I can do something useful
> > with the rest of the output that I'm currently throwing away. :-)
> >
>
> If you're scripting with bash I would suggest something like this:
>
> % ./ffprobe -v 0 INPUT -show_streams -of flat=s=_:h=0 | grep -E '(width|height)'
> stream_0_width=1280
> stream_0_height=720
>
> And eval that output, so you can directly access the information with
> $stream_0_width and $stream_0_height.
>
Complete example:

    % cat res.sh
    #!/bin/bash
    eval $(ffprobe -v 0 $1 -show_streams -of flat=s=_:h=0 | grep -E 'width|height')
    printf "${stream_0_width}x${stream_0_height}\n"

    % ./res.sh big_buck_bunny_1080p_h264.mov
    1920x1080

Note: flat output is fairly recent and you may need to upgrade your
FFmpeg.

--
Clément B.

_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

attachment0 (501 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: FFprobe scripting question

Rodney Baker
In reply to this post by Rodney Baker
On Sat, 16 Jun 2012 22:40:48 Clément Bœsch wrote:
[...]

> > If you're scripting with bash I would suggest something like this:
> >
> > % ./ffprobe -v 0 INPUT -show_streams -of flat=s=_:h=0 | grep -E
> > '(width|height)' stream_0_width=1280
> > stream_0_height=720
> >
> > And eval that output, so you can directly access the information with
> > $stream_0_width and $stream_0_height.
>
> Complete example:
>
>     % cat res.sh
>     #!/bin/bash
>     eval $(ffprobe -v 0 $1 -show_streams -of flat=s=_:h=0 | grep -E
> 'width|height') printf "${stream_0_width}x${stream_0_height}\n"
>
>     % ./res.sh big_buck_bunny_1080p_h264.mov
>     1920x1080
>
> Note: flat output is fairly recent and you may need to upgrade your
> FFmpeg.

Excellent, thanks Clement. I usually keep within a couple of weeks of git head
so should be OK there. My bash scripting skills are very basic - I've only
just learned how to do command line parameter parsing (and even then only
using short options so far) so the example is much appreciated.

FWIW, here is the script in its current form (testing it as I type this).

Regards,
Rodney.
--
======================================================
Rodney Baker
[hidden email]
web: www.jeremiah31-10.net
======================================================

--
==========================================================================
Rodney Baker VK5ZTV
[hidden email]
==========================================================================

_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

convert_video_files (4K) Download Attachment