Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 763679
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T16:36:04+00:00 2026-05-14T16:36:04+00:00

I have a batch conversion script to turn .mkvs of various dimensions into ipod/iphone

  • 0

I have a batch conversion script to turn .mkvs of various dimensions into ipod/iphone sized .mp4s, cropping/scaling to suit. Determining the original dimensions, required crop, output file is all working fine. However, on successful completion of the first conversion, HandbrakeCLI causes the parent script to exit. Why would this be? And how can I stop it?

The code, as it currently stands:

#!/bin/bash
find . -name "*.mkv" | while read FILE
do
    # What would the output file be?
    DST=../Touch/$(dirname "$FILE")
    MKV=$(basename "$FILE")
    MP4=${MKV%%.mkv}.mp4

    # If it already exists, don't overwrite it
    if [ -e "$DST/$MP4" ]
    then
        echo "NOT overwriting $DST/$MP4"
    else

        # Stuff to determine dimensions/cropping removed for brevity

        HandbrakeCLI --preset "iPhone & iPod Touch" --vb 900 --crop $crop -i "$FILE" -o "$DST/$MP4" > /dev/null 2>&1

        if [ $? != 0 ]
        then
            echo "$FILE had problems" >> errors.log  
        fi
     fi
done

I have additionally tried it with a trap, but that didn’t change the behaviour (although the last trap did fire)

trap "echo Handbrake SIGINT-d"  SIGINT
trap "echo Handbrake SIGTERM-d" SIGTERM
trap "echo Handbrake EXIT-d"    EXIT
trap "echo Handbrake 0-d"       0

Edited to add:

The fact that the ‘0’ trap fired prompted me to investigate why that might be. Executing as bash -x $script revealed that the find | while read loop is ending prematurely.

I’ve re-factored the find and encode into separate scripts. The find loop is now:

find . -name "*.mkv" | while read FILE
do
    handbrake-touch "$FILE"

    if [ $? != 0 ]
    then
        echo "$FILE had problems" >> errors.log  
    fi
done

The behaviour remains the same – one encode followed by the while loop ending. If I just put an ‘echo $FILE’ in place of the ‘handbrake-touch’, all the files are listed. The current directory doesn’t change (I was wondering what might break the find | while).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T16:36:04+00:00Added an answer on May 14, 2026 at 4:36 pm

    Now resolved, thanks to a clue from this other thread. I now echo nothing into HandbrakeCLI to ensure it’s not using the same stdin as my script:

    find . -name "*.mkv" | while read FILE
    do
        echo "" | handbrake-touch "$FILE"
    
        if [ $? != 0 ]
        then
            echo "$FILE had problems" >> errors.log  
        fi
    done
    

    …and it works as intended/expected.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a batch script that triggers vlc for me on my network, the
I have a batch script on an EC2 instance that I would like to
I have a batch file (in windows XP, with command extension activated) with the
I have a batch file that was created for an Oracle database that I'm
For example, suppose I have a batch file called 'test.cmd' and it simply contains:
I have a few batch files I need to run frequently in developing a
We have 50+ Java batch processes that run at different times of the day.
I have a nightly batch job that can tell if it has failed. I
I have a daily batch process that involves selecting out a large number of
Is there any way to have a Windows batch file directly input SQL statements

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.