LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 01-14-2024, 02:42 PM   #1
jpifer
LQ Newbie
 
Registered: Mar 2006
Posts: 4

Rep: Reputation: 0
grep and use multiple lines from output


I'm trying to grep for info from ffmpeg, then use that to re-run ffmpeg. Hoping someone can help me combine this and make it work.

If I run this:
ffmpeg -i "input.mkv" 2>&1 | grep "Stream #" | grep eng

I get this for example:
Stream #0:2(eng): Audio: ac3, 48000 Hz, 5.1(side), fltp, 448 kb/s
Stream #0:4(eng): Subtitle: hdmv_pgs_subtitle

I would like to pull the 0:2 and 0:4 (or more of them if there are) then run ffmpeg again using them as parameters.

Any help is appreciated.

Thank!
 
Old 01-14-2024, 09:52 PM   #2
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,152

Rep: Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125
I'd be mighty surprised if there isn't an option to get (only) that data directly from ffmpeg itself. It seems to have all the bells and whistles - others will be able to answer that.
If I had to do it without that knowledge I'd use sed. Something like this should work - presumes exactly the layout above, no exceptions.
Code:
ffmpeg -i "input.mkv" 2>&1 | sed -rn 's/Stream #([0-9]+:[0-9]+).eng.+/\1/p'

Last edited by syg00; 01-15-2024 at 03:32 AM. Reason: closing quote
 
Old 01-14-2024, 11:03 PM   #3
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,353
Blog Entries: 3

Rep: Reputation: 3766Reputation: 3766Reputation: 3766Reputation: 3766Reputation: 3766Reputation: 3766Reputation: 3766Reputation: 3766Reputation: 3766Reputation: 3766Reputation: 3766
There is also ffprobe.

Code:
ffprobe -show_streams -select_streams v input.mkv

ffprobe -show_streams -select_streams v:1 input.mkv
etc.
 
Old 01-17-2024, 12:40 PM   #4
jpifer
LQ Newbie
 
Registered: Mar 2006
Posts: 4

Original Poster
Rep: Reputation: 0
Thanks for the help. Your replies got me on a good track.
 
  


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
[SOLVED] How to use grep to pull certain lines of a command output SteveThePirate87 Programming 12 10-30-2012 06:13 PM
Creating an alias in ksh that uses grep and includes 'grep -v grep' doug248 Linux - Newbie 2 08-05-2012 02:07 PM
[SOLVED] CAT command | multiple lines to multiple lines udiubu Programming 11 10-28-2011 06:09 AM
use grep to match multiple lines noony123 Linux - Newbie 2 02-03-2011 04:47 AM
grep output on stdout and grep output to file don't match xnomad Linux - General 3 01-13-2007 04:56 AM

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

All times are GMT -5. The time now is 07:24 AM.

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