Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am trying to find information about how to transcode a file into multiple outputs in one shot, but I don't seem to be able to. Most of the results I find describe the opposite: merging multiple files into one.

Here's the situation:

I have an IP webcam that takes a "dump" or raw capture (although I don't like to say 'raw' because it may be mistaken with the .raw format) that consists of two streams: An H264 video and a PCM audio.

I need to transcode that "raw/dump" capture into three MP4 files, two of them with audio and video (H264+AAC) and the third one with just the AAC audio; more specifically:

  1. A file at the same resolution than the original, ensuring it runs at 30 fps, has aac audio at 128kbps and the pixel format is yuv420p (the "dumped" video stream's pixel fomat is yuvj420p, which makes the stream in unplayable directly in Chrome... at least for now).

  2. A file with the same features as above, but half the resolution.

  3. A file containing just the AAC audio.

I have the command to get the first file working pretty well (although I someone has any comment for that one, it will be greately appreciated as well):

    /usr/bin/avconv "/home/borrajax/Videos/original.dump" \
    -acodec libvo_aacenc -ac 1 -ab 128k -ar 44100 \
    -vcodec libx264 -preset fast -r 30 -pix_fmt yuv420p \
    "/home/borrajax/Videos/transcoded.mp4"

Probably I could save some of the options, but the issue is that the camera's configuration can be modified, so I need to make sure that the resulting .mp4 has the format I need (that's why I specified so many)

My guess is that is probably good idea (I say "probably" because I don't know much anything about video encoding) trying to transcode the three files in one shot, re-using the transcoded data to save time.

For instance: the video with half the resolution of the original one will have exactly the same audio than the "big" one so there's no need to transcode it again. Obviously, same thing goes for the audio file. There shouldn't be a need to transcode three times. Also, maybe (and here, I don't know what will be better) I can also reuse the video stream. Since I need two videos with a different fps and pixel format than the original maybe it's worthy transcoding only once (like I'm already doing in the command above) and then grab that video stream that already has 30fps and yuv420p pixel format and just make its resolution half.

I guess it'll be a good idea to sum up... how can I chain (pipe?) multiple outputs with avconv, applying different options to each?

Using:

  • Ubuntu 12.04 LTS
  • avconv version 0.8.5-4:0.8.5-0ubuntu0.12.04.1

Thank you in advance!

share|improve this question
1  
Just a comment: libvo_aacenc produces rather bad quality AAC. libfdk_aac or libfaac should be preferred. –  slhck Mar 8 '13 at 8:16

1 Answer 1

up vote 1 down vote accepted

Probably the most efficient way to do this without duplicating effort would be with a script that does several things and then muxes the results to make the final files.

For example:

  1. transcode audio from original to AAC result in audio.aac

    avconv -i <input> -c:a libfaac -vn audio.aac
    
  2. transcode video from original to full resolution in temp-full-vid.mp4

    avconv -i <input> -c:v libx264 -pix_fmt yuv420p -preset fast -r 30 -an temp-full-vid.mp4
    
  3. transcode video from original to half resulution in temp-half-vid.mp4

    avconv -i <input> -c:v libx264 -pix_fmt yuv420p -preset fast -r 30 -filter:v scale=-1:ih/2 -an temp-half-vid.mp4
    
  4. mux temp-full-vid.mp4 and audio.aac into full.mp4

    avconv -i temp-full-vid.mp4 -i audio.aac -c copy -map 0 -map 1 full.mp4
    
  5. mux temp-half-vid.mp4 and audio.aac into half.mp4

    avconv -i temp-half-vid.mp4 -i audio.aac -c copy -map 0 -map 1 half.mp4
    
  6. delete temp-full-vid.mp4 and temp-half-vid.mp4

This leaves you with the 3 files full.mp4, half.mp4, and audio.aac that you're looking for with no unnecessary redoing of transcoding.

share|improve this answer
    
I added some example commands. Not tested with avconv, but they should work in latest ffmpeg. In case of troubles, users should compile the real FFmpeg from source. –  slhck Mar 8 '13 at 8:22

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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