[Libav-user] Huge packet sized during encoding

Harald Schlangmann harry at gps-laptimer.de
Fri Mar 21 13:18:41 CET 2014


Hi,

I’m developing an app on Android reading in a video, applying an overlay, and writing it back to another video. Besides several issues I faced already ;-) I’m currently struggling to find the reason for - well - bad encoding results using xlib264. What I get from my tracing:

Information on video processed (from av_dump_format ()):

2101226411 00 --> call to VideoSource::startAssetReader ()
2101226411 01   --> opening video /storage/emulated/legacy/Movies/IMG_0806.mp4
2101226419 01   --> Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/storage/emulated/legacy/Movies/IMG_0806.mp4':
2101226419 01   -->   Metadata:
2101226419 01   -->     major_brand     : isom
2101226419 01   -->     minor_version   : 512
2101226419 01   -->     compatible_brands: isomiso2avc1mp41
2101226419 01   -->     encoder         : Lavf55.19.104
2101226419 01   -->   Duration: 00:15:40.57, bitrate: N/A
2101226419 01   -->     Stream #0:0(und), 0, 1/30000: Video: h264 (avc1 / 0x31637661), 1280x720, 0/1, 2274 kb/s, 29.97 fps, 29.97 tbr, 30k tbn (default)
2101226419 01   -->     Metadata:
2101226419 01   -->       handler_name    : VideoHandler
2101226419 01   -->     Stream #0:1(und), 0, 1/44100: Audio: aac (mp4a / 0x6134706D), 44100 Hz, 1 channels, 128 kb/s (default)
2101226419 01   -->     Metadata:
2101226419 01   -->       handler_name    : SoundHandler
2101226423 00 —> VideoSource::startAssetReader () returns

Information on video created: 

2101226748 00 --> call to AssetWriter::startAssetWriter ()
2101226748 01   --> adding stream for encoder 'h264'
2101226749 01   --> set video resolution to 1280 x 720
2101226749 01   --> set bit rate to 2.169246 MBit/s
2101226749 01   --> time_base set to 1001/30000 s
2101226749 01   --> adding stream for encoder 'aac'
2101226764 01   --> Output #0, mp4, to '/storage/emulated/legacy/Movies/Overlay-20140221-003642.mp4':
2101226764 01   -->     Stream #0:0, 0, 1/90000: Video: h264 (libx264), yuv420p, 1280x720, 1001/30000, q=-1--1, 2274 kb/s, 90k tbn, 29.97 tbc
2101226764 01   -->     Stream #0:1, 0, 1/90000: Audio: aac, 44100 Hz, 2 channels, fltp, 64 kb/s
2101226764 00 --> AssetWriter::startAssetWriter () returns

Now, looking into the packets written, I see (approximately 1 second of video, 30 frames):

