Zenity --progress from Handbrake CLI output

久未见 提交于 2019-12-06 03:40:10

问题


My goal is to create a gtk progress bar with the output of HandBrakeCLI using zenity --progress. I've ran into some snags and I'm wondering if someone knows of a better way or can help me with what I'm currently doing.

Normal Output:

HandBrakeCLI -i infile -o outfile --preset=iPad

Displays

Encoding: task 1 of 1, 11.97 % (72.81 fps, avg 86.78 fps, ETA 00h00m43s)

HandBrake piped to tr and cut commands so I only have the percentages that zenity will expect.

HandBrakeCLI -i infile -o outfile --preset=iPad 2>&1 | tr -s '\r' '\n' | cut -b 24-28

Results in what I would expect:

1.05 
1.06 
1.10 
1.10

But, the output is delayed a lot and sometimes won't even display. If I only use my tr expression I get the output above on each line but it's the whole output including "Encoding: task......".

It's like the cut command can't keep up with the std out of Handbrake. I read up on using named pipes, created one and directed HandBrake's output to the pipe then in another terminal tried the tr and cut command via the pipe and it results in the same delay.

Using awk's print substring also results in the same delay.

I can't figure it out. I'm after the zenity --progress indicator because my HandBrake job is called as a MythTV job and I'd like a progress bar to pop up so I know when and an encode is in process.


回答1:


You can use the solutions answered here on stackexchange.

For example:

The stdbuf program which is part of the GNU coreutils.

stdbuf -i0 -o0 -e0 command

Another example is the expect command unbuffer, e.g.

unbuffer long_running_command | print_progress

unbuffer connects to long_running_command via a pseudoterminal (pty), which makes the system treat it as an interactive process, therefore not using the 4-kiB buffering in the pipeline that is the likely cause of the delay.

For longer pipelines, you may have to unbuffer each command (except the final one), e.g.

unbuffer x | unbuffer -p y | z



回答2:


Using UNBUFFER suggested by erik to use with your first post, the following command do the trick :

( HandBrakeCLI -i infile -o outfile --preset=iPad | 
        unbuffer -p grep -i "encoding: task " | 
        unbuffer -p cut -c24-25 ) | 
        zenity --progress --auto-close


来源:https://stackoverflow.com/questions/13691884/zenity-progress-from-handbrake-cli-output

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!