0

I have a CDN that serves videos to my Flutter application. The videos are around 20-30MB. Is there a way to instead of downloading the entire video before playing it, download the video in pieces, and immediately output the first piece to the user?

Just like http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4, doesn't download the 300MB video if you play it in the browser, but dowloads it in portions?

I tried different video players (video_player, cached_video_play, better_player...) and tried experimenting with different request headers for the CDN. Nothing seems to work.

Any suggestions?

1 Answers1

0

You also have https://server.com/files/video.mp4 MP4 video file link? Make sure it's a faststart or fragmentedMp4 file.

I did not try this but maybe this is enough to make it a faststart (MOOV header copied to the start of file) without transcoding. If you need to transcode you can give same flags along with the usual codec+bitrate attributes.

ffmpeg -i "video.mp4" -c:v copy -c:a copy -movflags "negative_cts_offsets+faststart" -y video_new.mp4

MOOV tells the details of stream (codec, resolution, etc..) and should be found at the start of file, but it may be found at the end if file was for a disk storage use.

Fragmented mp4 is a technique interleaving payloads for streaming but may introduce problems for forward/rewind without the HLS-DASH manifest descriptor files. Very old players don't support fragmented mp4 file.

If you want to transcode you may try this one.

ffmpeg -i "input.mp4" -preset fast -c:v libx264 -profile:v main -level 4.0 \
  -s:v 640x360 -b:v 712k -pix_fmt yuv420p \
  -refs 3 -bf 3 -g 50 -keyint_min 25 -b_strategy 1 -flags +cgop -sc_threshold 0 \
  -c:a aac -b:a 128k -maxrate:a 128k -bufsize:a 128k -af aresample=48000 -ar 48000 -ac 2 \
  -movflags "negative_cts_offsets+faststart" \
  -y video_new.mp4
Whome
  • 10,181
  • 6
  • 53
  • 65