<jupyter_start><jupyter_text>FFmpeg demo: video encoding<jupyter_code># Download a static FFmpeg build and add it to PATH.
%run 'util/load-ffmpeg.ipynb'
print('Done!')
# [optional] Print input video information. You can upload another video file and change the file name below.
!ffprobe -hide_banner input.mp4
print('Done!')
# Compress input.mp4 to a target bitrate and save as output.mp4. 
# Change the command line flags as you need for different encoding settings.

!ffmpeg -hide_banner -i input.mp4 -b:v 200k -y output.mp4
print('Done!')
# Display both the source (top) video and encoded (bottom) video.
# Sometimes the two players get out of sync. Press "sync" to mitigate that.

%run util/play-video.ipynb --ref input.mp4 --tar output.mp4
HTML(html)
# Calculate PSNR between input.mp4 and output.mp4
!ffmpeg -hide_banner -i output.mp4 -i input.mp4 -lavfi psnr -f null - 2>&1 | grep "Parsed_psnr_0"

# Calculate SSIM between input.mp4 and output.mp4
!ffmpeg -hide_banner -i output.mp4 -i input.mp4 -lavfi ssim -f null - 2>&1 | grep "Parsed_ssim_0"

# Calculate VMAF between input.mp4 (ref) and output.mp4 (target).
!ffmpeg -hide_banner -i output.mp4 -i input.mp4 \
  -lavfi "libvmaf=model_path={ffmdir[0]}/model/vmaf_v0.6.1.pkl" -f null - 2>&1 | grep 'VMAF' \
  || echo 'VMAF calculation failed!'

print('Done!')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11878247958426132, 'fraction_numerical': 0.025241276911655532, 'mean_word_length': 4.224806201550388, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '46775', 'license': 'MIT', 'n_tokens_mistral': 512, 'n_tokens_neox': 496, 'n_words': 163, 'path': 'ffmpeg-demo-compression.ipynb', 'repo_name': 'op07n/jupyter-video-test1', 'size': '1347'}