1

A Foreword: I have looked at the topics on stackoverflow related to this topic. None of them answer the question or have anything to do with the issue.

I make LP videos on YouTube. I recently started using .TS (Transport Stream) files to record with through the answer here. When extracting the second audio stream from the file through ffmpeg I end up with an audio file 7 seconds longer than the video file I used as input. The file used as input is 12:50 and the audio file is 12:57.

I believe this is due to the fact that ffmpeg is changing the bitrate of the file. The source bitrate is 167 kb/s and according to the console output ffmpeg is saving it as 164.7 kb/s.

I know I can manually define the bitrate to save as via -b:a:0 167k but I want this batch file to work with any file I give it, and the bitrate of the stream in question varies, as it's the mic/aux stream. I am writing a utility in Batch so I can just drag and drop the file to extract the second audio stream, so I'd love to avoid reading the bitrate unless there's an ffmpeg command that returns the bitrate for a specific stream in the input file that is easy to parse.

For the codec you can use -c:a:0 copy, why can't you use copy on the bitrate? To me it makes no sense.

The command I'm using to extract the audio:

ffmpeg -i "%~1" -map 0:2 -c:a:0 copy "%~n1.aac"

The entire batch file:

@echo off

REM This code checks to ensure the command-line variables have been properly set.

if [%1]==[] goto ALERT
if [%2]==[] (
    SET outpt="%~n1.aac"
    goto END_COMMENT
)
SET outpt="%~2"

GOTO END_COMMENT

------------------------------------------

The code below actually runs the extraction of the audio stream with the configured values

ffmpeg -i <input_file> -map 0:2 -c:a:0 copy <output_file>

ffmpeg -i <input_file> -map
    The base command, map tells ffmpeg that we wish to define the order of streams
    we with to operate on

0:2
    Defines the stream to work on, 0 is the input, so input 0 (the file) and 2 is the stream (0=video,1+=audio, last stream may be metadata)

-c:a:0 copy
    Codec of audio stream 0 for output should be an exact copy of all applicable settings from input stream

<output_file>
    The name of the file to output. The extension should match the codec. For most intents this will be .aac

------------------------------------------

:END_COMMENT

echo %outpt%

ffmpeg -i "%~1" -map 0:2 -c:a:0 copy %outpt%
goto END

:ALERT
@echo Incorrect usage: At least 1 param is required
@echo     ^<param^> = Required
@echo     [param] = Optional
@echo(
@echo     extract.bat ^<input_file^> [output_file]

:END
pause

At request the following file is the full output of -v 9 -loglevel 99 (I don't see how 8 MB worth of [mpegts @ Address] is useful, but here you go: https://www.dropbox.com/s/0ous9hc6e2kbyvp/log.txt?dl=0

Community
  • 1
  • 1
D3_JMultiply
  • 1,022
  • 2
  • 12
  • 22
  • can you post the full output of ffmpeg including ' -v 9 -loglevel 99' before the '-i' in the command? – user3770489 Sep 25 '15 at 09:34
  • um... when I enter that I get a log so long I can't even copy it all... It's been sconstantly printing out [mpegts @ xxxxxxxxxxxxxxxxxxxxx] for literally the last 5 minutes... – D3_JMultiply Sep 26 '15 at 02:45
  • Ok, redirected output to a log file, 8 MB of verbose data... Not sure exactly how to post that much data... Updated main post. – D3_JMultiply Sep 26 '15 at 02:52

0 Answers0