“This is the 18th day of my participation in the Gwen Challenge in November. Check out the details: The Last Gwen Challenge in 2021”

directory

preface

The body of the

conclusion


preface

Video files in MP4 format are very common in daily work and life. Today we will see how FFmpeg converts a video file to MP4 format.

The body of the

In the field of voD, MP4 format should be the most common multimedia file packaging format. We need to know that mp4 files are made up of a number of boxes and fullboxes, of which each Box consists of header and data. FullBox is an extension of Box, with 8-bit version flags and 24-bit Flags added to the header.

The header part of Box and FullBox contains the length, size and type of the entire Box, and the data part is the actual data stored, which may be data or nested Box (then the Box will be called a container).

Now that we have a general understanding of the mp4 structure, let’s use FFmpeg to convert a TS (or FLV) source file into an MP4 file by running the following command:

ffmpeg -i benben.ts -c copy -f mp4 benben2.mp4

The running results are as follows:

Input #0, MPEGts, from ‘benben.ts’: Duration: 00:00:10.19, start: 1.462011, bitrate: 635 KB /s Program 1 Metadata: service_name : Service01 service_provider: FFmpeg Stream #0:0[0x100]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p, 368×640 [SAR 45:46 DAR 9:16], 24 fps, 24 tbr, 90k tbn, 48 tbc Stream #0:10×101: Audio: aac (LC) ([15][0][0][0] / 0x000F), 48000 Hz, stereo, fltp, 67 kb/s [mp4 @ 02eac480] Codec for stream 0 does not use global headers but container format requires global headers [mp4 @ 02eac480] Codec for stream 1 does not use global headers but container format requires global headers Output #0, Mp4, to ‘Benben2.mp4 ‘: Metadata: Encoder: Lavf56.40.100 Stream #0:0: Video: h264 ([33][0][0][0] / 0x0021), yuv420p, 368×640 [SAR 45:46 DAR 9:16], q=2-31, 24 fps, 24 tbr, 90k tbn, 90k tbc Stream #0:1(eng): Audio: aac ([64][0][0][0] / 0x0040), 48000 Hz, stereo, 67 kb/s Stream mapping: Stream #0:0 -> #0:0 (copy) Stream #0:1 -> #0:1 (copy) Press [q] to stop, [?] for help [mp4 @ 02eac480] Malformed AAC bitstream detected: use the audio bitstream filter ‘aac_adtstoasc’ to fix it (‘-bsf:a aac_adtstoasc’ option with ffmpeg) av_interleaved_write_frame(): Operation not permitted Frame = 6 FPS = 0.0q = -1.0lsize = 84kB Time =00:00:00.14 bitRate =4700.5kbits/s Video: 80kb Audio: 80KB Subtitle :0kB Other Streams :0kB Global headers:0kB muxing overhead: 1.068532% Conversion Failed!

Error running result:

An error message prompts us to set the audio conversion mode, and then run the following command:

 ffmpeg -i benben.ts -c copy -bsf:a aac_adtstoasc  -f mp4 benben2.mp4

Output result:

[mp4 @ 0547f420] Codec for stream 0 does not use global headers but container format requires global headers [mp4 @ 0547f420] Codec for stream 1 does not use global headers but container format requires global headers Output #0, mp4, To ‘benben2.mp4’: Metadata: encoder: Lavf56.40.100 Stream #0:0: Video: h264 ([33][0][0][0] / 0x0021), yuv420p, 368×640 [SAR 45:46 DAR 9:16], q=2-31, 24 fps, 24 tbr, 90k tbn, 90k tbc Stream #0:1(eng): Audio: aac ([64][0][0][0] / 0x0040), 48000 Hz, stereo, 67 kb/s Stream mapping: Stream #0:0 -> #0:0 (copy) Stream #0:1 -> #0:1 (copy) Press [q] to stop, [?] For help Frame = 244 FPS = 0.0q = -1.0lsize = 707kB Time =00:00:10.06 Bitrate = 575.9kbits/s Video :620kB Audio :79kB Subtitle :0kB Other Streams :0kB Global Headers :0kB Muxing overhead: 1.147096%

File conversion succeeded:

Finally, use mp4Info to view the structure of the target video file:

conclusion

When using FFMPEG to convert FLV files, you need to modify the parameters according to the specific use scenario. Do not panic if errors occur. By analyzing the specific cause of the error, we will definitely be able to fix it. Good Luck!

If there is a problem, welcome to comment message or private communication!

About the author: Hi, everyone, I am Liuzhen007, an audio and video technology enthusiast, CSDN blog expert, Huawei Cloud community cloud sharing expert, signed author, welcome to follow me to share more audio and video related content!