56

I have a video for which I'd like to convert the audio codec to AAC 320 kbps / 44.100 kHz. What would I use for ffmpeg switches such that all the video settings and codec remain the same, but only the audio codec and settings change?

Here's my video:

$ ffmpeg -i Winnipeg.rb\ Scala-Talk.mov 
FFmpeg version SVN-r25375, Copyright (c) 2000-2010 the FFmpeg developers
  built on Oct  6 2010 13:02:41 with gcc 4.2.1 (Apple Inc. build 5664)
  configuration: --enable-libmp3lame --enable-shared --disable-mmx --arch=x86_64
  libavutil     50.32. 2 / 50.32. 2
  libavcore      0. 9. 1 /  0. 9. 1
  libavcodec    52.92. 0 / 52.92. 0
  libavformat   52.80. 0 / 52.80. 0
  libavdevice   52. 2. 2 / 52. 2. 2
  libavfilter    1.48. 0 /  1.48. 0
  libswscale     0.12. 0 /  0.12. 0

Seems stream 0 codec frame rate differs from container frame rate: 2000.00 (2000/1) -> 10.00 (10/1)
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'Winnipeg.rb Scala-Talk.mov':
  Metadata:
    major_brand     : qt  
    minor_version   : 537199360
    compatible_brands: qt  
  Duration: 01:10:53.00, start: 0.000000, bitrate: 283 kb/s
    Stream #0.0(eng): Video: h264, yuv420p, 800x598, 94 kb/s, 10 fps, 10 tbr, 1k tbn, 2k tbc
    Stream #0.1(eng): Audio: adpcm_ima_qt, 22050 Hz, 1 channels, s16
    Stream #0.2(eng): Audio: adpcm_ima_qt, 22050 Hz, 1 channels, s16
At least one output file must be specified

Many thanks in advance! One thing with ffmpeg I've never been able to grok is how to just "tweak" files without having to regurgitate every little setting for things you don't want changed.

1
  • The audio (as well as the video) appears to be fairly low quality. Note that you won't actually increase the quality of the audio by changing format, increasing sampling rate, and increasing bitrate.
    – Force Flow
    Nov 27, 2010 at 1:18

4 Answers 4

84

An aggregation of Ehsan's answer with fletom's comment that works for me, thanks to both.

ffmpeg -i input.avi -acodec mp3 -vcodec copy out.avi
3
  • 2
    just for self reference since I always forget this -vcodec copy part
    – igorushi
    May 29, 2016 at 18:27
  • 3
    Can you expand your answer a little to explain it? Thanks.
    – fixer1234
    May 29, 2016 at 19:12
  • 4
    -i input.avi specifies the file you want to convert. out.avi is the converted file. -acodec mp3 says to convert the audio stream to mp3 while writing it to the output file. vcodec copy says to just copy the video stream into the output file without changing it.
    – Wodin
    Dec 13, 2016 at 20:46
11

If you just want to change the audio and/or video codec(s) you could just add them as parameters like so:

Just change the audio codec to mp3 (what ever the original codec was)

ffmpeg -i input.avi -vcodec copy -acodec mp3 out.avi

Just change the video codec to h264

ffmpeg -i input.avi -vcodec h264 out.avi

It's good to note that ffmpeg must support encoding of the new codec. See https://stackoverflow.com/questions/3377300/what-are-all-codecs-supported-by-ffmpeg

2
  • 6
    This worked for me, but I needed to add -vcodec copy in order to prevent it from trying to transcode my video into h.264. Dunno why it did that by default.
    – fletom
    Jan 14, 2016 at 5:29
  • Yeh the first line actually re-encodes video don't use it
    – malhal
    Jun 14, 2020 at 21:00
10

Hard to judge what you are doing, since the ffmpeg command was a bit garbled in your post.

To replace an audio track:

ffmpeg -i test.avi -i normalized.mp3 -map 0:0 -map 1:0 -vcodec copy -acodec copy new_test.avi

More information about the above parameters is found in: FFmpeg Documentation.

1
  • 1
    Thanks. This solved my problem. When I run ffmpeg -i old.mkv -i onlySound.m4a out.mkv the operation takes way longer. Why is that soo? Jun 25, 2018 at 9:05
-4

Why don't you use Handbrake which lets keep the video and change the audio and it is a GUI for FFmpeg and it works like a charm.

1
  • 5
    HandBrake actually can't do this; it can do a simple copy of audio or subtitle streams, but it always re-encodes the video.
    – evilsoup
    Dec 19, 2012 at 12:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .