Saturday, June 16, 2018

How to avoid terminal to scroll down to last message in bash?


I write a bash script that run some other commands in new terminal:


#!/bin/bash
# Sample script
gnome-terminal --title="blah blah" -x bash -c ffmpeg -i udp://239.1.2.1:60001?fifo_size=50000000 -acodec copy -vcodec copy -preset ultrafast \
-flags -global_header -f hls -hls_time 20 -hls_wrap 5 /var/www/html/ts/1.m3u8 &
sleep 1
gnome-terminal --title="blah blah" -x bash -c ffmpeg -i udp://239.1.2.2:60002?fifo_size=50000000 -acodec copy -vcodec copy -preset ultrafast \
-flags -global_header -f hls -hls_time 20 -hls_wrap 5 /var/www/html/ts/2.m3u8

The output of each ffmpeg line is more than one page and it is similar to:


libavutil      54.  7.100 / 54.  7.100
libavcodec 56. 1.100 / 56. 1.100
libavformat 56. 4.101 / 56. 4.101
... many pages after ....
[h264 @ 0xc04c60] decode_slice_header error
[h264 @ 0xc04c60] no frame!
[h264 @ 0xc04c60] non-existing PPS 0 referenced
.... many pages after ....
Program 105
Metadata:
service_name : IRIB-TV5
service_provider: IRIB
[adts @ 0xf943e0] Using AVStream.codec.time_base as a timebase hint to the muxer is deprecated. Set AVStream.time_base instead.
Output #0, hls, to '/home/stream/Desktop/tst/1.m3u8':
Metadata:
encoder : Lavf56.4.101
Stream #0:0: Video: h264 (libx264), yuv420p, 720x576 [SAR 12:11 DAR 15:11], q=-1--1, 25 fps, 90k tbn, 25 tbc
Metadata:
encoder : Lavc56.1.100 libx264
Stream #0:1(per): Audio: aac, 48000 Hz, stereo, fltp, 128 kb/s
Metadata:
encoder : Lavc56.1.100 aac
Stream mapping:
Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
Stream #0:1 -> #0:1 (aac_latm (native) -> aac (native))
Press [q] to stop, [?] for help
[h264 @ 0xf42120] reference picture missing during reorder
[h264 @ 0xf42120] Missing reference picture, default is 65716
[h264 @ 0xf42120] reference picture missing during reorder
[h264 @ 0xf42120] Missing reference picture, default is 65717

When I run this script in a new terminal and I launch the command (in this case ffmpeg), it immediately shows many output lines, many pages sometimes, and goes to last message automatically...


How can I scroll up and down to first message in the terminal, or stop it at the first page?


Answer



Update after that the question was completely reformulated:


You can use | more or | less to stop the output after the first page.


 gnome-terminal --title="blah blah" -x bash -c  ' find  ~  | less'

Note: you need to use '' to say where it finishes the bash commands.
Within less you can move:



  • Home and End To the beginning and the end of the page.

  • PgUp and PgUp One page down or up.

  • Up and Dn One line up or down.




One of the line of your script can be similar to


gnome-terminal --title="blah blah" -x bash -c                                 \
'ffmpeg -i udp://239.1.2.1:60001?fifo_size=50000000 -acodec copy -vcodec copy \
-preset ultrafast -flags -global_header -f hls -hls_time 20 -hls_wrap 5 \
/var/www/html/ts/1.m3u8 | less ' &



There are some shortcuts:



  • Ctrl+ Shift+Up or Dn To scroll up or down of a line

  • Shift+PgUpor PgDn To scroll up or down of a page

  • Shift+Home or End To scroll up to the beginning or down to the end


You can read about other shortcuts directly on the gnome help page.


No comments:

Post a Comment

hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...