Question

I have an s3 bucket with several hundreds video files.
Those files were created by cutting parts of larger video files using ffmpeg.
I wrote a script for this, which downloads the original video file from another bucket, runs ffmpeg to cut the file, and uploads the new file to it's bucket. For downloading and uploading from/to s3 i used this php library.
The ffmpeg syntax I used:

ffmpeg -y -vsync 2 -async 1 -ss [time-in] -t [duration] -i [large-input-video.mp4] -vcodec copy -acodec copy [short-output-video.mp4]

Which should just cut the original file between the specified times, without any changes to the a/v codecs.
All the original video files are encoded in h.264, and this is also the required encoding for the new files (which will be streamed through a CDN to the clients' flash players).

My problem is that only a small part of the new files are coming out as encoded in h.264, but most of them aren't (h.264 is a must, otherwise the files wont play on the clients' side).
I can't trace the problem to the original videos, since when i use the same ffmpeg command manually, with the same parameters and on the same files, the output files come out just fine. It seems arbitrary.

I use ffprobe to get information about the files' codecs.
For example:
ffprobe of one of the large (original) video files:

...
Stream #0.0(und): Video: h264, yuv420p, 640x352, 499 kb/s, 25 fps, 25 tbr, 90k tbn, 50 tbc
...

ffprobe of the corresponding new cut file:

...
Stream #0.0(und): Video: mpeg4, yuv420p, 640x352 [PAR 1:1 DAR 20:11], 227 kb/s, 25 fps, 25 tbr, 25 tbn, 25 tbc
...

As can be seen, the difference is in 'mpeg4' vs. 'h264'.

Any insights on what can cause the new files to come out in the wrong encoding would be greatly appreciated.

Thanks!

Edit: Problem Resolved
After analyzing all the files, I noticed that about two thirds of them are coming out in the wrong codec.
Since I used three machines for the cutting process (three separate EC2 servers), it occurred to me that on two of them there is a bad installation of ffmpeg (as @LordNeckbeard suggested in his answer).
I ran the process again, only on the invalid files, on the third machine alone - which produced the desired result.

Was it helpful?

Solution

The "mpeg4" on your output files most likely indicates that ffmpeg is re-encoding instead of copying the video stream. I can't say the same for the audio since you did not provide that information. Older ffmpeg uses the "mpeg4" video encoder as the default for outputs using the MP4 container. Check your script or library since everything works as expected when invoking ffmpeg manually.

Of less concern is that -vsync 2 -async 1 are probably ignored when using -vcodec copy -acodec copy.

Also note that you may want to run your cut output through qt-faststart (it's included in the ffmpeg source) or alternatively MP4Box. This will move some data to the beginning of the file so the video can begin playing before it is completely downloaded by the client.

Lastly, the placement of -ss matters. As an input option (before -i) it is much faster since it immediately seeks to your desired time and then begins decoding, but it is not as accurate as -ss as an output option which completely decodes everything before your desired time. If accuracy is more important than speed then consider testing -ss as an output option.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top