2101227476 01   --> video packet sized 156862 bytes written for pts = 6873867 with stream time_base 1 / 30000 (229.13s)
2101227502 01   --> video packet sized 64695 bytes written for pts = 6875869 with stream time_base 1 / 30000 (229.20s)
2101227530 01   --> video packet sized 22829 bytes written for pts = 6874868 with stream time_base 1 / 30000 (229.16s)
2101227615 01   --> video packet sized 103060 bytes written for pts = 6877871 with stream time_base 1 / 30000 (229.26s)
2101227643 01   --> video packet sized 31593 bytes written for pts = 6876870 with stream time_base 1 / 30000 (229.23s)
2101227668 01   --> video packet sized 89404 bytes written for pts = 6880874 with stream time_base 1 / 30000 (229.36s)
2101227694 01   --> video packet sized 29312 bytes written for pts = 6879873 with stream time_base 1 / 30000 (229.33s)
2101227718 01   --> video packet sized 21731 bytes written for pts = 6878872 with stream time_base 1 / 30000 (229.30s)
2101227811 01   --> video packet sized 286220 bytes written for pts = 6883877 with stream time_base 1 / 30000 (229.46s)
2101227839 01   --> video packet sized 77027 bytes written for pts = 6882876 with stream time_base 1 / 30000 (229.43s)
2101227865 01   --> video packet sized 32279 bytes written for pts = 6881875 with stream time_base 1 / 30000 (229.40s)
2101227905 01   --> video packet sized 267214 bytes written for pts = 6884878 with stream time_base 1 / 30000 (229.50s)
2101227932 01   --> video packet sized 320495 bytes written for pts = 6885879 with stream time_base 1 / 30000 (229.53s)
2101227959 01   --> video packet sized 335585 bytes written for pts = 6887881 with stream time_base 1 / 30000 (229.60s)
2101228060 01   --> video packet sized 235464 bytes written for pts = 6886880 with stream time_base 1 / 30000 (229.56s)
2101228085 01   --> video packet sized 392501 bytes written for pts = 6889883 with stream time_base 1 / 30000 (229.66s)
2101228110 01   --> video packet sized 255984 bytes written for pts = 6888882 with stream time_base 1 / 30000 (229.63s)
2101228245 01   --> video packet sized 339338 bytes written for pts = 6891885 with stream time_base 1 / 30000 (229.73s)
2101228279 01   --> video packet sized 251143 bytes written for pts = 6890884 with stream time_base 1 / 30000 (229.70s)
2101228306 01   --> video packet sized 382294 bytes written for pts = 6893887 with stream time_base 1 / 30000 (229.80s)
2101228331 01   --> video packet sized 231140 bytes written for pts = 6892886 with stream time_base 1 / 30000 (229.76s)
2101228360 01   --> video packet sized 383165 bytes written for pts = 6896890 with stream time_base 1 / 30000 (229.90s)
2101228389 01   --> video packet sized 271674 bytes written for pts = 6895889 with stream time_base 1 / 30000 (229.86s)
2101228477 01   --> video packet sized 252329 bytes written for pts = 6894888 with stream time_base 1 / 30000 (229.83s)
2101228523 01   --> video packet sized 484016 bytes written for pts = 6897891 with stream time_base 1 / 30000 (229.93s)
2101228556 01   --> video packet sized 362961 bytes written for pts = 6899893 with stream time_base 1 / 30000 (230.00s)
2101228584 01   --> video packet sized 263645 bytes written for pts = 6898892 with stream time_base 1 / 30000 (229.96s)
2101228669 01   --> video packet sized 386746 bytes written for pts = 6901895 with stream time_base 1 / 30000 (230.06s)
2101228709 01   --> video packet sized 284070 bytes written for pts = 6900894 with stream time_base 1 / 30000 (230.03s)
2101228828 01   --> video packet sized 369222 bytes written for pts = 6903897 with stream time_base 1 / 30000 (230.13s)

Adding up the packet sized, these are 6983998 bytes which means nearly 7 MB per second. A video with length 3.5 minutes is 1.6 GB large - which is in line with this sample. Instead of the 2274 kb/s defined for the stream, the above sample means 54562 kb/s…

So my question: what could be the reason the video output gets that large? 

The configuration I apply to the video stream’s codec context is setting the codec_id, width, height, bitrate, time_base, gop_size=12, and pix_fmt = AV_PIX_FMT_YUV420P (see dump output above). The step I do when writing a frame is scaling / encoding a frame (size 1280x720, from RGB565 to AV_PIX_FMT_YUV420P, resulting in size = 1843200 bytes), setting its pts field, initializing a new packet, writing the frame using avcodec_encode_video2 (), and writing it using av_interleaved_write_frame () in case I got a packet completed (by avcodec_encode_video2).

Sorry for the long mail. In case code snippets are required, I’m happy to add.

Thanks for any thought how I can fix or debug that!

Greetings Harald

-
Harald Schlangmann
Antwerpener Str. 52, 50672 Köln, Germany
+49 151 2265 4439
Harry at gps-laptimer.de
www.gps-laptimer.de

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4145 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20140321/0616e4a1/attachment.p7s>


More information about the Libav-user mailing list