ffmpeg highest quality mp4 to mpg - ffmpeg

I have a mp4 video that I need to convert to mpg (for windows PowerPoint2010)
I have been trying to get best quality. But I keep getting error:
[mpeg # 0x2523620] buffer underflow st=0 bufi=420177 size=445860
[mpeg # 0x2523620] packet too large, ignoring buffer limits to mux it
[mpeg # 0x2523620] buffer underflow st=0 bufi=420177 size=445860
[mpeg # 0x2523620] buffer underflow st=0 bufi=422218 size=445860
Could someone help me with the syntax for best quality ouput to mpg. Here is the output of the mp4 file:
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'video.mp4':
Metadata:
major_brand : mp42
minor_version : 0
compatible_brands: mp41isom
creation_time : 2016-06-10 11:15:06
Duration: 00:04:20.86, start: 0.000000, bitrate: 18677 kb/s
Stream #0:0(und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 1920x1080, 18541 kb/s, 29.97 fps, 29.97 tbr, 29970 tbn, 59.94 tbc (default)
Metadata:
creation_time : 2016-06-10 11:15:06
handler_name : VideoHandler
encoder : AVC Coding
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 132 kb/s (default)
Metadata:
creation_time : 2016-06-10 11:15:06
handler_name : SoundHandler
I have tried the following but keep getting that error:
ffmpeg -i video.mp4 -c:v libx264 -c:a copy -qp 5 video.mpg
ffmpeg -i video.mp4 -c:v libx264 -c:a copy -qscale:v 1 video.mpg
ffmpeg -i video.mp4 -c:v libx264 -crf 0 -c:a copy -bf 2 -flags qprd -flags mv0 video.mpg
ffmpeg -i video.mp4 -c:v libx264 -crf 0 -c:a copy video.mpg
ffmpeg -i video.mp4 -c:v libx264 -preset slow -crf 5 -c:a copy video.mpg
ffmpeg -i video.mp4 -c:v libx264 -preset slow -crf 5 -c:a copy -maxrate 11000k video.mpg
ffmpeg -i video.mp4 -c:v libx264 -preset slow -crf 5 -c:a copy -maxrate 5000 -bufsize 11000 video.mpg
Thanks,

Doesn't look like PP2010 supports H.264. (If it did, you could skip re-encoding altogether).
Try
ffmpeg -i video.mp4 -c:v mpeg2video -q:v 5 -c:a mp2 -f vob video.mpg
This will produce a MPEG-2 Program Stream container with MPEG-2 video and MP2 audio.

Related

How does MPG determine its default audio track?

I have some mpg files that I transcoded from DVDs I bought a long time ago (maybe 20 years ago). ffprobe:
Input #0, mpeg, from 'da-orig.mpg':
Duration: 00:06:59.44, start: 0.044100, bitrate: 6354 kb/s
Stream #0:0[0x1e0]: Video: mpeg2video (Main), yuv420p(tv, progressive), 720x480 [SAR 8:9 DAR 4:3], Closed Captions, 31 fps, 59.94 tbr, 90k tbn
Side data:
cpb: bitrate max/min/avg: 7500000/0/0 buffer size: 1835008 vbv_delay: N/A
Stream #0:1[0x85]: Audio: ac3, 48000 Hz, stereo, fltp, 192 kb/s
Stream #0:2[0x83]: Audio: ac3, 48000 Hz, stereo, fltp, 192 kb/s
Stream #0:3[0x81]: Audio: ac3, 48000 Hz, mono, fltp, 192 kb/s
Stream #0:4[0x80]: Audio: ac3, 48000 Hz, mono, fltp, 192 kb/s
This shows there are 4 audio streams. When I play this file in VLC / QuickTime it seems that Audio Track 4 is the default. I'd like to understand how this is chosen. Is it something within the mpg container format or are players choosing the stream that has the lowest id (0x80) ?
More background, when I try to turn this into a mp4 file with the following command:
ffmpeg -i da-orig.mpg -c copy -map 0 da-copy.mp4
I get roughly the same size file, but the default audio track is stream #0:1[0x85].
What I want is an equivalent mp4 file (so the same audio track chosen).
as written in this guide
"The -map option is used to choose which streams from the input(s)
should be included in the output(s)."
in your case you have only one input so it would be -map 0
if you have 2 inputs and want video from one and audio from the other it would be -map 0:v -map 1:a
since your input is a container selecting the video would be -map 0:v
and the second audio stream would be -map 0:a:2
ffmpeg -i da-orig.mpg -map 0:v -c:v h264 -crf 17 -preset 'veryslow' -map 0:a:2 -c:a copy output.mp4
to answer to your comment the sequence can help you
after you rename your collection with sequential numbers 'collection-name_0000' then
ffmpeg -i collection_name_#04d.mpg -map 0:v -c:v h264 -crf 17 -preset 'veryslow' -map 0:a:2 -c:a copy output-#04d.mp4
this iterate through the videos if they have the same number of streams

ffmpeg can't transcode DVD ac3 audio stream, but VLC can play it

I'm attempting to transcode a DVD to a single MKV file. I've had success in the past with other DVDs, but I'm running into an error I haven't seen before.
First I concatenate the VOB files I want to transcode:
cat VTS_02_1.VOB VTS_02_2.VOB VTS_02_3.VOB > WMAV.VOB
ffprobe output:
$ ffprobe -analyzeduration 100M -probesize 100M WMAV.VOB Input #0, mpeg, from 'WMAV.VOB':
Duration: 01:05:19.42, start: 0.300300, bitrate: 5686 kb/s
Stream #0:0[0x1bf]: Data: dvd_nav_packet
Stream #0:1[0x1e0]: Video: mpeg2video (Main), yuv420p(tv, smpte170m, top first), 720x480 [SAR 32:27 DAR 16:9], 29.97 fps, 29.97 tbr, 90k tbn, 59.94 tbc
Stream #0:2[0x80]: Audio: ac3, 48000 Hz, stereo, fltp, 192 kb/s
Unsupported codec with id 100357 for input stream 0
Then I run this command to transcode the file:
ffmpeg -analyzeduration 100M -probesize 100M \
-i WMAV.VOB \
-map 0:1 -map 0:2 \
-c:v libx264 -preset slow -tune film -crf 21 \
-c:a aac -b:a 192k \
wmav.mkv
However, when I include -c:a aac, I get thousands of errors like this:
Error while decoding stream #0:2: Error number -16976906 occurred
[ac3 # 000002bd24d8eec0] expacc 127 is out-of-range
[ac3 # 000002bd24d8eec0] error decoding the audio block
There doesn't seem to be any issue with the audio stream since it plays back fine in VLC. The transcode succeeds if I use -c:a copy.
What is causing this error and how could I fix the problem?

duration change after transcode ts

i have a problem about transcode with ffmpeg
i want to cover m3u8 to mp4, so i transcode every ts file first, and then concat them to a mp4, but i found that the duration will be bigger than source file.
source file is :
http://oc7iy3eta.bkt.clouddn.com/src_20.ts
after transcode, test file is:
http://oc7iy3eta.bkt.clouddn.com/test_20.ts
i use the command as bellow to change to 5fps, and 400k bitrate:
sudo ffmpeg -analyzeduration 2147483647 -probesize 2147483647 -nostdin -y -v warning -i ./src_20.ts -threads 3 -movflags faststart -metadata:s:v rotate=0 -chunk_duration 520000 -video_track_timescale 25000 -pix_fmt yuv420p -copytb 1 -vcodec libx264 -b:v 400000 -minrate 400000 -maxrate 400000 -bufsize 500k -force_key_frames "expr:gte(t,n_forced*2)" -vsync 1 -r 5 -s 544*960 -acodec libfaac -async 1 ./test_20.ts
i use ffprobe command to see video info:
source file info:
Duration: 00:00:01.26, start: 28.346989, bitrate: 921 kb/s
Program 1
Metadata:
service_name : Service01
service_provider: FFmpeg
Stream #0:0[0x100]: Audio: aac ([15][0][0][0] / 0x000F), 44100 Hz, stereo, fltp, 23 kb/s
Stream #0:1[0x101]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p, 544x960, 10.67 tbr, 90k tbn, 180k tbc
test file:
Input #0, mpegts, from 'test_20.ts':
Duration: 00:00:01.62, start: 1.576778, bitrate: 447 kb/s
Program 1
Metadata:
service_name : Service01
service_provider: FFmpeg
Stream #0:0[0x100]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p, 544x960, 5 fps, 5 tbr, 90k tbn, 10 tbc
Stream #0:1[0x101]: Audio: aac ([15][0][0][0] / 0x000F), 44100 Hz, stereo, fltp, 5 kb/s
=======================================================================
question
so , we can see that the duration of src file is 1.26s , but after transcode, the test file is 1.62s.
why? can anybody help
I suggest you save the m3u8 to a single TS and then transcode that to MP4.
ffmpeg -i in.m3u8 -c copy src.ts
Your current command is transcoding each TS to CFR at half the rate but your source timestamps have some jitter, so due to PTS quantization, there will be a mismatch. A single file transcode will minimize it.

ffmpeg - whatsapp: video format not supported

I have two videos (.mp4) files. One uploads to whatsapp and another does not.
Using ffmpeg I checked their properties:
a) Properties of video which uploads:
Duration: 00:00:56.45, start: 0.148000, bitrate: 1404 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1080x1080, 1359 kb/s, 23.98 fps, 23.98 tbr, 90k tbn, 47.95 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #0:1(eng): Audio: aac (HE-AACv2) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 47 kb/s (default)
Metadata:
handler_name : SoundHandler
At least one output file must be specified
b) video which does not upload to whatsapp (because its says format not supported)
Duration: 00:00:56.10, start: 0.000000, bitrate: 543 kb/s
Stream #0:0: Video: h264 (High) (H264 / 0x34363248), yuv420p, 1080x1080 [SAR 1:1 DAR 1:1], 464 kb/s, 23.98 fps, 23.98 tbr, 23.98 tbn, 47.95 tbc
Stream #0:1: Audio: aac (LC) ([255][0][0][0] / 0x00FF), 48000 Hz, stereo, fltp, 56 kb/s
The difference in video I noticed:
(avc1 / 0x31637661) vs (H264 / 0x34363248)
1359 kb/s vs 464 kb/s
90k tbn vs 23.98 tbn
What can be the reason?
Also the second video is not being played in Android.
The link for the video is https://drive.google.com/open?id=0B4UM6vTHw4pyMExQQ1lxZGp0N2c
There are some options for a better compatibility:
ffmpeg -i broken.mp4 -c:v libx264 -profile:v baseline -level 3.0 -pix_fmt yuv420p working.mp4
With -profile:v baseline -level 3.0 you make the file more compatible with most older players, including WhatsApp ;). Although, this disables some advanced features.
-pix_fmt yuv420p is necessary to compile to baseline (YUV planar color space with 4:2:0 chroma subsampling).
Also, you can adjust other options as bitrate, framerate, audio, etc.
Source: H.264 docs
Copied from https://www.reddit.com/r/ffmpeg/comments/564kyc/ffmpeg_whatsapp_video_format_not_supported/?st=ivjxdi0v&sh=848ce7eb
ffmpeg -i brokenvideo.mp4 -c:v libx264 -c:a aac fixedvideo.mp4
Also had to apply this fix: FFMPEG (libx264) "height not divisible by 2"
This is worked for me in 2020
ffmpeg -i broken.mp4 -c:v libx264 -profile:v high -level 3.0 -pix_fmt yuv420p -brand mp42 fixed.mp4
I tried all previous commands and I got some errors. I was able to encode my video using this command and here is the explanation and why I set it up like this for a better compatibility:
ffmpeg -i input.mp4 \
-c:v libx264 -pix_fmt yuv420p \
-profile:v baseline -level 3.0 \
-vf "pad=ceil(iw/2)*2:ceil(ih/2)*2" -vb 1024k \
-acodec aac -ar 44100 -ac 2\
-minrate 1024k -maxrate 1024k -bufsize 1024k \
-movflags +faststart \
output.mp4
If your input contains AAC audio you can stream copy instead of re-encoding by changing -acodec aac -ar 44100 -ac 2 to -acodec copy to preserve the audio quality.
option
explanation
-vcodec libx264
Chooses video encoder libx264
-pix_fmt yuv420p
Ensures YUV 4:2:0 chroma subsampling for compatibility
-profile:v baseline
Set the encoding profile to baseline. Used primarily for low-cost applications that require additional data loss robustness
-level 3.0
Set the operating point level to 3.0 which is necessary to have compatibility with WhatsApp
-vf "pad=ceil(iw/2)*2:ceil(ih/2)*2"
If you get not divisible by 2 error see
-acodec aac
Chooses audio encoder aac
-minrate 1024k
set min bitrate tolerance to 1024k (in bits/s). It is of little use elsewise
-maxrate 1024k
set max bitrate tolerance to 1024k (in bits/s). Requires bufsize to be set
-bufsize 1024k
set rate-control buffer size to 1024k (in bits)
-movflags +faststart
enables fast start for streaming
Note about faststart
Normally, a MP4 file has all its metadata packets stored at the end of the file, in data units named atoms. The mdat atom is located before the moov atom. If the file is created by adding the -movflags faststart, the moov atom is moved at the beginning of the MP4 file. By using this option, the moov atom is located before the mdat atom. This allows video playback to begin before the file has been completely downloaded.
2023-01-22 I used the most upvoted answer format and it worked for video, but audio was not working on iPhones. Here's what worked for me:
ffmpeg -i broken.mp4 -c:v libx264 -profile:v baseline -level 3.0 -pix_fmt yuv420p -ac 2 working.mp4
I had to add -ac 2 because the audio format I had wasn't seen as stereo by iOS.

ffmpeg - set metatag to .ts file

i have a .mp4 video, that is recorded in iphone4s.This video file contains 'Rotate - 180' metadata.
When i am converting the .mp4 file to .ts using ffmpeg. I lost the 'Rotate' meta tag.
The ffmpeg command that i have used is given below.
ffmpeg -i input_file.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb output_file.ts
is there any one know how to set 'Rotate' meta data to a .ts file ?
or
any other way to copy all meta datas in the input .mp4 file to output .ts file
Thank you
Nothing seems to work to add the rotation metadata to .ts files with ffmpeg. Only re-encoding works.
My input file has a rotation value of 90.
Terminal command:
./ffmpeg -i input_file.mp4
Metadata:
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'input_file.mp4':
Metadata:
major_brand : isom
minor_version : 0
compatible_brands: isom3gp4
creation_time : 2013-08-27 21:25:13
Duration: 00:00:21.33, start: 0.000000, bitrate: 16820 kb/s
Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x1080, 17011 kb/s, 30 fps, 30 tbr, 90k tbn, 180k tbc
Metadata:
rotate : 90
creation_time : 2013-08-27 21:25:13
handler_name : VideoHandle
Stream #0:1(eng): Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 121 kb/s
Metadata:
creation_time : 2013-08-27 21:25:13
handler_name : SoundHandle
The following attempts did not get the rotation value to copy over:
./ffmpeg -y -i input_file.mp4 -vcodec copy -acodec copy -bsf h264_mp4toannexb output_file.ts
./ffmpeg -y -i input_file.mp4 -vcodec copy -acodec copy -bsf h264_mp4toannexb -metadata rotate=90 output_file.ts
//------ even manually specifying the metadata as the first video stream does not work: ------//
./ffmpeg -y -i input_file.mp4 -vcodec copy -acodec copy -bsf h264_mp4toannexb -metadata:s:v:0 rotate=90 output_file.ts
Even though you can manually inject metadata like:
./ffmpeg -y -i input_file.mp4 -vcodec copy -acodec copy -bsf h264_mp4toannexb -metadata TITLE='Test Title' output_file.ts
This does work, but requires re-encoding, which is really inefficient compared to video and audio codec copying above.
(1 == 90 degree CW rotation)
./ffmpeg -y -i input_file.mp4 -vf "transpose=1" output_file.ts

Resources