Precisa de ajuda com o script bash do MPV

2

Basicamente, eu tento editar um script bash. A meta do Script é permitir que eu tire um monte de screenshots de vídeos simplesmente iniciando-o no terminal, tendo apenas que especificar o nome do arquivo e a captura de tela Number desejada. Eu trabalhei alguns bugs, mas estou tendo problemas com a obtenção de MPV para atribuir o nome do arquivo que eu quero.

Este é o script atual.

#!/bin/bash


### Global variables
filename=""

### Error handling
if [ -z ${filename} ]; 
then
    echo "ERROR: No video file supplied. Please enter a video file as argument."
    exit 1;
fi

NUM_OF_SCREENSHOTS=9
if [ ! -z  ]; 
then
  NUM_OF_SCREENSHOTS=
  echo "WARNING: Overwrite default number of screenshots to ${NUM_OF_SCREENSHOTS}."
  sleep 3s
fi




# Get the total length of the video in seconds.
#  Use mplayer to display the info of the video and then get the value of ID_LENGTH, the total number of seconds of the video.
total_length=$(mplayer -identify -frames 0 -vc null -vo null -ao null "$filename" | grep ID_LENGTH | sed 's/ID_LENGTH=//' | sed 's/\..*//')
# Reference https://github.com/mpv-player/mpv/blob/master/TOOLS/mpv_identify.sh

# Remove 4 seconds from the video so that it doesn't take screenshot at the ends.
let total_length-=4

# time_slice: At which time interval should mplayer take screenshots.
let time_slice=${total_length}/${NUM_OF_SCREENSHOTS}

# time_at: When should mplayer take screenshots.
time_at=${time_slice};

# Looping to take screenshots.
for ((i=1; i <= NUM_OF_SCREENSHOTS ; i++))
do


  # Take the screenshot.
  #mplayer -loop 1 -nosound -frames 1 -ss ${time_at} -vo png:z=9 ${filename}
  mpv --quiet --no-audio --vo=image --screenshot-template="%f %n" --start=${time_at} --frames=1 "$filename" 

  # Increment to the next time slice.
  let time_at+=${time_slice}



done
    
por wisperer 13.10.2015 / 05:33

1 resposta

0

O script não pode funcionar dessa maneira. O script é muito bom, embora você deva fazer pequenas melhorias (Use ShellCheck para isso.)

O problema é que mpv usa um contador interno para nomear o arquivo de captura de tela ( %n ). E o contador é resetado a cada passagem do loop.

O script modificado abaixo renomeia o arquivo.

#!/usr/bin/env bash

### Global variables
filename=""

### Error handling
if [ -z "${filename}" ]; 
then
    echo "ERROR: No video file supplied. Please enter a video file as argument."
    exit 1;
fi

NUM_OF_SCREENSHOTS=9
if [ ! -z "" ]; 
then
  NUM_OF_SCREENSHOTS=
  echo "WARNING: Overwrite default number of screenshots to ${NUM_OF_SCREENSHOTS}."
  sleep 3s
fi

# Get the total length of the video in seconds.
#  Use mplayer to display the info of the video and then get the value of ID_LENGTH, the total number of seconds of the video.
total_length=$(mplayer -identify -frames 0 -vc null -vo null -ao null "$filename" | grep ID_LENGTH | sed 's/ID_LENGTH=//' | sed 's/\..*//')
# Reference https://github.com/mpv-player/mpv/blob/master/TOOLS/mpv_identify.sh

# Remove 4 seconds from the video so that it doesn't take screenshot at the ends.
let total_length-=4

# time_slice: At which time interval should mplayer take screenshots.
let time_slice=${total_length}/${NUM_OF_SCREENSHOTS}

# time_at: When should mplayer take screenshots.
time_at=${time_slice};

# Looping to take screenshots.
for ((i=1; i <= NUM_OF_SCREENSHOTS ; i++))
do

  # Take the screenshot.
  #mplayer -loop 1 -nosound -frames 1 -ss ${time_at} -vo png:z=9 ${filename}
  mpv --quiet --no-audio --vo=image --start=${time_at} --frames=1 "$filename" 
  rename 's/^[0-9]+/out'"${time_at}"'/' 00000001.jpg

  # Increment to the next time slice.
  let time_at+=${time_slice}

done

exit 0
    
por A.B. 15.10.2015 / 08:34