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 extract a small part from a larger video without changing the codecs, resolution or something else. Therefore, I use FFmpeg with the following settings.

ffmpeg -vcodec copy -acodec copy -ss 01:00:00 -t 00:00:30 -metadata title="Custom title" -metadata artist="Artist Name" -metadata language="English" -i input_file_h264.mp4 output_file.mp4

I am processing the video on Ubuntu 10.10. with FFmpeg version 0.6-4:0.6-2ubuntu6.2.

The output file comes with the same codec information as the input file. Though, it does open up in VLC and other media player as if the resolution of the video changed. The input source comes with a resolution of 720x576. The codec used is H264 - MPEG-4 AVC (part 10) (avc1). When the output video opens up it appears wider (16:9) although the video settings did not change.
I could not find anything like aspect ratio misconfigured in VLC also.

Do you know of a problem with H264 on Ubuntu? As far as I understand libx264 is used. But is that relevant when I simple slice a video?


As suggested by slhck I changed the order of arguments.

ffmpeg -ss 01:00:00 -i 28c3-4906-en-lightning_talks_day_3_pecha_kucha_h264.mp4 -vcodec copy -acodec copy -t 00:00:30 output_file_slhck.mp4
share|improve this question
1  
I can't reproduce the error. It works without problems for me. Please update to FFmpeg 0.9 or newer as explained here and try again. It should just work. –  slhck Dec 31 '11 at 14:31
    
I updated FFmpeg and used the argument order as you suggested. Now it works perfectly! Thank you! –  JJD Dec 31 '11 at 15:13
    
Glad I could help! –  slhck Dec 31 '11 at 16:16
add comment

1 Answer

up vote 2 down vote accepted

You're not really copying the video stream.

Supply the acodec and vcodec options after the i option. Just think about how you would process them. First read the file, then decide how to encode, then output. If you don't do this, the options will be parsed differently1, which would explain the difference in input and output according to your log:

Input:  Stream #0.0(und): Video: h264, yuv420p, 720x576 [PAR 64:45 DAR 16:9]
Output: Stream #0.0(und): Video: libx264, yuv420p, 720x576 [PAR 89:44 DAR 445:176]

Note the difference in Pixel Aspect Ratio (PAR)? Currently, you're trying to decode the video with the copy codec, which obviously does not exist. Placement of options in FFmpeg really matters sometimes.2

This is also what the manual says:

Select an encoder (when used before an output file) or a decoder (when used before an input file) for one or more streams

So, to summarize — metadata left out for readability:

ffmpeg -ss 01:00:00 -i input_file_h264.mp4 -vcodec copy -acodec copy -t 00:06:00 output_file.mp4

1 – With newer versions of FFmpeg, the command would have failed because a copy decoder does not exist.

2 – Also, place the t option after the encoding process, and leave ss at the beginning. Putting ss at the beginning ensures that the file is read up until the time, and then begins encoding. If you were to place ss after i, that would encode the file from the beginning on, which could take a long time.

share|improve this answer
    
Sorry, it does not work. Also, imho that would be quite bad if FFmpeg does not optimize the order of parameters. –  JJD Dec 31 '11 at 14:03
    
@JJD The order of parameters does matter. It's just not very evident from the manual. With FFmpeg 0.9, placing the vcodec or acodec options before i results in the Unknown decoder 'copy' error because it tries to decode the input file with this, not encode the output file. Please update your FFmpeg version and try again! –  slhck Dec 31 '11 at 14:05
    
I expected that the aspect ratio does not change since I did not configure it to do so. Is there no way to force FFmpeg to keep the aspect ratio? -- I do not want to offend you but the fact that I have to put the arguments in a certain order is very user-unfriendly. –  JJD Dec 31 '11 at 14:12
1  
I'm looking into it. Anyway, you have to put them in a different order because the meaning changes. Placing them before means that you want to force a certain decoder for the input video, while placing them after means that you want to force a certain encoder for the output video. See in the FFmpeg manual under the -codec option: > Select an encoder (when used before an output file) or a decoder (when used before an input file) for one or more streams. –  slhck Dec 31 '11 at 14:15
    
As for the aspect ratio: If you use vcodec copy at the right position, it should leave the video (and its aspect ratio) untouched. If you still have problems, please append the output of the new command to your question. You can manually adjust the aspect ratio with the -aspect option (see manual for usage). –  slhck Dec 31 '11 at 14:16
add comment

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.