|
149 | 149 | "metadata": {},
|
150 | 150 | "outputs": [],
|
151 | 151 | "source": [
|
152 |
| - "import json\n", |
153 |
| - "\n", |
154 | 152 | "analyzer_template_path = '../analyzer_templates/invoice.json'\n",
|
155 | 153 | "with open(analyzer_template_path, 'r') as f:\n",
|
156 | 154 | " template_content = json.load(f)\n",
|
|
649 | 647 | "\n",
|
650 | 648 | "Let's analyze a marketing video to extract descriptions, sentiment, and key insights that could be valuable for content understanding and marketing analytics.\n",
|
651 | 649 | "\n",
|
652 |
| - "Marketing video analytics template:" |
| 650 | + "Content Understanding offers three ways to slice a video, letting you get the output you need for whole videos or short clips. You can use these options by setting the `segmentationMode` property on a custom analyzer.\n", |
| 651 | + "- Whole-video – `\"segmentationMode\": \"noSegmentation\"` The service treats the entire video file as a single segment and extracts metadata across its full duration. \n", |
| 652 | + " Example:\n", |
| 653 | + " - Compliance checks that look for specific brand-safety issues anywhere in an ad\n", |
| 654 | + " - full-length descriptive summaries\n", |
| 655 | + "- Automatic segmentation – `\"segmentationMode\": \"auto\"` The service analyzes the timeline and breaks it up for you. Groups successive shots into coherent scenes, capped at one minute each. \n", |
| 656 | + " Example:\n", |
| 657 | + " - Create storyboards from a show\n", |
| 658 | + " - Inserting mid-roll ads at logical pauses.\n", |
| 659 | + "- Custom segmentation – `\"segmentationMode\": \"custom\"` You describe the logic in natural language and the model creates segments to match. Set `segmentationDefinition` with a string describing how you'd like the video to be segmented. Custom allows segments of varying length from seconds to minutes depending on the prompt. \n", |
| 660 | + " Example:\n", |
| 661 | + " - Break a news broadcast up into stories." |
| 662 | + ] |
| 663 | + }, |
| 664 | + { |
| 665 | + "cell_type": "markdown", |
| 666 | + "metadata": {}, |
| 667 | + "source": [ |
| 668 | + "### 6-1 Analyze without Segmentation\n", |
| 669 | + "\n", |
| 670 | + "In this example, we analyze a marketing video without segmentation.\n", |
| 671 | + "- Please set `segmentationMode` to `noSegmentation` in the analyzer schema `config` to process the entire video as one segment." |
653 | 672 | ]
|
654 | 673 | },
|
655 | 674 | {
|
|
695 | 714 | "cell_type": "markdown",
|
696 | 715 | "metadata": {},
|
697 | 716 | "source": [
|
698 |
| - "Marketing video analysis result:" |
| 717 | + "Marketing video analysis result\n", |
| 718 | + "- The result is generated from the content of the entire video." |
| 719 | + ] |
| 720 | + }, |
| 721 | + { |
| 722 | + "cell_type": "code", |
| 723 | + "execution_count": null, |
| 724 | + "metadata": {}, |
| 725 | + "outputs": [], |
| 726 | + "source": [ |
| 727 | + "print(json.dumps(result_json, indent=2))" |
| 728 | + ] |
| 729 | + }, |
| 730 | + { |
| 731 | + "cell_type": "markdown", |
| 732 | + "metadata": {}, |
| 733 | + "source": [ |
| 734 | + "Clean up marketing video analyzer\n", |
| 735 | + "\n", |
| 736 | + "Note: In production environments, you would typically keep analyzers for reuse rather than deleting them" |
| 737 | + ] |
| 738 | + }, |
| 739 | + { |
| 740 | + "cell_type": "code", |
| 741 | + "execution_count": null, |
| 742 | + "metadata": {}, |
| 743 | + "outputs": [], |
| 744 | + "source": [ |
| 745 | + "client.delete_analyzer(video_analyzer_id)" |
| 746 | + ] |
| 747 | + }, |
| 748 | + { |
| 749 | + "cell_type": "markdown", |
| 750 | + "metadata": {}, |
| 751 | + "source": [ |
| 752 | + "### 6-2 Analyze With Automatic Segmentation\n", |
| 753 | + "\n", |
| 754 | + "In this example, we use automatic segmentation for marketing video analytics. \n", |
| 755 | + "- Please set `segmentationMode` to `auto` in the analyzer schema `config` to enable automatic segmentation." |
| 756 | + ] |
| 757 | + }, |
| 758 | + { |
| 759 | + "cell_type": "code", |
| 760 | + "execution_count": null, |
| 761 | + "metadata": {}, |
| 762 | + "outputs": [], |
| 763 | + "source": [ |
| 764 | + "analyzer_template_path = '../analyzer_templates/marketing_video_segmenation_auto.json'\n", |
| 765 | + "with open(analyzer_template_path, 'r') as f:\n", |
| 766 | + " template_content = json.load(f)\n", |
| 767 | + " print(json.dumps(template_content, indent=2))" |
| 768 | + ] |
| 769 | + }, |
| 770 | + { |
| 771 | + "cell_type": "markdown", |
| 772 | + "metadata": {}, |
| 773 | + "source": [ |
| 774 | + "Create and run marketing video analyzer" |
| 775 | + ] |
| 776 | + }, |
| 777 | + { |
| 778 | + "cell_type": "code", |
| 779 | + "execution_count": null, |
| 780 | + "metadata": {}, |
| 781 | + "outputs": [], |
| 782 | + "source": [ |
| 783 | + "sample_file_path = '../data/FlightSimulator.mp4'\n", |
| 784 | + "video_analyzer_id = \"marketing-video-analytics-\" + str(uuid.uuid4())\n", |
| 785 | + "\n", |
| 786 | + "print(f\"Creating marketing video analyzer: {video_analyzer_id}\")\n", |
| 787 | + "response = client.begin_create_analyzer(video_analyzer_id, analyzer_template_path=analyzer_template_path)\n", |
| 788 | + "result = client.poll_result(response)\n", |
| 789 | + "print(\"✅ Marketing video analyzer created successfully!\")\n", |
| 790 | + "\n", |
| 791 | + "print(f\"Analyzing marketing video: {sample_file_path}\")\n", |
| 792 | + "print(\"⏳ Note: Video analysis may take significantly longer than document analysis...\")\n", |
| 793 | + "response = client.begin_analyze(video_analyzer_id, file_location=sample_file_path)\n", |
| 794 | + "result_json = client.poll_result(response)" |
| 795 | + ] |
| 796 | + }, |
| 797 | + { |
| 798 | + "cell_type": "markdown", |
| 799 | + "metadata": {}, |
| 800 | + "source": [ |
| 801 | + "Marketing video analysis result\n", |
| 802 | + "- The output includes automatically segmented clips with descriptions in the markdown content. \n", |
| 803 | + "- The analyzer generates the fields defined in the schema separately for each segment." |
| 804 | + ] |
| 805 | + }, |
| 806 | + { |
| 807 | + "cell_type": "code", |
| 808 | + "execution_count": null, |
| 809 | + "metadata": {}, |
| 810 | + "outputs": [], |
| 811 | + "source": [ |
| 812 | + "print(json.dumps(result_json, indent=2))" |
| 813 | + ] |
| 814 | + }, |
| 815 | + { |
| 816 | + "cell_type": "markdown", |
| 817 | + "metadata": {}, |
| 818 | + "source": [ |
| 819 | + "Clean up marketing video analyzer\n", |
| 820 | + "\n", |
| 821 | + "Note: In production environments, you would typically keep analyzers for reuse rather than deleting them" |
| 822 | + ] |
| 823 | + }, |
| 824 | + { |
| 825 | + "cell_type": "code", |
| 826 | + "execution_count": null, |
| 827 | + "metadata": {}, |
| 828 | + "outputs": [], |
| 829 | + "source": [ |
| 830 | + "client.delete_analyzer(video_analyzer_id)" |
| 831 | + ] |
| 832 | + }, |
| 833 | + { |
| 834 | + "cell_type": "markdown", |
| 835 | + "metadata": {}, |
| 836 | + "source": [ |
| 837 | + "### 6-3 Analyze With Custom Segmentation\n", |
| 838 | + "\n", |
| 839 | + "In this example, we use custom segmentation for marketing video analytics. \n", |
| 840 | + "- Please set `segmentationMode` to `custom`. \n", |
| 841 | + "- Provide a `segmentationDefinition` string describing how you would like the video to be segmented." |
| 842 | + ] |
| 843 | + }, |
| 844 | + { |
| 845 | + "cell_type": "code", |
| 846 | + "execution_count": null, |
| 847 | + "metadata": {}, |
| 848 | + "outputs": [], |
| 849 | + "source": [ |
| 850 | + "analyzer_template_path = '../analyzer_templates/marketing_video_segmenation_custom.json'\n", |
| 851 | + "with open(analyzer_template_path, 'r') as f:\n", |
| 852 | + " template_content = json.load(f)\n", |
| 853 | + " print(json.dumps(template_content, indent=2))" |
| 854 | + ] |
| 855 | + }, |
| 856 | + { |
| 857 | + "cell_type": "markdown", |
| 858 | + "metadata": {}, |
| 859 | + "source": [ |
| 860 | + "Create and run marketing video analyzer" |
699 | 861 | ]
|
700 | 862 | },
|
701 | 863 | {
|
|
704 | 866 | "metadata": {},
|
705 | 867 | "outputs": [],
|
706 | 868 | "source": [
|
| 869 | + "sample_file_path = '../data/FlightSimulator.mp4'\n", |
| 870 | + "video_analyzer_id = \"marketing-video-analytics-\" + str(uuid.uuid4())\n", |
707 | 871 | "\n",
|
| 872 | + "print(f\"Creating marketing video analyzer: {video_analyzer_id}\")\n", |
| 873 | + "response = client.begin_create_analyzer(video_analyzer_id, analyzer_template_path=analyzer_template_path)\n", |
| 874 | + "result = client.poll_result(response)\n", |
| 875 | + "print(\"✅ Marketing video analyzer created successfully!\")\n", |
| 876 | + "\n", |
| 877 | + "print(f\"Analyzing marketing video: {sample_file_path}\")\n", |
| 878 | + "print(\"⏳ Note: Video analysis may take significantly longer than document analysis...\")\n", |
| 879 | + "response = client.begin_analyze(video_analyzer_id, file_location=sample_file_path)\n", |
| 880 | + "result_json = client.poll_result(response)" |
| 881 | + ] |
| 882 | + }, |
| 883 | + { |
| 884 | + "cell_type": "markdown", |
| 885 | + "metadata": {}, |
| 886 | + "source": [ |
| 887 | + "Marketing video analysis result\n", |
| 888 | + "- The video is segmented according to your custom definition, with segment descriptions included in the markdown content. \n", |
| 889 | + "- The segmentation may differ from automatic segmentation results. \n", |
| 890 | + "- The analyzer generates the fields defined in the schema separately for each segment." |
| 891 | + ] |
| 892 | + }, |
| 893 | + { |
| 894 | + "cell_type": "code", |
| 895 | + "execution_count": null, |
| 896 | + "metadata": {}, |
| 897 | + "outputs": [], |
| 898 | + "source": [ |
708 | 899 | "print(json.dumps(result_json, indent=2))"
|
709 | 900 | ]
|
710 | 901 | },
|
|
0 commit comments