0

I wrote the following script that is meant to remove the unnecessary audio streams, aka dubbing, as well as subtitles from the movies in my collection:

#!/usr/bin/bash

echo "What is the path to the source file?"
read if
of=$(echo "${if}"|sed -E 's/(\.)([avimp4kv]{3,3}$)/\1stripped.\2/')
echo "What is the number of the audio stream that you want to copy?"
read no

ffmpeg -v 0 -i "${if}" -map 0:v -map 0:${no} "${of}"

My intent is to save on storage while preserving the original quality of both video and audio stream of my choice. I noticed that the reduction of the size of the media files is very large. For example: Todo_Sobre_Mi_Madre_(1999).avi that has 1.4GB and the following streams:

Input #0, avi, from 'Todo_Sobre_Mi_Madre_(1999).avi':
  Metadata:
    encoder         : VirtualDubMod 1.5.10.2 (build 2540/release)
  Duration: 01:41:24.67, start: 0.000000, bitrate: 1936 kb/s
    Stream #0:0: Video: mpeg4 (DX50 / 0x30355844), yuv420p, 720x304 [SAR 1:1 DAR 45:19], 1539 kb/s, 23.98 fps, 23.98 tbr, 23.98 tbn, 30k tbc
    Stream #0:1: Audio: mp3 (U[0][0][0] / 0x0055), 48000 Hz, stereo, fltp, 192 kb/s
    Stream #0:2: Audio: mp3 (U[0][0][0] / 0x0055), 48000 Hz, stereo, fltp, 192 kb/s

was converted to Todo_Sobre_Mi_Madre_(1999).stripped.avi of only 248MB with the following streams:

Input #0, avi, from 'Todo_Sobre_Mi_Madre_(1999).stripped.avi':
  Metadata:
    encoder         : Lavf58.29.100
  Duration: 01:41:24.75, start: 0.000000, bitrate: 341 kb/s
    Stream #0:0: Video: mpeg4 (Simple Profile) (FMP4 / 0x34504D46), yuv420p, 720x304 [SAR 1:1 DAR 45:19], 200 kb/s, 23.98 fps, 23.98 tbr, 23.98 tbn, 24k tbc
    Stream #0:1: Audio: mp3 (U[0][0][0] / 0x0055), 48000 Hz, stereo, fltp, 128 kb/s

I noticed the unintended reduction of the bitrate of both the video, from 1539 kb/s to just 200 kb/s and the audio stream, from 192 kb/s to just 128 kb/s. The resolution remained unchanged. What am I doing wrong? How might I utilize ffmpeg and its -map option to accomplish my goal?

1
  • 1
    Next time posting, please always include all the ffmpeg output, not just the parts you think are relevant. Thanks!
    – slhck
    Apr 21 at 15:34

1 Answer 1

1

You need to add -c copy to make ffmpeg copy the bitstreams as-is. This is also called remuxing.

Otherwise it will default to re-encoding each stream, and the chosen defaults usually mean a rather low bitrate (and, consequently a reduction in quality.)

For more info, see the FFmpeg wiki entry on selecting streams.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.